home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Internet Business Development Kit / PRODUCT_CD.iso / sqlsvr / ptk / mips / gateway.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-12  |  3.9 KB  |  145 lines

  1. // This program is an example of an Open Data Services application. It accepts
  2. // requests from clients and then passes those requests on to an SQL server.
  3. // The results from the SQL server are then sent back to the client.
  4.  
  5. #include    <stdlib.h>
  6. #include    <stdio.h>
  7. #include    <string.h>
  8. #include    <windows.h>
  9. #include    <sqlfront.h>
  10. #include    <sqldb.h>
  11. #include    <srv.h>
  12.  
  13. // Globals
  14. //
  15. DBCHAR *SrvrName = "";  // Default remote server name
  16. DBCHAR *RegistryName = "Gateway";   // Default registry name
  17.  
  18. // function prototypes
  19. //
  20. void getargs(int argc, char **argv);
  21.  
  22. void main(int argc, char **argv);
  23.  
  24. int SRVAPI init_server(SRV_SERVER *server);
  25.  
  26. void SRVAPI set_remote_server_name(char *name);
  27.  
  28. int chk_err(SRV_SERVER *server, SRV_PROC *srvproc, int srverror,
  29.             BYTE severity, BYTE state, int oserrnum, DBCHAR *errtext,
  30.             int errtextlen, DBCHAR *oserrtext, int oserrtextlen);
  31.  
  32. void main(argc, argv)
  33. int argc;
  34. char *argv[];
  35. {
  36.     SRV_CONFIG *config; // The configuration structure
  37.     SRV_SERVER *server; // The service process
  38.     int exitcode;
  39.  
  40.     // Read any command line arguments.
  41.     //
  42.     getargs(argc, argv);
  43.  
  44.     // Send the name retrieved to the gateway's DLL module
  45.     //
  46.     set_remote_server_name(SrvrName);
  47.  
  48.     // Allocate a configuration structure that is used to initialize
  49.     // the Open Data Services application
  50.     //
  51.     config = srv_config_alloc();
  52.  
  53.     // Allow 20 connections at a time.
  54.     //
  55.     srv_config(config, (DBINT)SRV_CONNECTIONS, "100", SRV_NULLTERM);
  56.  
  57.     // Set the log file.
  58.     //
  59.     srv_config(config, (DBINT)SRV_LOGFILE, "gateway.log", SRV_NULLTERM);
  60.  
  61.     // The gateway will not convert data source strings in order to allow
  62.     // SQL Server and DB-libraray to coordinate on the codepage as usual.
  63.     //
  64.     srv_config(config, (DBINT)SRV_ANSI_CODEPAGE, "TRUE", SRV_NULLTERM);
  65.  
  66.     // Install the Open Data Services error handler.
  67.     //
  68.     srv_errhandle(chk_err);
  69.  
  70.     // Initialize the gateway and save the server handle
  71.     // so it can be used in later functions.
  72.     //
  73.     server = srv_init(config, RegistryName, SRV_NULLTERM);
  74.     if (server == NULL) {
  75.         printf("Unable to initialize Gateway.\n");
  76.         ExitProcess(exitcode);
  77.     }
  78.  
  79.     // When starting the gateway, initialize the remote server structure.
  80.     // This is done in the init_server() function.
  81.     // All the other event handlers are also defined in the init_server()
  82.     // function.
  83.     //
  84.     srv_handle(server, (DBINT)SRV_START, init_server);
  85.  
  86.     // Now everything's ready to go with our gateway, so we
  87.     // start it and keep it going until we get a stop request.
  88.     //
  89.     srv_log(server, FALSE, " ", SRV_NULLTERM);  // insert blank line
  90.     srv_log(server, TRUE, "Gateway Starting", SRV_NULLTERM);
  91.  
  92.     printf("\nGateway Starting\n");
  93.  
  94.     srv_run(server);
  95.  
  96. }
  97.  
  98. // GETARGS
  99. //    Read the command line arguments.
  100. //
  101. // Parameters:
  102. //     argc - int (from "main" entry)
  103. //     argv - pointer to array of char pointers (from "main" entry)
  104. //
  105. // Returns:
  106. //     VOID
  107. //
  108. void getargs(int argc, char *argv[])
  109. {
  110.  
  111.     int i;
  112.     char *ptr;
  113.     int exitcode;
  114.  
  115.     for (i = 1; i < argc; ++i) {
  116.         if (argv[i][0] != '-' && argv[i][0] != '/') {
  117.             printf(
  118.             "Usage: gateway -S<remote server name> [-R<registry key name>]\n");
  119.                 
  120.             ExitProcess(exitcode);
  121.         }
  122.         ptr = argv[i];
  123.         switch (ptr[1]) {
  124.  
  125.         case 'S':
  126.             if (strlen(ptr + 2) > 0) {
  127.                 SrvrName = ptr + 2;
  128.             }
  129.             break;
  130.  
  131.         case 'R':
  132.             if (strlen(ptr + 2) > 0) {
  133.                 RegistryName = ptr + 2;
  134.             }
  135.             break;
  136.  
  137.         default:
  138.             printf(
  139.             "Usage: gateway -S<remote server name> [-R<registry key name>]\n");
  140.                 
  141.             ExitProcess(exitcode);
  142.         }
  143.     }
  144. }
  145.