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