home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / interb / InterBase_WI-V6.0-server.exe / server / examples / services / gstat.c < prev    next >
C/C++ Source or Header  |  2000-06-23  |  3KB  |  124 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4. #include "/home/stsikin/dev_test/super/jrd/ibase.h"
  5.  
  6. #define RESPBUF    1024
  7. #define RETURN_ERROR    {isc_service_detach(status, &svc_handle); exit (1);}
  8.  
  9. int main (argc, argv)
  10. int    argc;
  11. char    *argv[];
  12. {
  13. char    *user = "SYSDBA",
  14.         *pass = "masterkey";
  15. long    status [20];
  16. long    *svc_handle = NULL;
  17. char    svc_name[RESPBUF], spb_buff[RESPBUF], thd_buff[RESPBUF];
  18. char    sendbuf[] = {isc_info_svc_line};
  19. char    respbuf[RESPBUF], *p = respbuf, *spb = spb_buff, *thd = thd_buff,*x;
  20. short    spblen, thdlen;
  21. int    i = 0, options = 0;
  22.  
  23.  
  24. if (argc != 2)
  25.     {
  26.     printf ("Usage: %s dbfile\n", argv[0]);
  27.     return (1);
  28.     }
  29.  
  30. *spb++ = isc_spb_version;
  31. *spb++ = isc_spb_current_version;
  32.  
  33. *spb++ = isc_spb_user_name;
  34. *spb++ = strlen (user);
  35. for (x = user; *x;)
  36.   *spb++ = *x++;
  37.  
  38. *spb++ = isc_spb_password;
  39. *spb++ = strlen (pass);
  40. for (x = pass; *x;)
  41.   *spb++ = *x++;
  42.  
  43. sprintf (svc_name, "typhoon:service_mgr");
  44.  
  45. spblen = spb - spb_buff;
  46.  
  47. if (isc_service_attach (status, 0, svc_name, &svc_handle, spblen, spb_buff))
  48.     {
  49.     isc_print_status (status);
  50.     return (1);
  51.     }
  52.  
  53. *thd++ = isc_action_svc_db_stats;
  54. *thd++ = isc_spb_dbname;
  55. *thd++ = strlen (argv[1]);
  56. *thd++ = strlen (argv[1]) >> 8;
  57. for (x = argv[1]; *x;)
  58.   *thd++ = *x++;
  59. *thd++ = isc_spb_options;
  60.  
  61.  
  62. /*******************************************************************
  63. options |= (options | isc_spb_sts_data_pages | isc_spb_sts_db_log |
  64.             isc_spb_sts_hdr_pages | isc_spb_sts_idx_pages |
  65.             isc_spb_sts_sys_relations );
  66. *********************************************************************/
  67. options = isc_spb_sts_idx_pages | isc_spb_sts_sys_relations;
  68. *thd++ = options;
  69. *thd++ = options >> 8;
  70. *thd++ = options >> 16;
  71. *thd++ = options >> 24;
  72.  
  73. thdlen = thd - thd_buff;
  74.  
  75. printf ("Attach succeed\n");
  76.  
  77. if (isc_service_start(status, &svc_handle, NULL, thdlen, thd_buff))
  78.     {
  79.     isc_print_status (status);
  80.     isc_service_detach (status, &svc_handle);
  81.     return(1);
  82.     }
  83. printf ("Start succeed\n");
  84.  
  85. do
  86.     {
  87.     if (isc_service_query (status, &svc_handle, NULL, 0, NULL,
  88.         sizeof (sendbuf), sendbuf, RESPBUF, respbuf))
  89.         {
  90.         isc_print_status (status);
  91.         isc_service_detach (status, &svc_handle);
  92.         return(1);
  93.         }
  94.  
  95.     x = p = respbuf;
  96.  
  97.     if (*p++ == isc_info_svc_line) 
  98.         {
  99.         ISC_USHORT len = 0, chTmp = 0;
  100.         ISC_ULONG  tra_id = 0;
  101.  
  102.         len = (ISC_USHORT)isc_vax_integer(p, sizeof(ISC_USHORT));
  103.         if (len == 0)
  104.             break;
  105.         p += sizeof (ISC_USHORT);
  106.         for (chTmp = 0; chTmp < len; chTmp++)
  107.             printf ("%c", p[chTmp]);
  108.         p += len;
  109.         }
  110.         
  111.     if (*p == isc_info_truncated)
  112.         continue;
  113.     /****************************
  114.     if (*p == isc_info_end)
  115.         break;
  116.         **************************/
  117.  
  118.     }
  119. while (*x == isc_info_svc_line);
  120.  
  121. isc_service_detach(status, &svc_handle);
  122. return (0);
  123. }
  124.