home *** CD-ROM | disk | FTP | other *** search
/ Freelog 42 / Freelog042.iso / Alu / Ancestrologie / Sources / InterBase_WI-V6.0.1-server.ZIP / examples / services / start_backup_split.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-05  |  2.9 KB  |  142 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    i = 0;
  23.  
  24.  
  25. if (argc != 5)
  26.     {
  27.     printf ("Usage: %s dbfile gbk1file size gbk2file\n", argv[0]);
  28.     exit (1);
  29.     }
  30.  
  31. *spb++ = isc_spb_version;
  32. *spb++ = isc_spb_current_version;
  33.  
  34. *spb++ = isc_spb_user_name;
  35. *spb++ = strlen (user);
  36. for (x = user; *x;)
  37.   *spb++ = *x++;
  38.  
  39. *spb++ = isc_spb_password;
  40. *spb++ = strlen (pass);
  41. for (x = pass; *x;)
  42.   *spb++ = *x++;
  43.  
  44. sprintf (svc_name, "typhoon:service_mgr");
  45.  
  46. spblen = spb - spb_buff;
  47.  
  48. if (isc_service_attach (status, 0, svc_name, &svc_handle, spblen, spb_buff))
  49.     {
  50.     isc_print_status (status);
  51.     exit (1);
  52.     }
  53.  
  54. *thd++ = isc_action_svc_backup;
  55. *thd++ = isc_spb_dbname;
  56. *thd++ = (strlen (argv[1]) + 1);
  57. *thd++ = (strlen (argv[1]) + 1) >> 8;
  58. for (x = argv[1]; *x;)
  59.   *thd++ = *x++;
  60. *thd++ = isc_spb_bkp_file;
  61. *thd++ = strlen (argv[2]);
  62. *thd++ = strlen (argv[2]) >> 8;
  63. for (x = argv[2]; *x;)
  64.   *thd++ = *x++;
  65.  
  66. *thd++ = isc_spb_bkp_length;
  67. *thd++ = atoi (argv[3]);
  68. *thd++ = atoi (argv[3]) >> 8;
  69. *thd++ = atoi (argv[3]) >> 16;
  70. *thd++ = atoi (argv[3]) >> 24;
  71. *thd++ = isc_spb_bkp_file;
  72. *thd++ = strlen (argv[4]);
  73. *thd++ = strlen (argv[4]) >> 8;
  74. for (x = argv[4]; *x;)
  75.     *thd++ = *x++;
  76.  
  77. *thd++ = isc_spb_verbose;
  78.  
  79. thdlen = thd - thd_buff;
  80.  
  81. printf ("Attach succeed\n");
  82.  
  83. if (isc_service_start(status, &svc_handle, NULL, thdlen, thd_buff))
  84.     {
  85.     isc_print_status (status);
  86.     isc_service_detach (status, &svc_handle);
  87.     exit(1);
  88.     }
  89. printf ("Start succeed\n");
  90.  
  91. do
  92.     {
  93.     if (isc_service_query (status, &svc_handle, NULL, 0, NULL,
  94.     sizeof (sendbuf), sendbuf, RESPBUF, respbuf))
  95.     {
  96.     isc_print_status (status);
  97.     isc_service_detach (status, &svc_handle);
  98.     exit(1);
  99.     }
  100.  
  101.     x = p = respbuf;
  102.  
  103.     if (*p++ == isc_info_svc_line)
  104.     {
  105.     ISC_USHORT len = 0, chTmp = 0, key;
  106.  
  107.     len = (ISC_USHORT)isc_vax_integer(p, sizeof(ISC_USHORT));
  108.     p += sizeof (ISC_USHORT);
  109.     if (!len)
  110.         if (*p == isc_info_data_not_ready)
  111.         {
  112.         printf ("no data available at this moment\n");
  113.         continue;
  114.         }
  115.         else
  116.         {
  117.         if (*p != isc_info_end)
  118.             printf ("Format error ... <%d>\n", *p);
  119.         break;
  120.         }
  121.     for (chTmp = 0; chTmp < len; chTmp++)
  122.         printf("%c",p[chTmp]);
  123.     p += len;
  124.     if (*p != isc_info_truncated && *p != isc_info_end)
  125.         {
  126.         printf ("Format error ... encountered <%d>\n", *p);
  127.         break;
  128.         }
  129.     else
  130.         {
  131.         /* printf ("\nisc_info_truncated  || isc_info_end\n"); */
  132.         }
  133.     }
  134.     else
  135.     printf ("not a isc_info_svc_line, but %d\n", *x);
  136.     }
  137. while (*x == isc_info_svc_line);
  138.  
  139.  
  140. isc_service_detach(status, &svc_handle);
  141. }
  142.