home *** CD-ROM | disk | FTP | other *** search
/ Freelog 42 / Freelog042.iso / Alu / Ancestrologie / Sources / InterBase_WI-V6.0.1-server.ZIP / examples / services / isc_info_svc_all.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-05  |  12.6 KB  |  344 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4. #include "ibase.h"
  5. #include "common.h"
  6. #include "license.h"
  7. #include "svc_undoc.h"
  8.  
  9. #define MULTI_CLIENT_SUPPORT     0x2L    /* SuperServer model (vs. multi-inet) */
  10. #define SVC_RESPBUF    512
  11. #define SERVICES isc_info_svc_server_version,\
  12.     isc_info_svc_implementation,\
  13.     isc_info_svc_get_licensed_users,\
  14.     isc_info_svc_user_dbpath,\
  15.     isc_info_svc_get_env,\
  16.     isc_info_svc_get_env_lock,\
  17.     isc_info_svc_get_env_msg,\
  18.     isc_info_svc_get_license,\
  19.     isc_info_svc_svr_db_info,\
  20.     isc_info_svc_get_license_mask,\
  21.     isc_info_svc_version,\
  22.     isc_info_svc_capabilities,\
  23.     isc_info_svc_get_config
  24.  
  25. void main ()
  26. {
  27. char    *user = "SYSDBA", *pass = "masterkey";
  28. long    status [20], *svc_handle = NULL;
  29. char    respbuf[SVC_RESPBUF], svc_name[SVC_RESPBUF], spb_buff[SVC_RESPBUF], sendbuf[] = { SERVICES };
  30. char    *buffer, *p = respbuf, *spb = spb_buff, *x;
  31. short    spblen;
  32. ISC_ULONG path_length;
  33.  
  34. *spb++ = isc_spb_version;
  35. *spb++ = isc_spb_current_version;
  36.  
  37. *spb++ = isc_spb_user_name;
  38. *spb++ = strlen (user);
  39. for (x = user; *x;)
  40.   *spb++ = *x++;
  41.  
  42. *spb++ = isc_spb_password;
  43. *spb++ = strlen (pass);
  44. for (x = pass; *x;)
  45.   *spb++ = *x++;
  46.  
  47. sprintf (svc_name, "corkie:service_mgr");
  48.  
  49. spblen = spb - spb_buff;
  50.  
  51. if (isc_service_attach (status, 0, svc_name, &svc_handle, spblen, spb_buff))
  52.   {
  53.   isc_print_status (status);
  54.   return;
  55.   }
  56.  
  57. if (isc_service_query (status, &svc_handle, NULL, 0, NULL, sizeof (sendbuf), sendbuf, SVC_RESPBUF, respbuf))
  58.   {
  59.   isc_print_status (status);
  60.   isc_service_detach (status, &svc_handle);
  61.   return;
  62.   }
  63.  
  64. do {
  65.     switch (*p++)
  66.         {
  67.  
  68.         case isc_info_truncated:
  69.             printf ("Buffer Truncated\n");
  70.             break;
  71.  
  72.         case isc_info_svc_get_licensed_users:
  73.             {
  74.             ISC_ULONG nUsers;
  75.             p+= sizeof (ISC_USHORT);
  76.             nUsers = (ISC_ULONG)isc_vax_integer(p, sizeof (ISC_ULONG));
  77.             printf ("Number of licensed users: %d\n", nUsers);
  78.             p += sizeof(ISC_ULONG);
  79.             break;
  80.             }
  81.  
  82.         case isc_info_svc_server_version:
  83.             {
  84.             path_length = (ISC_USHORT) isc_vax_integer (p, sizeof(ISC_USHORT));
  85.             p += sizeof (ISC_USHORT);
  86.             buffer = (char*) malloc (path_length);
  87.             strncpy (buffer, p, path_length);
  88.             buffer [path_length] = '\0';
  89.             printf ("Server version: %s\n", buffer);
  90.             p += path_length;
  91.             break;
  92.             }
  93.             
  94.         case isc_info_svc_implementation:
  95.             {
  96.             path_length = (ISC_USHORT) isc_vax_integer (p, sizeof(ISC_USHORT));
  97.             p += sizeof (ISC_USHORT);
  98.             buffer = (char*) malloc (path_length);
  99.             strncpy (buffer, p, path_length);
  100.             buffer [path_length] = '\0';
  101.             printf ("Server implementation: %s\n", buffer);
  102.             p += path_length;
  103.             break;
  104.             }
  105.  
  106.         case isc_info_svc_svr_db_info:
  107.             {
  108.             printf ("Database information:\n");
  109.             do {
  110.                 switch (*p++)
  111.                     {
  112.                     case isc_spb_dbname:
  113.                         {
  114.                         /* Database names in use */
  115.                         path_length = (ISC_USHORT) isc_vax_integer (p, sizeof(ISC_USHORT));
  116.                         p += sizeof (ISC_USHORT);
  117.                         buffer = (char*) malloc (path_length);
  118.                         strncpy (buffer, p, path_length);
  119.                         buffer [path_length] = '\0';
  120.                         printf ("Database in use: %s\n", buffer);
  121.                         p += path_length;
  122.                         break;
  123.                         }
  124.                     case isc_spb_num_att:
  125.                         {
  126.                         /* Num Attachments */
  127.                         ISC_ULONG nAttachments;
  128.                         p+= sizeof (ISC_USHORT);
  129.                         nAttachments = (ISC_ULONG)isc_vax_integer(p, sizeof (ISC_ULONG));
  130.                         printf ("\tNumber of attachments: %d\n", nAttachments);
  131.                         p += sizeof(ISC_ULONG);
  132.                         break;
  133.                         }
  134.                     case isc_spb_num_db:
  135.                         {
  136.                         /* Num databases */
  137.                         ISC_ULONG nDatabases;
  138.                         p+= sizeof (ISC_USHORT);
  139.                         nDatabases = (ISC_ULONG)isc_vax_integer(p, sizeof(ISC_ULONG));
  140.                         printf ("\tNumber of databases: %d\n", nDatabases);
  141.                         p += sizeof(ISC_ULONG);
  142.                         break;
  143.                         }              
  144.                     }
  145.                 } while (*p != isc_info_flag_end);
  146.             break;
  147.             }
  148.  
  149.         case isc_info_svc_get_license:
  150.             {
  151.             printf ("License information:\n");
  152.             do {
  153.                 switch (*p++)
  154.                     {
  155.                     case isc_spb_lic_key:
  156.                         {
  157.                         path_length = (ISC_USHORT) isc_vax_integer (p, sizeof(ISC_USHORT));
  158.                         p += sizeof (ISC_USHORT);
  159.                         buffer = (char*) malloc (path_length);
  160.                         strncpy (buffer, p, path_length);
  161.                         buffer [path_length] = '\0';
  162.                         printf ("\tLicense Key: %s\n", buffer);
  163.                         p += path_length;
  164.                         break;
  165.                         }
  166.                     case isc_spb_lic_id:
  167.                         {
  168.                         path_length = (ISC_USHORT) isc_vax_integer (p, sizeof(ISC_USHORT));
  169.                         p += sizeof (ISC_USHORT);
  170.                         buffer = (char*) malloc (path_length);
  171.                         strncpy (buffer, p, path_length);
  172.                         buffer [path_length] = '\0';
  173.                         printf ("\tLicense ID: %s\n", buffer);
  174.                         p += path_length;
  175.                         break;
  176.                         }              
  177.                     }
  178.                 } while (*p != isc_info_flag_end);
  179.             break;
  180.             }
  181.  
  182.         case isc_info_svc_get_license_mask:
  183.             {
  184.             ISC_ULONG mask;
  185.             printf ("License Information:\n");
  186.             p += sizeof (ISC_USHORT);
  187.             mask = (ISC_ULONG) isc_vax_integer (p, sizeof(ISC_ULONG));
  188.             if (mask & LIC_S)
  189.                 printf ("\tRemote Server Enabled\n");
  190.             p += sizeof (ISC_ULONG);
  191.             break;
  192.             }
  193.  
  194.         case isc_info_svc_get_config:
  195.             {
  196.             ISC_USHORT chTmp = 0, key;
  197.             ISC_ULONG len = 0, ulConfigInfo;
  198.             
  199.             printf ("Configuration Settings:\n");
  200.             len = (ISC_USHORT)isc_vax_integer(p, sizeof(ISC_USHORT));
  201.             p += sizeof(ISC_USHORT);
  202.             for (chTmp = 0; chTmp < len; chTmp++)
  203.                 {
  204.                 key = p[chTmp];
  205.                 ulConfigInfo = (ISC_ULONG)isc_vax_integer(p+ chTmp + 2, p[chTmp+1]);
  206.                 switch (key)
  207.                     {
  208.                     case ISCCFG_LOCKMEM_KEY:
  209.                         printf ("\tLock mem: %d\n", ulConfigInfo);
  210.                         break;
  211.                     case ISCCFG_LOCKSEM_KEY:
  212.                         printf ("\tLock Semaphores: %d\n", ulConfigInfo);
  213.                         break;
  214.                     case ISCCFG_LOCKSIG_KEY:
  215.                         printf ("\tLock sig: %d\n", ulConfigInfo);
  216.                         break;
  217.                     case ISCCFG_EVNTMEM_KEY:
  218.                         printf ("\tEvent mem: %d\n", ulConfigInfo);
  219.                         break;
  220.                     case ISCCFG_PRIORITY_KEY:
  221.                         printf ("\tPriority: %d\n", ulConfigInfo);
  222.                         break;
  223.                     case ISCCFG_MEMMIN_KEY:
  224.                         printf ("\tMin memory: %d\n", ulConfigInfo);
  225.                         break;
  226.                     case ISCCFG_MEMMAX_KEY:
  227.                         printf ("\tMax Memory: %d\n", ulConfigInfo);
  228.                         break;
  229.                     case ISCCFG_LOCKORDER_KEY:
  230.                         printf ("\tLock order: %d\n", ulConfigInfo);
  231.                         break;
  232.                     case ISCCFG_ANYLOCKMEM_KEY:
  233.                         printf ("\tAny lock mem: %d\n", ulConfigInfo);
  234.                         break;
  235.                     case ISCCFG_ANYLOCKSEM_KEY:
  236.                         printf ("\tAny lock semaphore: %d\n", ulConfigInfo);
  237.                         break;
  238.                     case ISCCFG_ANYLOCKSIG_KEY:
  239.                         printf ("\tany lock sig: %d\n", ulConfigInfo);
  240.                         break;
  241.                     case ISCCFG_ANYEVNTMEM_KEY:
  242.                         printf ("\tany event mem: %d\n", ulConfigInfo);
  243.                         break;
  244.                     case ISCCFG_LOCKHASH_KEY:
  245.                         printf ("\tLock hash: %d\n", ulConfigInfo);
  246.                         break;
  247.                     case ISCCFG_DEADLOCK_KEY:
  248.                         printf ("\tDeadlock: %d\n", ulConfigInfo);
  249.                         break;
  250.                     case ISCCFG_LOCKSPIN_KEY:
  251.                         printf ("\tLock spin: %d\n", ulConfigInfo);
  252.                         break;
  253.                     case ISCCFG_CONN_TIMEOUT_KEY:
  254.                         printf ("\tConn timeout: %d\n", ulConfigInfo);
  255.                         break;
  256.                     case ISCCFG_DUMMY_INTRVL_KEY:
  257.                         printf ("\tDummy interval: %d\n", ulConfigInfo);
  258.                         break;
  259.                     case ISCCFG_IPCMAP_KEY:
  260.                         printf ("\tMap size: %d\n", ulConfigInfo);
  261.                         break;
  262.                     case ISCCFG_DBCACHE_KEY:
  263.                         printf ("\tCache size: %d\n", ulConfigInfo);
  264.                         break;
  265.                     }
  266.                 chTmp += p[chTmp+1] + 1;
  267.                 }
  268.             }
  269.             break;
  270.  
  271.         case isc_info_svc_version:
  272.             {
  273.             ISC_ULONG svcversion;
  274.             p += sizeof (ISC_USHORT);
  275.             svcversion = (ISC_ULONG) isc_vax_integer (p, sizeof(ISC_ULONG));
  276.             printf ("Service Manager Version: %d\n", svcversion);
  277.             p += sizeof (ISC_ULONG);
  278.             break;
  279.             }
  280.  
  281.         case isc_info_svc_capabilities:
  282.             {
  283.             ISC_ULONG capabilities;
  284.             printf ("Server Capabilities:\n");
  285.             p += sizeof (ISC_USHORT);
  286.             capabilities = (ISC_ULONG) isc_vax_integer (p, sizeof(ISC_ULONG));
  287.             if (capabilities & MULTI_CLIENT_SUPPORT)
  288.                 printf ("\tSupports multiple clients\n");
  289.             p += sizeof (ISC_ULONG);
  290.             break;
  291.             }
  292.  
  293.         case isc_info_svc_user_dbpath:
  294.             {
  295.             path_length = (ISC_USHORT) isc_vax_integer (p, sizeof(ISC_USHORT));
  296.             p += sizeof (ISC_USHORT);
  297.             buffer = (char*) malloc (path_length);
  298.             strncpy (buffer, p, path_length);
  299.             buffer [path_length] = '\0';
  300.             printf ("Path to ISC4.GDB: %s\n", buffer);
  301.             p += path_length;
  302.             break;
  303.             }
  304.  
  305.         case isc_info_svc_get_env:
  306.             {
  307.             path_length = (ISC_USHORT) isc_vax_integer (p, sizeof(ISC_USHORT));
  308.             p += sizeof (ISC_USHORT);
  309.             buffer = (char*) malloc (path_length);
  310.             strncpy (buffer, p, path_length);
  311.             buffer [path_length] = '\0';
  312.             printf ("Value of $INTERBASE: %s\n", buffer);
  313.             p += path_length;
  314.             break;
  315.             }
  316.  
  317.         case isc_info_svc_get_env_lock:
  318.             {
  319.             path_length = (ISC_USHORT) isc_vax_integer (p, sizeof(ISC_USHORT));
  320.             p += sizeof (ISC_USHORT);
  321.             buffer = (char*) malloc (path_length);
  322.             strncpy (buffer, p, path_length);
  323.             buffer [path_length] = '\0';
  324.             printf ("Path to <hostname>.lck: %s\n", buffer);
  325.             p += path_length;
  326.             break;
  327.             }
  328.  
  329.         case isc_info_svc_get_env_msg:
  330.             {
  331.             path_length = (ISC_USHORT) isc_vax_integer (p, sizeof(ISC_USHORT));
  332.             p += sizeof (ISC_USHORT);
  333.             buffer = (char*) malloc (path_length);
  334.             strncpy (buffer, p, path_length);
  335.             buffer [path_length] = '\0';
  336.             printf ("Path to INTERBASE.MSG: %s\n", buffer);
  337.             p += path_length;
  338.             break;
  339.             }
  340.         }
  341.     } while (*p);
  342. isc_service_detach (status, &svc_handle);                          
  343. }
  344.