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