]>
Commit | Line | Data |
---|---|---|
92eb0760 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
7 | * | |
8 | * $Log$ | |
89371417 | 9 | * Revision 1.5 1988-04-19 12:38:41 mar |
10 | * pass version number on queries | |
92eb0760 | 11 | * |
89371417 | 12 | * Revision 1.4 87/08/22 17:11:16 wesommer |
13 | * Increment the nesting level only after we know we're connected. | |
14 | * | |
d0dbd4ea | 15 | * Revision 1.3 87/08/02 21:49:53 wesommer |
16 | * Prevent recursive query call. | |
17 | * | |
4bff4d9d | 18 | * Revision 1.2 87/06/16 17:48:58 wesommer |
19 | * Clean up memory allocation, indenting. | |
20 | * | |
83e80378 | 21 | * Revision 1.1 87/06/04 01:29:32 wesommer |
22 | * Initial revision | |
23 | * | |
92eb0760 | 24 | */ |
25 | ||
26 | #ifndef lint | |
27 | static char *rcsid_sms_query_c = "$Header$"; | |
28 | #endif lint | |
29 | ||
30 | #include "sms_private.h" | |
31 | ||
83e80378 | 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 | */ | |
4bff4d9d | 38 | int level = 0; |
83e80378 | 39 | |
92eb0760 | 40 | int sms_query(name, argc, argv, callproc, callarg) |
83e80378 | 41 | char *name; /* Query name */ |
42 | int argc; /* Arg count */ | |
43 | char **argv; /* Args */ | |
44 | int (*callproc)(); /* Callback procedure */ | |
45 | char *callarg; /* Callback argument */ | |
92eb0760 | 46 | { |
83e80378 | 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 | */ | |
92eb0760 | 67 | |
83e80378 | 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; | |
4bff4d9d | 79 | |
80 | if (level) return SMS_QUERY_NOT_REENTRANT; | |
83e80378 | 81 | |
82 | CHECK_CONNECTED; | |
d0dbd4ea | 83 | level++; |
92eb0760 | 84 | |
89371417 | 85 | params = ¶ms_st; |
86 | params->sms_version_no = sending_version_no; | |
83e80378 | 87 | params->sms_procno = SMS_QUERY; |
88 | params->sms_argc = argc; | |
89 | params->sms_argl = NULL; | |
90 | params->sms_argv = argv; | |
92eb0760 | 91 | |
83e80378 | 92 | if ((status = sms_do_call(params, &reply))) |
93 | goto punt; | |
92eb0760 | 94 | |
83e80378 | 95 | while ((status = reply->sms_status) == SMS_MORE_DATA) { |
96 | if (!stopcallbacks) | |
97 | stopcallbacks = | |
92eb0760 | 98 | (*callproc)(reply->sms_argc, reply->sms_argv, callarg); |
92eb0760 | 99 | sms_destroy_reply(reply); |
83e80378 | 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(); | |
4bff4d9d | 109 | status = SMS_ABORTED; |
110 | goto punt_1; | |
92eb0760 | 111 | } |
83e80378 | 112 | } |
113 | punt: | |
114 | sms_destroy_reply(reply); | |
4bff4d9d | 115 | punt_1: |
116 | level--; | |
83e80378 | 117 | return status; |
92eb0760 | 118 | } |
83e80378 | 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 | */ |