]>
Commit | Line | Data |
---|---|---|
92eb0760 | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
babbc197 | 7 | * For copying and distribution information, please see the file |
8 | * <mit-copyright.h>. | |
83e80378 | 9 | * |
92eb0760 | 10 | */ |
11 | ||
12 | #ifndef lint | |
13 | static char *rcsid_sms_query_c = "$Header$"; | |
14 | #endif lint | |
15 | ||
babbc197 | 16 | #include <mit-copyright.h> |
8defc06b | 17 | #include "mr_private.h" |
8fd777cf | 18 | #include <string.h> |
92eb0760 | 19 | |
83e80378 | 20 | /* |
8defc06b | 21 | * This routine is the primary external interface to the mr library. |
83e80378 | 22 | * |
23 | * It builds a new argument vector with the query handle prepended, | |
8defc06b | 24 | * and calls mr_query_internal. |
83e80378 | 25 | */ |
4bff4d9d | 26 | int level = 0; |
83e80378 | 27 | |
8defc06b | 28 | int mr_query(name, argc, argv, callproc, callarg) |
83e80378 | 29 | char *name; /* Query name */ |
30 | int argc; /* Arg count */ | |
31 | char **argv; /* Args */ | |
32 | int (*callproc)(); /* Callback procedure */ | |
33 | char *callarg; /* Callback argument */ | |
92eb0760 | 34 | { |
83e80378 | 35 | register char **nargv = (char **)malloc(sizeof(char *) * (argc+1)); |
36 | register int status = 0; | |
37 | nargv[0] = name; | |
8fd777cf | 38 | memcpy((char *)(nargv+1), (char *)argv, sizeof(char *) * argc); |
8defc06b | 39 | status = mr_query_internal(argc+1, nargv, callproc, callarg); |
83e80378 | 40 | free(nargv); |
41 | return status; | |
42 | } | |
43 | /* | |
8defc06b | 44 | * This routine makes an MR query. |
83e80378 | 45 | * |
46 | * argv[0] is the query name. | |
47 | * argv[1..argc-1] are the query arguments. | |
48 | * | |
49 | * callproc is called once for each returned value, with arguments | |
50 | * argc, argv, and callarg. | |
51 | * If it returns a non-zero value, further calls to it are not done, and | |
52 | * all future data from the server is ignored (there should be some | |
53 | * way to send it a quench..) | |
54 | */ | |
92eb0760 | 55 | |
8defc06b | 56 | int mr_query_internal(argc, argv, callproc, callarg) |
83e80378 | 57 | int argc; /* Arg count */ |
58 | char **argv; /* Args */ | |
59 | int (*callproc)(); /* Callback procedure */ | |
60 | char *callarg; /* Callback argument */ | |
61 | { | |
62 | int status; | |
8defc06b | 63 | mr_params params_st; |
64 | register mr_params *params = NULL; | |
65 | mr_params *reply = NULL; | |
83e80378 | 66 | int stopcallbacks = 0; |
4bff4d9d | 67 | |
8defc06b | 68 | if (level) return MR_QUERY_NOT_REENTRANT; |
83e80378 | 69 | |
70 | CHECK_CONNECTED; | |
d0dbd4ea | 71 | level++; |
92eb0760 | 72 | |
89371417 | 73 | params = ¶ms_st; |
8defc06b | 74 | params->mr_version_no = sending_version_no; |
75 | params->mr_procno = MR_QUERY; | |
76 | params->mr_argc = argc; | |
77 | params->mr_argl = NULL; | |
78 | params->mr_argv = argv; | |
92eb0760 | 79 | |
8defc06b | 80 | if ((status = mr_do_call(params, &reply))) |
83e80378 | 81 | goto punt; |
92eb0760 | 82 | |
8defc06b | 83 | while ((status = reply->mr_status) == MR_MORE_DATA) { |
83e80378 | 84 | if (!stopcallbacks) |
85 | stopcallbacks = | |
8defc06b | 86 | (*callproc)(reply->mr_argc, reply->mr_argv, callarg); |
87 | mr_destroy_reply(reply); | |
83e80378 | 88 | reply = NULL; |
89 | ||
8defc06b | 90 | initialize_operation(_mr_recv_op, mr_start_recv, &reply, |
83e80378 | 91 | (int (*)())NULL); |
8defc06b | 92 | queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); |
83e80378 | 93 | |
8defc06b | 94 | mr_complete_operation(_mr_recv_op); |
95 | if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) { | |
96 | mr_disconnect(); | |
97 | status = MR_ABORTED; | |
4bff4d9d | 98 | goto punt_1; |
92eb0760 | 99 | } |
83e80378 | 100 | } |
101 | punt: | |
8defc06b | 102 | mr_destroy_reply(reply); |
4bff4d9d | 103 | punt_1: |
104 | level--; | |
83e80378 | 105 | return status; |
92eb0760 | 106 | } |