6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.3 1987-08-02 21:49:53 wesommer
10 * Prevent recursive query call.
12 * Revision 1.2 87/06/16 17:48:58 wesommer
13 * Clean up memory allocation, indenting.
15 * Revision 1.1 87/06/04 01:29:32 wesommer
21 static char *rcsid_sms_query_c = "$Header$";
24 #include "sms_private.h"
27 * This routine is the primary external interface to the sms library.
29 * It builds a new argument vector with the query handle prepended,
30 * and calls sms_query_internal.
34 int sms_query(name, argc, argv, callproc, callarg)
35 char *name; /* Query name */
36 int argc; /* Arg count */
37 char **argv; /* Args */
38 int (*callproc)(); /* Callback procedure */
39 char *callarg; /* Callback argument */
41 register char **nargv = (char **)malloc(sizeof(char *) * (argc+1));
42 register int status = 0;
44 bcopy((char *)argv, (char *)(nargv+1), sizeof(char *) * argc);
45 status = sms_query_internal(argc+1, nargv, callproc, callarg);
50 * This routine makes an SMS query.
52 * argv[0] is the query name.
53 * argv[1..argc-1] are the query arguments.
55 * callproc is called once for each returned value, with arguments
56 * argc, argv, and callarg.
57 * If it returns a non-zero value, further calls to it are not done, and
58 * all future data from the server is ignored (there should be some
59 * way to send it a quench..)
62 int sms_query_internal(argc, argv, callproc, callarg)
63 int argc; /* Arg count */
64 char **argv; /* Args */
65 int (*callproc)(); /* Callback procedure */
66 char *callarg; /* Callback argument */
70 register sms_params *params = NULL;
71 sms_params *reply = NULL;
72 int stopcallbacks = 0;
74 if (level) return SMS_QUERY_NOT_REENTRANT;
80 params->sms_procno = SMS_QUERY;
81 params->sms_argc = argc;
82 params->sms_argl = NULL;
83 params->sms_argv = argv;
85 if ((status = sms_do_call(params, &reply)))
88 while ((status = reply->sms_status) == SMS_MORE_DATA) {
91 (*callproc)(reply->sms_argc, reply->sms_argv, callarg);
92 sms_destroy_reply(reply);
95 initialize_operation(_sms_recv_op, sms_start_recv, &reply,
97 queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
99 complete_operation(_sms_recv_op);
100 if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
102 status = SMS_ABORTED;
107 sms_destroy_reply(reply);
116 * c-continued-statement-offset: 4
118 * c-argdecl-indent: 4