6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
13 static char *rcsid_sms_query_c = "$Header$";
16 #include <mit-copyright.h>
17 #include "mr_private.h"
21 * This routine is the primary external interface to the mr library.
23 * It builds a new argument vector with the query handle prepended,
24 * and calls mr_query_internal.
28 int mr_query(name, argc, argv, callproc, callarg)
29 char *name; /* Query name */
30 int argc; /* Arg count */
31 char **argv; /* Args */
32 int (*callproc)(); /* Callback procedure */
33 char *callarg; /* Callback argument */
35 register char **nargv = (char **)malloc(sizeof(char *) * (argc+1));
36 register int status = 0;
38 memcpy((char *)(nargv+1), (char *)argv, sizeof(char *) * argc);
39 status = mr_query_internal(argc+1, nargv, callproc, callarg);
44 * This routine makes an MR query.
46 * argv[0] is the query name.
47 * argv[1..argc-1] are the query arguments.
49 * callproc is called once for each returned value, with arguments
50 * argc, argv, and callarg.
51 * If it returns a non-zero value, further calls to it are not done, and
52 * all future data from the server is ignored (there should be some
53 * way to send it a quench..)
56 int mr_query_internal(argc, argv, callproc, callarg)
57 int argc; /* Arg count */
58 char **argv; /* Args */
59 int (*callproc)(); /* Callback procedure */
60 char *callarg; /* Callback argument */
64 register mr_params *params = NULL;
65 mr_params *reply = NULL;
66 int stopcallbacks = 0;
68 if (level) return MR_QUERY_NOT_REENTRANT;
74 params->mr_version_no = sending_version_no;
75 params->mr_procno = MR_QUERY;
76 params->mr_argc = argc;
77 params->mr_argl = NULL;
78 params->mr_argv = argv;
80 if ((status = mr_do_call(params, &reply)))
83 while ((status = reply->mr_status) == MR_MORE_DATA) {
86 (*callproc)(reply->mr_argc, reply->mr_argv, callarg);
87 mr_destroy_reply(reply);
90 initialize_operation(_mr_recv_op, mr_start_recv, &reply,
92 queue_operation(_mr_conn, CON_INPUT, _mr_recv_op);
94 mr_complete_operation(_mr_recv_op);
95 if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) {
102 mr_destroy_reply(reply);