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

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4. #include "ibase.h"
  5.  
  6. #define RESPBUF    1024
  7.  
  8. void main (argc, argv)
  9. int    argc;
  10. char    *argv[];
  11. {
  12. char    *user = "SYSDBA",
  13.         *pass = "masterkey";
  14. long    status [20];
  15. long    *svc_handle = NULL;
  16. char    *buffer;
  17. char    send_buff[32], *pSendBuff;
  18. char    svc_name[RESPBUF], spb_buff[RESPBUF], thd_buff[RESPBUF];
  19. char    sendbuf[] = {isc_info_svc_line};
  20. char    respbuf[RESPBUF], *p = respbuf, *spb = spb_buff, *thd = thd_buff,*x;
  21. short    spblen, thdlen;
  22. int    options =0, i = 0;
  23.  
  24.  
  25. if (argc < 4)
  26.     {
  27.     printf ("Usage: %s gbkfile1 gbkfile2 ... gbkfileN gdbfile\n", argv[0]);
  28.     exit (1);
  29.     }
  30.  
  31. argc--;
  32. *spb++ = isc_spb_version;
  33. *spb++ = isc_spb_current_version;
  34.  
  35. *spb++ = isc_spb_user_name;
  36. *spb++ = strlen (user);
  37. for (x = user; *x;)
  38.   *spb++ = *x++;
  39.  
  40. *spb++ = isc_spb_password;
  41. *spb++ = strlen (pass);
  42. for (x = pass; *x;)
  43.   *spb++ = *x++;
  44.  
  45. sprintf (svc_name, "typhoon:service_mgr");
  46.  
  47. spblen = spb - spb_buff;
  48.  
  49. if (isc_service_attach (status, 0, svc_name, &svc_handle, spblen, spb_buff))
  50.     {
  51.     isc_print_status (status);
  52.     exit (1);
  53.     }
  54.  
  55. *thd++ = isc_action_svc_restore;
  56. for (i = 1; argc > 1; --argc, i++)
  57.     {
  58.     *thd++ = isc_spb_bkp_file;
  59.     *thd++ = strlen (argv[i]);
  60.     *thd++ = strlen (argv[i]) >> 8;
  61.     for (x = argv[i]; *x;)
  62.     *thd++ = *x++;
  63.     }
  64.  
  65. *thd++ = isc_spb_dbname;
  66. *thd++ = strlen (argv[i]);
  67. *thd++ = strlen (argv[i]) >> 8;
  68. for (x = argv[i]; *x;)
  69.   *thd++ = *x++;
  70.  
  71.  
  72. *thd++ = isc_spb_verbose;
  73. *thd++ = isc_spb_options;
  74. options = isc_spb_res_create;
  75. *thd++ = options;
  76. *thd++ = options >> 8;
  77. *thd++ = options >> 16;
  78. *thd++ = options >> 24;
  79.  
  80. thdlen = thd - thd_buff;
  81.  
  82. printf ("Attach succeed\n");
  83.  
  84. if (isc_service_start(status, &svc_handle, NULL, thdlen, thd_buff))
  85.     {
  86.     isc_print_status (status);
  87.     isc_service_detach (status, &svc_handle);
  88.     exit(1);
  89.     }
  90. printf ("Start succeed\n");
  91.  
  92. do
  93.     {
  94.     if (isc_service_query (status, &svc_handle, NULL, 0, NULL,
  95.     sizeof (sendbuf), sendbuf, RESPBUF, respbuf))
  96.     {
  97.     isc_print_status (status);
  98.     isc_service_detach (status, &svc_handle);
  99.     exit(1);
  100.     }
  101.  
  102.     x = p = respbuf;
  103.  
  104.     if (*p++ == isc_info_svc_line)
  105.     {
  106.     ISC_USHORT len = 0, chTmp = 0, key;
  107.  
  108.     len = (ISC_USHORT)isc_vax_integer(p, sizeof(ISC_USHORT));
  109.     p += sizeof (ISC_USHORT);
  110.     if (!len)
  111.         if (*p == isc_info_data_not_ready)
  112.         {
  113.         printf ("no data available at this moment\n");
  114.         continue;
  115.         }
  116.         else
  117.         {
  118.         if (*p != isc_info_end)
  119.             printf ("Format error ... <%d>\n", *p);
  120.         break;
  121.         }
  122.     for (chTmp = 0; chTmp < len; chTmp++)
  123.         printf("%c",p[chTmp]);
  124.     p += len;
  125.     if (*p != isc_info_truncated && *p != isc_info_end)
  126.         {
  127.         printf ("Format error ... encountered <%d>\n", *p);
  128.         break;
  129.         }
  130.     else
  131.         {
  132.         /* printf ("\nisc_info_truncated  || isc_info_end\n"); */
  133.         }
  134.     }
  135.     else
  136.     printf ("not a isc_info_svc_line, but %d\n", *x);
  137.     }
  138. while (*x == isc_info_svc_line);
  139.  
  140.  
  141. isc_service_detach(status, &svc_handle);
  142. }
  143.