]> andersk Git - moira.git/blob - lib/mr_query.c
Prevent recursive query call.
[moira.git] / lib / mr_query.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987 by the Massachusetts Institute of Technology
7  *
8  *      $Log$
9  *      Revision 1.3  1987-08-02 21:49:53  wesommer
10  *      Prevent recursive query call.
11  *
12  * Revision 1.2  87/06/16  17:48:58  wesommer
13  * Clean up memory allocation, indenting.
14  * 
15  * Revision 1.1  87/06/04  01:29:32  wesommer
16  * Initial revision
17  * 
18  */
19
20 #ifndef lint
21 static char *rcsid_sms_query_c = "$Header$";
22 #endif lint
23
24 #include "sms_private.h"
25
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  */
32 int level = 0;
33
34 int sms_query(name, argc, argv, callproc, callarg)
35     char *name;         /* Query name */
36     int argc;           /* Arg count */
37     char **argv;                /* Args */
38     int (*callproc)();  /* Callback procedure */
39     char *callarg;              /* Callback argument */
40 {
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  */
61
62 int 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;
73
74     if (level) return SMS_QUERY_NOT_REENTRANT;
75     level++;
76     
77     CHECK_CONNECTED;
78
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;
84         
85     if ((status = sms_do_call(params, &reply)))
86         goto punt;
87
88     while ((status = reply->sms_status) == SMS_MORE_DATA) {
89         if (!stopcallbacks) 
90             stopcallbacks =
91                 (*callproc)(reply->sms_argc, reply->sms_argv, callarg);
92         sms_destroy_reply(reply);
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();
102             status = SMS_ABORTED;
103             goto punt_1;
104         }
105     }   
106 punt:
107     sms_destroy_reply(reply);
108 punt_1:
109     level--;
110     return status;
111 }
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.284824 seconds and 5 git commands to generate.