]>
Commit | Line | Data |
---|---|---|
de56407f | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
8defc06b | 6 | * Copyright (C) 1987, 1989, 1990 by the Massachusetts Institute of |
7 | * Technology | |
babbc197 | 8 | * For copying and distribution information, please see the file |
9 | * <mit-copyright.h>. | |
de56407f | 10 | * |
11 | * This routine is part of the client library. It handles | |
5f9f27e4 | 12 | * the protocol operations: invoking an update and getting the |
8defc06b | 13 | * MR message of the day. |
de56407f | 14 | */ |
15 | ||
16 | #ifndef lint | |
17 | static char *rcsid_sms_do_update_c = "$Header$"; | |
18 | #endif lint | |
19 | ||
babbc197 | 20 | #include <mit-copyright.h> |
f4c08abd | 21 | #include <string.h> |
8defc06b | 22 | #include "mr_private.h" |
de56407f | 23 | |
5f9f27e4 | 24 | |
25 | /* Invoke a DCM update. */ | |
26 | ||
8defc06b | 27 | int mr_do_update() |
de56407f | 28 | { |
29 | int status; | |
8defc06b | 30 | mr_params param_st; |
31 | struct mr_params *params = NULL; | |
32 | struct mr_params *reply = NULL; | |
de56407f | 33 | |
34 | CHECK_CONNECTED; | |
35 | params = ¶m_st; | |
8defc06b | 36 | params->mr_version_no = sending_version_no; |
37 | params->mr_procno = MR_DO_UPDATE; | |
38 | params->mr_argc = 0; | |
39 | params->mr_argl = NULL; | |
40 | params->mr_argv = NULL; | |
de56407f | 41 | |
8defc06b | 42 | if ((status = mr_do_call(params, &reply)) == 0) |
43 | status = reply->mr_status; | |
de56407f | 44 | |
8defc06b | 45 | mr_destroy_reply(reply); |
de56407f | 46 | |
47 | return status; | |
48 | } | |
49 | ||
5f9f27e4 | 50 | |
8defc06b | 51 | /* Get the MR motd. This returns an MR status, and motd will either |
5f9f27e4 | 52 | * point to NULL or the motd in a static buffer. |
de56407f | 53 | */ |
5f9f27e4 | 54 | |
8defc06b | 55 | int mr_motd(motd) |
5f9f27e4 | 56 | char **motd; |
57 | { | |
58 | int status; | |
8defc06b | 59 | mr_params param_st; |
60 | struct mr_params *params = NULL; | |
61 | struct mr_params *reply = NULL; | |
5f9f27e4 | 62 | static char buffer[1024]; |
63 | ||
64 | *motd = NULL; | |
65 | CHECK_CONNECTED; | |
66 | params = ¶m_st; | |
8defc06b | 67 | params->mr_version_no = sending_version_no; |
68 | params->mr_procno = MR_MOTD; | |
69 | params->mr_argc = 0; | |
70 | params->mr_argl = NULL; | |
71 | params->mr_argv = NULL; | |
5f9f27e4 | 72 | |
8defc06b | 73 | if ((status = mr_do_call(params, &reply))) |
5f9f27e4 | 74 | goto punt; |
75 | ||
8defc06b | 76 | while ((status = reply->mr_status) == MR_MORE_DATA) { |
77 | if (reply->mr_argc > 0) { | |
78 | strncpy(buffer, reply->mr_argv[0], sizeof(buffer)); | |
5f9f27e4 | 79 | *motd = buffer; |
80 | } | |
8defc06b | 81 | mr_destroy_reply(reply); |
5f9f27e4 | 82 | reply = NULL; |
83 | ||
8defc06b | 84 | initialize_operation(_mr_recv_op, mr_start_recv, &reply, |
5f9f27e4 | 85 | (int (*)())NULL); |
8defc06b | 86 | queue_operation(_mr_conn, CON_INPUT, _mr_recv_op); |
5f9f27e4 | 87 | |
8defc06b | 88 | mr_complete_operation(_mr_recv_op); |
89 | if (OP_STATUS(_mr_recv_op) != OP_COMPLETE) { | |
90 | mr_disconnect(); | |
91 | status = MR_ABORTED; | |
5f9f27e4 | 92 | return(status); |
93 | } | |
94 | } | |
95 | punt: | |
8defc06b | 96 | mr_destroy_reply(reply); |
6ffcc74c | 97 | /* for backwards compatability */ |
8defc06b | 98 | if (status == MR_UNKNOWN_PROC) |
6ffcc74c | 99 | return(0); |
100 | else | |
101 | return(status); | |
5f9f27e4 | 102 | } |
2bf6c690 | 103 | |
104 | ||
105 | /* Tell the library to take care of another input source while it is | |
106 | * processing a query. For instance, an X toolkit application would | |
107 | * do something like | |
8defc06b | 108 | * mr_set_alternate_input(ConnectionNumber(XtDisplay(widget)), doxinput); |
2bf6c690 | 109 | * where doxinput is defined as: |
110 | * doxinput() { | |
111 | * extern Widget toplevel; | |
112 | * XEvent event; | |
113 | * while (XPending(XtDisplay(toplevel))) { | |
114 | * XNextEvent(XtDisplay(toplevel), &event); | |
115 | * XtDispatchEvent(&event); | |
116 | * } | |
117 | * XFlush(XtDisplay(toplevel)); | |
118 | * } | |
119 | */ | |
120 | ||
8defc06b | 121 | static int mr_alternate_input = 0; |
122 | static int (*mr_alternate_handler)(); | |
2bf6c690 | 123 | |
8defc06b | 124 | int mr_set_alternate_input(fd, proc) |
2bf6c690 | 125 | int fd; |
126 | int (*proc)(); | |
127 | { | |
8defc06b | 128 | if (mr_alternate_input != 0) |
129 | return(MR_ALREADY_CONNECTED); | |
130 | mr_alternate_input = fd; | |
131 | mr_alternate_handler = proc; | |
132 | return(MR_SUCCESS); | |
2bf6c690 | 133 | } |
134 | ||
135 | ||
136 | /* This is used by the parts of the library that must wait for GDB. It | |
137 | * handles alternate input streams (such as X) as well. | |
138 | */ | |
139 | ||
8defc06b | 140 | mr_complete_operation(op) |
2bf6c690 | 141 | OPERATION op; |
142 | { | |
143 | long infd, outfd, exfd; | |
144 | int rc; | |
145 | ||
146 | gdb_progress(); /* try for an immediate completion */ | |
147 | ||
8defc06b | 148 | if (mr_alternate_input == 0) |
2bf6c690 | 149 | return(complete_operation(op)); |
150 | ||
8defc06b | 151 | infd = (1<<mr_alternate_input); |
2bf6c690 | 152 | outfd = exfd = 0; |
153 | ||
154 | while(op->status != OP_COMPLETE && op->status != OP_CANCELLED) { | |
8defc06b | 155 | rc = con_select(mr_alternate_input, (fd_set *)&infd, (fd_set *)&outfd, |
2bf6c690 | 156 | (fd_set *)&exfd, (struct timeval *)NULL); |
8defc06b | 157 | if (rc > 0 && mr_alternate_handler) { |
158 | (*mr_alternate_handler)(); | |
2bf6c690 | 159 | } |
160 | } | |
161 | return(op->status); | |
162 | } | |
163 |