6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
9 * Revision 1.2 1987-06-16 17:48:58 wesommer
10 * Clean up memory allocation, indenting.
12 * Revision 1.1 87/06/04 01:29:32 wesommer
18 static char *rcsid_sms_query_c = "$Header$";
21 #include "sms_private.h"
24 * This routine is the primary external interface to the sms library.
26 * It builds a new argument vector with the query handle prepended,
27 * and calls sms_query_internal.
30 int sms_query(name, argc, argv, callproc, callarg)
31 char *name; /* Query name */
32 int argc; /* Arg count */
33 char **argv; /* Args */
34 int (*callproc)(); /* Callback procedure */
35 char *callarg; /* Callback argument */
37 register char **nargv = (char **)malloc(sizeof(char *) * (argc+1));
38 register int status = 0;
40 bcopy((char *)argv, (char *)(nargv+1), sizeof(char *) * argc);
41 status = sms_query_internal(argc+1, nargv, callproc, callarg);
46 * This routine makes an SMS query.
48 * argv[0] is the query name.
49 * argv[1..argc-1] are the query arguments.
51 * callproc is called once for each returned value, with arguments
52 * argc, argv, and callarg.
53 * If it returns a non-zero value, further calls to it are not done, and
54 * all future data from the server is ignored (there should be some
55 * way to send it a quench..)
58 int sms_query_internal(argc, argv, callproc, callarg)
59 int argc; /* Arg count */
60 char **argv; /* Args */
61 int (*callproc)(); /* Callback procedure */
62 char *callarg; /* Callback argument */
66 register sms_params *params = NULL;
67 sms_params *reply = NULL;
68 int stopcallbacks = 0;
73 params->sms_procno = SMS_QUERY;
74 params->sms_argc = argc;
75 params->sms_argl = NULL;
76 params->sms_argv = argv;
78 if ((status = sms_do_call(params, &reply)))
81 while ((status = reply->sms_status) == SMS_MORE_DATA) {
84 (*callproc)(reply->sms_argc, reply->sms_argv, callarg);
85 sms_destroy_reply(reply);
88 initialize_operation(_sms_recv_op, sms_start_recv, &reply,
90 queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
92 complete_operation(_sms_recv_op);
93 if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
99 sms_destroy_reply(reply);
107 * c-continued-statement-offset: 4
109 * c-argdecl-indent: 4