]> andersk Git - moira.git/blame - lib/mr_query.c
Prevent recursive query call.
[moira.git] / lib / mr_query.c
CommitLineData
92eb0760 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 *
8 * $Log$
4bff4d9d 9 * Revision 1.3 1987-08-02 21:49:53 wesommer
10 * Prevent recursive query call.
92eb0760 11 *
4bff4d9d 12 * Revision 1.2 87/06/16 17:48:58 wesommer
13 * Clean up memory allocation, indenting.
14 *
83e80378 15 * Revision 1.1 87/06/04 01:29:32 wesommer
16 * Initial revision
17 *
92eb0760 18 */
19
20#ifndef lint
21static char *rcsid_sms_query_c = "$Header$";
22#endif lint
23
24#include "sms_private.h"
25
83e80378 26/*
27 * This routine is the primary external interface to the sms library.
28 *
29 * It builds a new argument vector with the query handle prepended,
30 * and calls sms_query_internal.
31 */
4bff4d9d 32int level = 0;
83e80378 33
92eb0760 34int sms_query(name, argc, argv, callproc, callarg)
83e80378 35 char *name; /* Query name */
36 int argc; /* Arg count */
37 char **argv; /* Args */
38 int (*callproc)(); /* Callback procedure */
39 char *callarg; /* Callback argument */
92eb0760 40{
83e80378 41 register char **nargv = (char **)malloc(sizeof(char *) * (argc+1));
42 register int status = 0;
43 nargv[0] = name;
44 bcopy((char *)argv, (char *)(nargv+1), sizeof(char *) * argc);
45 status = sms_query_internal(argc+1, nargv, callproc, callarg);
46 free(nargv);
47 return status;
48}
49/*
50 * This routine makes an SMS query.
51 *
52 * argv[0] is the query name.
53 * argv[1..argc-1] are the query arguments.
54 *
55 * callproc is called once for each returned value, with arguments
56 * argc, argv, and callarg.
57 * If it returns a non-zero value, further calls to it are not done, and
58 * all future data from the server is ignored (there should be some
59 * way to send it a quench..)
60 */
92eb0760 61
83e80378 62int sms_query_internal(argc, argv, callproc, callarg)
63 int argc; /* Arg count */
64 char **argv; /* Args */
65 int (*callproc)(); /* Callback procedure */
66 char *callarg; /* Callback argument */
67{
68 int status;
69 sms_params params_st;
70 register sms_params *params = NULL;
71 sms_params *reply = NULL;
72 int stopcallbacks = 0;
4bff4d9d 73
74 if (level) return SMS_QUERY_NOT_REENTRANT;
75 level++;
83e80378 76
77 CHECK_CONNECTED;
92eb0760 78
83e80378 79 params = &params_st;
80 params->sms_procno = SMS_QUERY;
81 params->sms_argc = argc;
82 params->sms_argl = NULL;
83 params->sms_argv = argv;
92eb0760 84
83e80378 85 if ((status = sms_do_call(params, &reply)))
86 goto punt;
92eb0760 87
83e80378 88 while ((status = reply->sms_status) == SMS_MORE_DATA) {
89 if (!stopcallbacks)
90 stopcallbacks =
92eb0760 91 (*callproc)(reply->sms_argc, reply->sms_argv, callarg);
92eb0760 92 sms_destroy_reply(reply);
83e80378 93 reply = NULL;
94
95 initialize_operation(_sms_recv_op, sms_start_recv, &reply,
96 (int (*)())NULL);
97 queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
98
99 complete_operation(_sms_recv_op);
100 if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
101 sms_disconnect();
4bff4d9d 102 status = SMS_ABORTED;
103 goto punt_1;
92eb0760 104 }
83e80378 105 }
106punt:
107 sms_destroy_reply(reply);
4bff4d9d 108punt_1:
109 level--;
83e80378 110 return status;
92eb0760 111}
83e80378 112/*
113 * Local Variables:
114 * mode: c
115 * c-indent-level: 4
116 * c-continued-statement-offset: 4
117 * c-brace-offset: -4
118 * c-argdecl-indent: 4
119 * c-label-offset: -4
120 * End:
121 */
This page took 0.100045 seconds and 5 git commands to generate.