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.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-05  |  2.8 KB  |  136 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4. #include "/usr/interbase/../super/jrd/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    path_length, spblen, thdlen, sendBuffLen;
  22. int    i = 0;
  23. ISC_USHORT    n;
  24.  
  25.  
  26. if (argc != 3)
  27.     {
  28.     printf ("Usage: %s backupfile dbfile\n", argv[0]);
  29.     exit (1);
  30.     }
  31.  
  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. *thd++ = isc_action_svc_restore;
  55. *thd++ = isc_spb_bkp_file;
  56. *thd++ = strlen (argv[1]);
  57. *thd++ = strlen (argv[1]) >> 8;
  58. for (x = argv[1]; *x;)
  59.   *thd++ = *x++;
  60. *thd++ = isc_spb_dbname;
  61. *thd++ = strlen (argv[2]);
  62. *thd++ = strlen (argv[2]) >> 8;
  63. for (x = argv[2]; *x;)
  64.   *thd++ = *x++;
  65. *thd++ = isc_spb_verbose;
  66. *thd++ = isc_spb_options;
  67. n = isc_spb_res_replace;
  68. *thd++ = n;
  69. *thd++ = n >> 8;
  70. *thd++ = n >> 16;
  71. *thd++ = n >> 32;
  72.  
  73. printf ("<%u>\n", sizeof (ISC_ULONG));
  74. thdlen = thd - thd_buff;
  75.  
  76. printf ("Attach succeed\n");
  77.  
  78. if (isc_service_start(status, &svc_handle, NULL, thdlen, thd_buff))
  79.     {
  80.     isc_print_status (status);
  81.     isc_service_detach (status, &svc_handle);
  82.     exit(1);
  83.     }
  84. printf ("Start succeed\n");
  85.  
  86. do
  87.     {
  88.     if (isc_service_query (status, &svc_handle, NULL, 0, NULL,
  89.     sizeof (sendbuf), sendbuf, RESPBUF, respbuf))
  90.     {
  91.     isc_print_status (status);
  92.     isc_service_detach (status, &svc_handle);
  93.     exit(1);
  94.     }
  95.  
  96.     x = p = respbuf;
  97.  
  98.     if (*p++ == isc_info_svc_line)
  99.     {
  100.     ISC_USHORT len = 0, chTmp = 0, key;
  101.  
  102.     len = (ISC_USHORT)isc_vax_integer(p, sizeof(ISC_USHORT));
  103.     p += sizeof (ISC_USHORT);
  104.     if (!len)
  105.         if (*p ==  isc_info_data_not_ready)
  106.         {
  107.         printf ("no data available at this moment\n");
  108.         continue;
  109.         }
  110.         else
  111.         {
  112.         if (*p != isc_info_end)
  113.             printf ("Format error ... <%d>\n", *p);
  114.         break;
  115.         }
  116.     for (chTmp = 0; chTmp < len; chTmp++)
  117.         printf("%c",p[chTmp]);
  118.     p += len;
  119.     if (*p != isc_info_truncated && *p != isc_info_end)
  120.         {
  121.         printf ("Format error ... encountered <%d>\n", *p);
  122.         break;
  123.         }
  124.     else
  125.         {
  126.         /* printf ("\nisc_info_truncated  || isc_info_end\n"); */
  127.         }
  128.     }
  129.     else
  130.     printf ("not a isc_info_svc_line, but %d\n", *x);
  131.     }
  132. while (*x == isc_info_svc_line);
  133.  
  134. isc_service_detach(status, &svc_handle);
  135. }
  136.