6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.5 1988-04-19 12:38:41 mar
10 * pass version number on queries
12 * Revision 1.4 87/08/22 17:11:16 wesommer
13 * Increment the nesting level only after we know we're connected.
15 * Revision 1.3 87/08/02 21:49:53 wesommer
16 * Prevent recursive query call.
18 * Revision 1.2 87/06/16 17:48:58 wesommer
19 * Clean up memory allocation, indenting.
21 * Revision 1.1 87/06/04 01:29:32 wesommer
27 static char *rcsid_sms_query_c = "$Header$";
30 #include "sms_private.h"
33 * This routine is the primary external interface to the sms library.
35 * It builds a new argument vector with the query handle prepended,
36 * and calls sms_query_internal.
40 int sms_query(name, argc, argv, callproc, callarg)
41 char *name; /* Query name */
42 int argc; /* Arg count */
43 char **argv; /* Args */
44 int (*callproc)(); /* Callback procedure */
45 char *callarg; /* Callback argument */
47 register char **nargv = (char **)malloc(sizeof(char *) * (argc+1));
48 register int status = 0;
50 bcopy((char *)argv, (char *)(nargv+1), sizeof(char *) * argc);
51 status = sms_query_internal(argc+1, nargv, callproc, callarg);
56 * This routine makes an SMS query.
58 * argv[0] is the query name.
59 * argv[1..argc-1] are the query arguments.
61 * callproc is called once for each returned value, with arguments
62 * argc, argv, and callarg.
63 * If it returns a non-zero value, further calls to it are not done, and
64 * all future data from the server is ignored (there should be some
65 * way to send it a quench..)
68 int sms_query_internal(argc, argv, callproc, callarg)
69 int argc; /* Arg count */
70 char **argv; /* Args */
71 int (*callproc)(); /* Callback procedure */
72 char *callarg; /* Callback argument */
76 register sms_params *params = NULL;
77 sms_params *reply = NULL;
78 int stopcallbacks = 0;
80 if (level) return SMS_QUERY_NOT_REENTRANT;
86 params->sms_version_no = sending_version_no;
87 params->sms_procno = SMS_QUERY;
88 params->sms_argc = argc;
89 params->sms_argl = NULL;
90 params->sms_argv = argv;
92 if ((status = sms_do_call(params, &reply)))
95 while ((status = reply->sms_status) == SMS_MORE_DATA) {
98 (*callproc)(reply->sms_argc, reply->sms_argv, callarg);
99 sms_destroy_reply(reply);
102 initialize_operation(_sms_recv_op, sms_start_recv, &reply,
104 queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
106 complete_operation(_sms_recv_op);
107 if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
109 status = SMS_ABORTED;
114 sms_destroy_reply(reply);
123 * c-continued-statement-offset: 4
125 * c-argdecl-indent: 4