6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.4 1987-08-22 17:11:16 wesommer
10 * Increment the nesting level only after we know we're connected.
12 * Revision 1.3 87/08/02 21:49:53 wesommer
13 * Prevent recursive query call.
15 * Revision 1.2 87/06/16 17:48:58 wesommer
16 * Clean up memory allocation, indenting.
18 * Revision 1.1 87/06/04 01:29:32 wesommer
24 static char *rcsid_sms_query_c = "$Header$";
27 #include "sms_private.h"
30 * This routine is the primary external interface to the sms library.
32 * It builds a new argument vector with the query handle prepended,
33 * and calls sms_query_internal.
37 int sms_query(name, argc, argv, callproc, callarg)
38 char *name; /* Query name */
39 int argc; /* Arg count */
40 char **argv; /* Args */
41 int (*callproc)(); /* Callback procedure */
42 char *callarg; /* Callback argument */
44 register char **nargv = (char **)malloc(sizeof(char *) * (argc+1));
45 register int status = 0;
47 bcopy((char *)argv, (char *)(nargv+1), sizeof(char *) * argc);
48 status = sms_query_internal(argc+1, nargv, callproc, callarg);
53 * This routine makes an SMS query.
55 * argv[0] is the query name.
56 * argv[1..argc-1] are the query arguments.
58 * callproc is called once for each returned value, with arguments
59 * argc, argv, and callarg.
60 * If it returns a non-zero value, further calls to it are not done, and
61 * all future data from the server is ignored (there should be some
62 * way to send it a quench..)
65 int sms_query_internal(argc, argv, callproc, callarg)
66 int argc; /* Arg count */
67 char **argv; /* Args */
68 int (*callproc)(); /* Callback procedure */
69 char *callarg; /* Callback argument */
73 register sms_params *params = NULL;
74 sms_params *reply = NULL;
75 int stopcallbacks = 0;
77 if (level) return SMS_QUERY_NOT_REENTRANT;
83 params->sms_procno = SMS_QUERY;
84 params->sms_argc = argc;
85 params->sms_argl = NULL;
86 params->sms_argv = argv;
88 if ((status = sms_do_call(params, &reply)))
91 while ((status = reply->sms_status) == SMS_MORE_DATA) {
94 (*callproc)(reply->sms_argc, reply->sms_argv, callarg);
95 sms_destroy_reply(reply);
98 initialize_operation(_sms_recv_op, sms_start_recv, &reply,
100 queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
102 complete_operation(_sms_recv_op);
103 if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
105 status = SMS_ABORTED;
110 sms_destroy_reply(reply);
119 * c-continued-statement-offset: 4
121 * c-argdecl-indent: 4