|
|
1.1 root 1: /*
2: ******************************************************************************
3: *
4: * Module: bb_server.c
5: *
6: * Functions:
7: * main() - The main routine, mostly generated by rpcgen
8: * bb_server_init() - Initialize all of the data structures.
9: * bb_get_ip() - Get the IP address of the calling function.
10: * billboard_prog_1() - The dispatch routine, generated by rpcgen.
11: *
12: *
13: ******************************************************************************
14: */
15:
16: /*
17: ******************************************************************************
18: * Include Files
19: ******************************************************************************
20: */
21: #include <stdio.h>
22: #include <syslog.h>
23: #include <rpc/rpc.h>
24: #include "common.h"
25: #include "protocol.h"
26: #include "server.h"
27:
28: static void billboard_prog_1();
29: char *itoa();
30:
31:
32:
33: /*************************************************************************
34: ** **
35: ** main() - The main server routine. This was generated by rpcgen. **
36: ** It was cut out of the rpcgen'ed code because there needs to be **
37: ** initialization done inside of main. **
38: ** **
39: *************************************************************************/
40: main()
41: {
42: register SVCXPRT *transp;
43:
44: (void) pmap_unset(BILLBOARD_PROG, BILLBOARD_VERS);
45:
46: transp = svcudp_create(RPC_ANYSOCK);
47: if (transp == NULL) {
48: fprintf(stderr, "cannot create udp service.");
49: exit(1);
50: }
51: if (!svc_register(transp, BILLBOARD_PROG, BILLBOARD_VERS, billboard_prog_1, IPPROTO_UDP)) {
52: fprintf(stderr, "unable to register (BILLBOARD_PROG, BILLBOARD_VERS, udp).");
53: exit(1);
54: }
55:
56: transp = svctcp_create(RPC_ANYSOCK, 0, 0);
57: if (transp == NULL) {
58: fprintf(stderr, "cannot create tcp service.");
59: exit(1);
60: }
61: if (!svc_register(transp, BILLBOARD_PROG, BILLBOARD_VERS, billboard_prog_1, IPPROTO_TCP)) {
62: fprintf(stderr, "unable to register (BILLBOARD_PROG, BILLBOARD_VERS, tcp).");
63: exit(1);
64: }
65:
66: /*
67: ** Initialize the server. Read all of the data structures and
68: ** create the files that do not exist.
69: */
70: if ( bb_server_init() != BB_SUCCESS )
71: {
72: fprintf( stderr, "ABORTING: Unable to init server database.\n");
73: return BB_FAILURE;
74: }
75:
76: svc_run();
77: fprintf(stderr, "svc_run returned");
78: exit(1);
79: /* NOTREACHED */
80: }
81:
82:
83:
84: /*************************************************************************
85: ** **
86: ** bb_server_init() - Initialize the servers database structures. **
87: ** Setup or create the files if they do not exist. Most errors with **
88: ** the files will cause an abort. **
89: ** **
90: *************************************************************************/
91: int
92: bb_server_init()
93: {
94:
95: if ( bb_read_companies() != BB_SUCCESS )
96: {
97: fprintf( stderr, "Unable to read company data file.\n");
98: return BB_FAILURE;
99: }
100:
101: if ( bb_read_passwords() != BB_SUCCESS )
102: {
103: fprintf( stderr, "Unable to read password file.\n");
104: return BB_FAILURE;
105: }
106:
107: if ( bb_read_phases() != BB_SUCCESS )
108: {
109: fprintf( stderr, "Unable to read phases file.\n");
110: return BB_FAILURE;
111: }
112:
113: if ( bb_read_board() != BB_SUCCESS )
114: {
115: fprintf( stderr, "Unable to read board file.\n");
116: return BB_FAILURE;
117: }
118:
119: return BB_SUCCESS;
120: }
121:
122:
123: /*************************************************************************
124: ** **
125: ** bb_get_ip() - From the transport structure of the caller copy the **
126: ** IP address into an IP structure. **
127: ** **
128: *************************************************************************/
129: static SVCXPRT *bb_xprt; /* The xport struct of the request. */
130:
131: void
132: bb_get_ip( ip)
133: BB_ip ip; /* Pointer to an ip for output. */
134: {
135: char line[20]; /* Just some space for an ip number. */
136:
137: (void)memset( (char *)ip, (int)0, (int)BB_IP_ADDR_LEN);
138: sprintf( line, "%u.", bb_xprt->xp_raddr.sin_addr.S_un.S_un_b.s_b1);
139: strncpy( ip, line, 4);
140: sprintf( line, "%u.", bb_xprt->xp_raddr.sin_addr.S_un.S_un_b.s_b2);
141: strncat( ip, line, 4);
142: sprintf( line, "%u.", bb_xprt->xp_raddr.sin_addr.S_un.S_un_b.s_b3);
143: strncat( ip, line, 4);
144: sprintf( line, "%u", bb_xprt->xp_raddr.sin_addr.S_un.S_un_b.s_b4);
145: strncat( ip, line, 3);
146: }
147:
148:
149: static void
150: billboard_prog_1(rqstp, transp)
151: struct svc_req *rqstp;
152: register SVCXPRT *transp;
153: {
154: union {
155: BB_set_in bb_set_1_arg;
156: BB_set_in bb_unset_1_arg;
157: BB_list_in bb_alist_1_arg;
158: BB_list_in bb_blist_1_arg;
159: BB_list_in bb_clist_1_arg;
160: BB_list_in bb_dlist_1_arg;
161: BB_passwd_in bb_passwd_set_1_arg;
162: } argument;
163: char *result;
164: bool_t (*xdr_argument)(), (*xdr_result)();
165: char *(*local)();
166:
167: /*
168: ** This was added after rpcgen.
169: */
170: bb_xprt = transp;
171:
172:
173: switch (rqstp->rq_proc) {
174: case NULLPROC:
175: (void) svc_sendreply(transp, xdr_void, (char *)NULL);
176: return;
177:
178: case BB_SET:
179: xdr_argument = xdr_BB_set_in;
180: xdr_result = xdr_BB_set_out;
181: local = (char *(*)()) bb_set_1;
182: break;
183:
184: case BB_UNSET:
185: xdr_argument = xdr_BB_set_in;
186: xdr_result = xdr_BB_set_out;
187: local = (char *(*)()) bb_unset_1;
188: break;
189:
190: case BB_ALIST:
191: xdr_argument = xdr_BB_list_in;
192: xdr_result = xdr_BB_list_out;
193: local = (char *(*)()) bb_alist_1;
194: break;
195:
196: case BB_BLIST:
197: xdr_argument = xdr_BB_list_in;
198: xdr_result = xdr_BB_list_out;
199: local = (char *(*)()) bb_blist_1;
200: break;
201:
202: case BB_CLIST:
203: xdr_argument = xdr_BB_list_in;
204: xdr_result = xdr_BB_list_out;
205: local = (char *(*)()) bb_clist_1;
206: break;
207:
208: case BB_DLIST:
209: xdr_argument = xdr_BB_list_in;
210: xdr_result = xdr_BB_list_out;
211: local = (char *(*)()) bb_dlist_1;
212: break;
213:
214: case BB_PASSWD_SET:
215: xdr_argument = xdr_BB_passwd_in;
216: xdr_result = xdr_int;
217: local = (char *(*)()) bb_passwd_set_1;
218: break;
219:
220: case BB_GRID:
221: xdr_argument = xdr_void;
222: xdr_result = xdr_BB_grid;
223: local = (char *(*)()) bb_grid_1;
224: break;
225:
226: default:
227: svcerr_noproc(transp);
228: return;
229: }
230: bzero((char *)&argument, sizeof(argument));
231: if (!svc_getargs(transp, xdr_argument, &argument)) {
232: svcerr_decode(transp);
233: return;
234: }
235: result = (*local)(&argument, rqstp);
236: if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
237: svcerr_systemerr(transp);
238: }
239: if (!svc_freeargs(transp, xdr_argument, &argument)) {
240: fprintf(stderr, "unable to free arguments");
241: exit(1);
242: }
243: return;
244: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.