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