]> andersk Git - moira.git/blob - lib/mr_query.c
added UREG_HALF_ENROLLED; SMS->Moira
[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  *      For copying and distribution information, please see the file
8  *      <mit-copyright.h>.
9  * 
10  */
11
12 #ifndef lint
13 static char *rcsid_sms_query_c = "$Header$";
14 #endif lint
15
16 #include <mit-copyright.h>
17 #include "sms_private.h"
18
19 /*
20  * This routine is the primary external interface to the sms library.
21  *
22  * It builds a new argument vector with the query handle prepended,
23  * and calls sms_query_internal.
24  */
25 int level = 0;
26
27 int sms_query(name, argc, argv, callproc, callarg)
28     char *name;         /* Query name */
29     int argc;           /* Arg count */
30     char **argv;                /* Args */
31     int (*callproc)();  /* Callback procedure */
32     char *callarg;              /* Callback argument */
33 {
34     register char **nargv = (char **)malloc(sizeof(char *) * (argc+1));
35     register int status = 0;
36     nargv[0] = name;
37     bcopy((char *)argv, (char *)(nargv+1), sizeof(char *) * argc);
38     status = sms_query_internal(argc+1, nargv, callproc, callarg);
39     free(nargv);
40     return status;
41 }
42 /*
43  * This routine makes an SMS query.
44  *
45  * argv[0] is the query name.
46  * argv[1..argc-1] are the query arguments.
47  *
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..)
53  */
54
55 int sms_query_internal(argc, argv, callproc, callarg)
56     int argc;           /* Arg count */
57     char **argv;                /* Args */
58     int (*callproc)();  /* Callback procedure */
59     char *callarg;              /* Callback argument */
60 {
61     int status;
62     sms_params params_st;
63     register sms_params *params = NULL;
64     sms_params *reply = NULL;
65     int stopcallbacks = 0;
66
67     if (level) return SMS_QUERY_NOT_REENTRANT;
68     
69     CHECK_CONNECTED;
70     level++;
71
72     params = &params_st; 
73     params->sms_version_no = sending_version_no;
74     params->sms_procno = SMS_QUERY;
75     params->sms_argc = argc;
76     params->sms_argl = NULL;
77     params->sms_argv = argv;
78         
79     if ((status = sms_do_call(params, &reply)))
80         goto punt;
81
82     while ((status = reply->sms_status) == SMS_MORE_DATA) {
83         if (!stopcallbacks) 
84             stopcallbacks =
85                 (*callproc)(reply->sms_argc, reply->sms_argv, callarg);
86         sms_destroy_reply(reply);
87         reply = NULL;
88
89         initialize_operation(_sms_recv_op, sms_start_recv, &reply,
90                              (int (*)())NULL);
91         queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
92
93         sms_complete_operation(_sms_recv_op);
94         if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
95             sms_disconnect();
96             status = SMS_ABORTED;
97             goto punt_1;
98         }
99     }   
100 punt:
101     sms_destroy_reply(reply);
102 punt_1:
103     level--;
104     return status;
105 }
This page took 0.049593 seconds and 5 git commands to generate.