]> andersk Git - moira.git/blame - lib/mr_query.c
Command line printer manipulation client, and build goo.
[moira.git] / lib / mr_query.c
CommitLineData
fa59b86f 1/* $Id$
7ac48069 2 *
3 * Perform a Moira query
92eb0760 4 *
7ac48069 5 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
5eaef520 8 *
92eb0760 9 */
10
babbc197 11#include <mit-copyright.h>
7ac48069 12#include <moira.h>
8defc06b 13#include "mr_private.h"
7ac48069 14
a3bbcc2b 15#include <errno.h>
a43ce477 16#include <stdlib.h>
7ac48069 17#include <string.h>
18
19RCSID("$Header$");
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 27static int level = 0;
83e80378 28
5eaef520 29int mr_query(char *name, int argc, char **argv,
7ac48069 30 int (*callproc)(int, char **, void *), void *callarg)
92eb0760 31{
85330553 32 int status, stopcallbacks = 0;
33 mr_params params, reply;
5eaef520 34
85330553 35 CHECK_CONNECTED;
5eaef520 36 if (level)
37 return MR_QUERY_NOT_REENTRANT;
38
85330553 39 params.u.mr_procno = MR_QUERY;
40 params.mr_argc = argc + 1;
41 params.mr_argl = NULL;
42 params.mr_argv = malloc(sizeof(char *) * (argc + 1));
43 if (!params.mr_argv)
44 return ENOMEM;
45 params.mr_argv[0] = name;
46 memcpy(params.mr_argv + 1, argv, sizeof(char *) * argc);
92eb0760 47
85330553 48 level++;
49 if ((status = mr_do_call(&params, &reply)))
5eaef520 50 goto punt;
92eb0760 51
85330553 52 while ((status = reply.u.mr_status) == MR_MORE_DATA)
5eaef520 53 {
0046242c 54 if (callproc && !stopcallbacks)
85330553 55 stopcallbacks = (*callproc)(reply.mr_argc, reply.mr_argv, callarg);
5eaef520 56 mr_destroy_reply(reply);
83e80378 57
85330553 58 if (mr_receive(_mr_conn, &reply) != MR_SUCCESS)
5eaef520 59 {
60 mr_disconnect();
61 status = MR_ABORTED;
62 goto punt_1;
92eb0760 63 }
5eaef520 64 }
85330553 65
83e80378 66punt:
5eaef520 67 mr_destroy_reply(reply);
4bff4d9d 68punt_1:
5eaef520 69 level--;
85330553 70 free(params.mr_argv);
71
5eaef520 72 return status;
92eb0760 73}
This page took 0.132707 seconds and 5 git commands to generate.