]>
Commit | Line | Data |
---|---|---|
de56407f | 1 | /* |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
5 | ||
6 | #ifndef lint | |
7 | static char *rcsid_dispatch_c = "$Header$"; | |
8 | #endif lint | |
9 | ||
10 | #include <stdio.h> | |
11 | #include "gdb.h" | |
12 | #include <errno.h> | |
13 | #include <strings.h> | |
14 | #include "update.h" | |
15 | #include "sms_update_int.h" | |
16 | #include "smsu_int.h" | |
17 | ||
18 | /* XXX */ | |
19 | #include "kludge.h" | |
20 | /* XXX */ | |
21 | ||
22 | extern int auth_001(), exec_001(), inst_001(), xfer_001(); | |
23 | extern int xfer_002(), exec_002(); | |
24 | ||
25 | extern int sync_proc(), quit(); | |
26 | ||
27 | extern void gdb_debug(); | |
28 | extern int exit(), abort(), errno; | |
29 | ||
30 | CONNECTION conn; | |
31 | int code; | |
32 | char *whoami; | |
33 | ||
34 | #define send_int(n) \ | |
35 | (_send_int=(n),send_object(conn,(char *)&_send_int,INTEGER_T)) | |
36 | int _send_int; | |
37 | ||
38 | struct _dt { | |
39 | char *str; | |
40 | int (*proc)(); | |
41 | } dispatch_table[] = { | |
42 | { "INST_001", inst_001 }, | |
43 | { "AUTH_001", auth_001 }, | |
44 | { "XFER_001", xfer_001 }, | |
45 | { "EXEC_001", exec_001 }, | |
46 | { "XFER_002", xfer_002 }, | |
47 | { "EXEC_002", exec_002 }, | |
48 | { "quit", quit }, | |
49 | { (char *)NULL, abort } | |
50 | }; | |
51 | ||
52 | /* | |
53 | * general scratch space -- useful for building | |
54 | * error messages et al... | |
55 | */ | |
56 | char buf[BUFSIZ]; | |
57 | err(code, fmt) | |
58 | int code; | |
59 | char *fmt; | |
60 | { | |
61 | sprintf(buf, fmt, error_message(code)); | |
62 | sms_log_error(buf); | |
63 | } | |
64 | ||
65 | main(argc, argv) | |
66 | int argc; | |
67 | char **argv; | |
68 | { | |
69 | STRING str; | |
70 | struct _dt *d; | |
71 | ||
72 | #ifdef DEBUG | |
73 | gdb_debug(GDB_NOFORK); | |
74 | #endif /* DEBUG */ | |
75 | ||
76 | whoami = rindex(argv[0], '/'); | |
77 | if (whoami) | |
78 | whoami++; | |
79 | else | |
80 | whoami = argv[0]; | |
81 | ||
82 | /* interpret arguments here */ | |
83 | if (argc != 1) { | |
84 | fprintf(stderr, "Usage: %s\n", whoami); | |
85 | exit(1); | |
86 | } | |
87 | /* well, sort of... */ | |
88 | ||
89 | umask(0077); | |
90 | sms_update_initialize(); | |
91 | init_smsU_err_tbl(); | |
92 | ||
93 | /* wait for connection */ | |
94 | gdb_init(); | |
95 | conn = create_forking_server(SERVICE_NAME, 0); | |
96 | if (!conn) { | |
97 | err(errno, "%s: can't get connection"); | |
98 | exit(1); | |
99 | } | |
100 | if (connection_status(conn) == CON_STOPPED) { | |
101 | com_err(whoami, connection_errno(conn), ": can't get connection"); | |
102 | exit(1); | |
103 | } | |
104 | ||
105 | sms_log_info("got connection"); | |
106 | /* got a connection; loop forever */ | |
107 | while (1) { | |
108 | register char *cp; | |
109 | code = receive_object(conn, (char *)&str, STRING_T); | |
110 | if (code) { | |
111 | err(connection_errno(conn), "%s: receiving command"); | |
112 | sever_connection(conn); | |
113 | exit(1); | |
114 | } | |
115 | cp = index(STRING_DATA(str), ' '); | |
116 | if (cp) | |
117 | *cp = '\0'; | |
118 | for (d = dispatch_table; d->str; d++) { | |
119 | if (!strcmp(d->str, STRING_DATA(str))) { | |
120 | if (cp) | |
121 | *cp = ' '; | |
122 | #ifdef DEBUG | |
123 | printf("got request: %s\n", STRING_DATA(str)); | |
124 | #endif /* DEBUG */ | |
125 | (void)(d->proc)(STRING_DATA(str)); | |
126 | goto ok; | |
127 | } | |
128 | } | |
129 | sprintf(buf, "unknown request received: %s\n", STRING_DATA(str)); | |
130 | sms_log_error(buf); | |
131 | code = send_int(SMSU_UNKNOWN_PROC); | |
132 | if (code) { | |
133 | err(connection_errno(conn), "%s: sending UNKNOWN_PROC"); | |
134 | } | |
135 | ok: | |
136 | string_free(&str); | |
137 | } | |
138 | } | |
139 | ||
140 | int | |
141 | send_ok() | |
142 | { | |
143 | static int zero = 0; | |
144 | return((code = send_object(conn, (char *)&zero, INTEGER_T))); | |
145 | } |