Standardize License information
[openafs.git] / src / rx / simple.example / sample_server.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <sys/types.h>
11 #include <netdb.h>
12 #include <stdio.h>
13 #include "sample.h"
14
15 #define N_SECURITY_OBJECTS 1
16
17 extern TEST_ExecuteRequest();
18
19 main() {
20     struct rx_securityClass *(securityObjects[N_SECURITY_OBJECTS]);
21     struct rx_service *service;
22
23     /* Initialize Rx, telling it port number this server will use for its single service */
24     if (rx_Init(SAMPLE_SERVER_PORT) < 0) Quit("rx_init");
25
26     /* Create a single security object, in this case the null security object, for unauthenticated connections, which will be used to control security on connections made to this server */
27     securityObjects[SAMPLE_NULL] = rxnull_NewServerSecurityObject();
28     if (securityObjects[SAMPLE_NULL] == (struct rx_securityClass *) 0) Quit("rxnull_NewServerSecurityObject");
29
30     /* Instantiate a single sample service.  The rxgen-generated procedure which is called to decode requests is passed in here (TEST_ExecuteRequest). */
31     service = rx_NewService(0, SAMPLE_SERVICE_ID, "sample", securityObjects, N_SECURITY_OBJECTS, TEST_ExecuteRequest);
32     if (service == (struct rx_service *) 0) Quit("rx_NewService");
33
34     rx_StartServer(1); /* Donate this process to the server process pool */
35     Quit("StartServer returned?");
36 }
37
38 int TEST_Add(call, a, b, result)
39 struct rx_call *call;
40 int a,b;
41 int *result;
42 {
43     printf("TEST_Add(%d,%d)\n", a,b);
44     *result = a + b;
45     return 0;
46 }
47
48 int TEST_Sub(call, a, b, result)
49 struct rx_call *call;
50 int a,b;
51 int *result;
52 {
53     printf("TEST_Sub(%d,%d)\n", a,b);
54     *result = a - b;
55     return 0;
56 }
57
58 Quit(msg, a, b)
59     char *msg;
60 {
61     fprintf(stderr, msg, a, b);
62     exit(1);
63 }
64