]> andersk Git - moira.git/blame - lib/mr_query.c
added the function lowercase()
[moira.git] / lib / mr_query.c
CommitLineData
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
13static char *rcsid_sms_query_c = "$Header$";
14#endif lint
15
babbc197 16#include <mit-copyright.h>
8defc06b 17#include "mr_private.h"
92eb0760 18
83e80378 19/*
8defc06b 20 * This routine is the primary external interface to the mr library.
83e80378 21 *
22 * It builds a new argument vector with the query handle prepended,
8defc06b 23 * and calls mr_query_internal.
83e80378 24 */
4bff4d9d 25int level = 0;
83e80378 26
8defc06b 27int mr_query(name, argc, argv, callproc, callarg)
83e80378 28 char *name; /* Query name */
29 int argc; /* Arg count */
30 char **argv; /* Args */
31 int (*callproc)(); /* Callback procedure */
32 char *callarg; /* Callback argument */
92eb0760 33{
83e80378 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);
8defc06b 38 status = mr_query_internal(argc+1, nargv, callproc, callarg);
83e80378 39 free(nargv);
40 return status;
41}
42/*
8defc06b 43 * This routine makes an MR query.
83e80378 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 */
92eb0760 54
8defc06b 55int mr_query_internal(argc, argv, callproc, callarg)
83e80378 56 int argc; /* Arg count */
57 char **argv; /* Args */
58 int (*callproc)(); /* Callback procedure */
59 char *callarg; /* Callback argument */
60{
61 int status;
8defc06b 62 mr_params params_st;
63 register mr_params *params = NULL;
64 mr_params *reply = NULL;
83e80378 65 int stopcallbacks = 0;
4bff4d9d 66
8defc06b 67 if (level) return MR_QUERY_NOT_REENTRANT;
83e80378 68
69 CHECK_CONNECTED;
d0dbd4ea 70 level++;
92eb0760 71
89371417 72 params = &params_st;
8defc06b 73 params->mr_version_no = sending_version_no;
74 params->mr_procno = MR_QUERY;
75 params->mr_argc = argc;
76 params->mr_argl = NULL;
77 params->mr_argv = argv;
92eb0760 78
8defc06b 79 if ((status = mr_do_call(params, &reply)))
83e80378 80 goto punt;
92eb0760 81
8defc06b 82 while ((status = reply->mr_status) == MR_MORE_DATA) {
83e80378 83 if (!stopcallbacks)
84 stopcallbacks =
8defc06b 85 (*callproc)(reply->mr_argc, reply->mr_argv, callarg);
86 mr_destroy_reply(reply);
83e80378 87 reply = NULL;
88
8defc06b 89 initialize_operation(_mr_recv_op, mr_start_recv, &reply,
83e80378 90 (int (*)())NULL);
8defc06b 91 queue_operation(_mr_conn, CON_INPUT, _mr_recv_op);
83e80378 92
8defc06b 93 mr_complete_operation(_mr_recv_op);
94 if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) {
95 mr_disconnect();
96 status = MR_ABORTED;
4bff4d9d 97 goto punt_1;
92eb0760 98 }
83e80378 99 }
100punt:
8defc06b 101 mr_destroy_reply(reply);
4bff4d9d 102punt_1:
103 level--;
83e80378 104 return status;
92eb0760 105}
This page took 0.273487 seconds and 5 git commands to generate.