]> andersk Git - moira.git/blame - lib/mr_ops.c
sms -> mr
[moira.git] / lib / mr_ops.c
CommitLineData
de56407f 1/*
2 * $Source$
3 * $Author$
4 * $Header$
5 *
5f9f27e4 6 * Copyright (C) 1987, 1989 by the Massachusetts Institute of Technology
babbc197 7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
de56407f 9 *
10 * This routine is part of the client library. It handles
5f9f27e4 11 * the protocol operations: invoking an update and getting the
12 * SMS message of the day.
de56407f 13 */
14
15#ifndef lint
16static char *rcsid_sms_do_update_c = "$Header$";
17#endif lint
18
babbc197 19#include <mit-copyright.h>
de56407f 20#include "sms_private.h"
21
5f9f27e4 22
23/* Invoke a DCM update. */
24
de56407f 25int sms_do_update()
26{
27 int status;
28 sms_params param_st;
29 struct sms_params *params = NULL;
30 struct sms_params *reply = NULL;
31
32 CHECK_CONNECTED;
33 params = &param_st;
89371417 34 params->sms_version_no = sending_version_no;
de56407f 35 params->sms_procno = SMS_DO_UPDATE;
36 params->sms_argc = 0;
37 params->sms_argl = NULL;
38 params->sms_argv = NULL;
39
40 if ((status = sms_do_call(params, &reply)) == 0)
41 status = reply->sms_status;
42
43 sms_destroy_reply(reply);
44
45 return status;
46}
47
5f9f27e4 48
49/* Get the SMS motd. This returns an SMS status, and motd will either
50 * point to NULL or the motd in a static buffer.
de56407f 51 */
5f9f27e4 52
53int sms_motd(motd)
54char **motd;
55{
56 int status;
57 sms_params param_st;
58 struct sms_params *params = NULL;
59 struct sms_params *reply = NULL;
60 static char buffer[1024];
61
62 *motd = NULL;
63 CHECK_CONNECTED;
64 params = &param_st;
65 params->sms_version_no = sending_version_no;
66 params->sms_procno = SMS_MOTD;
67 params->sms_argc = 0;
68 params->sms_argl = NULL;
69 params->sms_argv = NULL;
70
71 if ((status = sms_do_call(params, &reply)))
72 goto punt;
73
74 while ((status = reply->sms_status) == SMS_MORE_DATA) {
75 if (reply->sms_argc > 0) {
76 strncpy(buffer, reply->sms_argv[0], sizeof(buffer));
77 *motd = buffer;
78 }
79 sms_destroy_reply(reply);
80 reply = NULL;
81
82 initialize_operation(_sms_recv_op, sms_start_recv, &reply,
83 (int (*)())NULL);
84 queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
85
2bf6c690 86 sms_complete_operation(_sms_recv_op);
5f9f27e4 87 if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
88 sms_disconnect();
89 status = SMS_ABORTED;
90 return(status);
91 }
92 }
93 punt:
94 sms_destroy_reply(reply);
6ffcc74c 95 /* for backwards compatability */
96 if (status == SMS_UNKNOWN_PROC)
97 return(0);
98 else
99 return(status);
5f9f27e4 100}
2bf6c690 101
102
103/* Tell the library to take care of another input source while it is
104 * processing a query. For instance, an X toolkit application would
105 * do something like
106 * sms_set_alternate_input(ConnectionNumber(XtDisplay(widget)), doxinput);
107 * where doxinput is defined as:
108 * doxinput() {
109 * extern Widget toplevel;
110 * XEvent event;
111 * while (XPending(XtDisplay(toplevel))) {
112 * XNextEvent(XtDisplay(toplevel), &event);
113 * XtDispatchEvent(&event);
114 * }
115 * XFlush(XtDisplay(toplevel));
116 * }
117 */
118
119static int sms_alternate_input = 0;
120static int (*sms_alternate_handler)();
121
122int sms_set_alternate_input(fd, proc)
123int fd;
124int (*proc)();
125{
126 if (sms_alternate_input != 0)
127 return(SMS_ALREADY_CONNECTED);
128 sms_alternate_input = fd;
129 sms_alternate_handler = proc;
130 return(SMS_SUCCESS);
131}
132
133
134/* This is used by the parts of the library that must wait for GDB. It
135 * handles alternate input streams (such as X) as well.
136 */
137
138sms_complete_operation(op)
139OPERATION op;
140{
141 long infd, outfd, exfd;
142 int rc;
143
144 gdb_progress(); /* try for an immediate completion */
145
146 if (sms_alternate_input == 0)
147 return(complete_operation(op));
148
149 infd = (1<<sms_alternate_input);
150 outfd = exfd = 0;
151
152 while(op->status != OP_COMPLETE && op->status != OP_CANCELLED) {
153 rc = con_select(sms_alternate_input, (fd_set *)&infd, (fd_set *)&outfd,
154 (fd_set *)&exfd, (struct timeval *)NULL);
155 if (rc > 0 && sms_alternate_handler) {
156 (*sms_alternate_handler)();
157 }
158 }
159 return(op->status);
160}
161
This page took 0.079288 seconds and 5 git commands to generate.