afsconfig-and-rcsid-all-around-20010705
[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 <afs/param.h>
11 #include <afsconfig.h>
12
13 RCSID("$Header$");
14
15 #include <sys/types.h>
16 #include <netdb.h>
17 #include <stdio.h>
18 #include "sample.h"
19
20 #define N_SECURITY_OBJECTS 1
21
22 extern TEST_ExecuteRequest();
23
24 main() {
25     struct rx_securityClass *(securityObjects[N_SECURITY_OBJECTS]);
26     struct rx_service *service;
27
28     /* Initialize Rx, telling it port number this server will use for its single service */
29     if (rx_Init(SAMPLE_SERVER_PORT) < 0) Quit("rx_init");
30
31     /* 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 */
32     securityObjects[SAMPLE_NULL] = rxnull_NewServerSecurityObject();
33     if (securityObjects[SAMPLE_NULL] == (struct rx_securityClass *) 0) Quit("rxnull_NewServerSecurityObject");
34
35     /* Instantiate a single sample service.  The rxgen-generated procedure which is called to decode requests is passed in here (TEST_ExecuteRequest). */
36     service = rx_NewService(0, SAMPLE_SERVICE_ID, "sample", securityObjects, N_SECURITY_OBJECTS, TEST_ExecuteRequest);
37     if (service == (struct rx_service *) 0) Quit("rx_NewService");
38
39     rx_StartServer(1); /* Donate this process to the server process pool */
40     Quit("StartServer returned?");
41 }
42
43 int TEST_Add(call, a, b, result)
44 struct rx_call *call;
45 int a,b;
46 int *result;
47 {
48     printf("TEST_Add(%d,%d)\n", a,b);
49     *result = a + b;
50     return 0;
51 }
52
53 int TEST_Sub(call, a, b, result)
54 struct rx_call *call;
55 int a,b;
56 int *result;
57 {
58     printf("TEST_Sub(%d,%d)\n", a,b);
59     *result = a - b;
60     return 0;
61 }
62
63 Quit(msg, a, b)
64     char *msg;
65 {
66     fprintf(stderr, msg, a, b);
67     exit(1);
68 }
69