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"
22 * This routine is the primary external interface to the mr library.
24 * It builds a new argument vector with the query handle prepended,
25 * and calls mr_query_internal.
29 int mr_query(char *name, int argc, char **argv,
30 int (*callproc)(), char *callarg)
32 char **nargv = malloc(sizeof(char *) * (argc + 1));
36 memcpy(nargv + 1, argv, sizeof(char *) * argc);
37 status = mr_query_internal(argc + 1, nargv, callproc, callarg);
43 * This routine makes an MR query.
45 * argv[0] is the query name.
46 * argv[1..argc-1] are the query arguments.
48 * callproc is called once for each returned value, with arguments
49 * argc, argv, and callarg.
50 * If it returns a non-zero value, further calls to it are not done, and
51 * all future data from the server is ignored (there should be some
52 * way to send it a quench..)
55 int mr_query_internal(int argc, char **argv, int (*callproc)(), char *callarg)
59 mr_params *params = NULL;
60 mr_params *reply = NULL;
61 int stopcallbacks = 0;
64 return MR_QUERY_NOT_REENTRANT;
70 params->mr_version_no = sending_version_no;
71 params->mr_procno = MR_QUERY;
72 params->mr_argc = argc;
73 params->mr_argl = NULL;
74 params->mr_argv = argv;
76 if ((status = mr_do_call(params, &reply)))
79 while ((status = reply->mr_status) == MR_MORE_DATA)
82 stopcallbacks = (*callproc)(reply->mr_argc, reply->mr_argv, callarg);
83 mr_destroy_reply(reply);
86 initialize_operation(_mr_recv_op, mr_start_recv, &reply, NULL);
87 queue_operation(_mr_conn, CON_INPUT, _mr_recv_op);
89 mr_complete_operation(_mr_recv_op);
90 if (OP_STATUS(_mr_recv_op) != OP_COMPLETE)
98 mr_destroy_reply(reply);