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

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4. #include <windows.h>
  5. #include "ibase.h"
  6.  
  7. #define RESPBUF    256
  8.  
  9. void 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    respbuf[RESPBUF], *p = respbuf, *spb = spb_buff, *thd = thd_buff,*x;
  19. short    spblen, thdlen;
  20. int    i = 0, cnt=0;
  21. boolean finished = FALSE;
  22.  
  23. if (argc != 3)
  24.     {
  25.     printf ("Usage: %s dbfile backupfile\n", argv[0]);
  26.     exit (1);
  27.     }
  28.  
  29. *spb++ = isc_spb_version;
  30. *spb++ = isc_spb_current_version;
  31.  
  32. *spb++ = isc_spb_user_name;
  33. *spb++ = strlen (user);
  34. for (x = user; *x;)
  35.   *spb++ = *x++;
  36.  
  37. *spb++ = isc_spb_password;
  38. *spb++ = strlen (pass);
  39. for (x = pass; *x;)
  40.   *spb++ = *x++;
  41.  
  42. sprintf (svc_name, "willaby:service_mgr");
  43.  
  44. spblen = spb - spb_buff;
  45.  
  46. if (isc_service_attach (status, 0, svc_name, &svc_handle, spblen, spb_buff))
  47.     {
  48.     isc_print_status (status);
  49.     exit (1);
  50.     }
  51.  
  52. *thd++ = isc_action_svc_backup;
  53. *thd++ = isc_spb_dbname;
  54. *thd++ = strlen (argv[1]);
  55. *thd++ = strlen (argv[1]) >> 8;
  56. for (x = argv[1]; *x;)
  57.   *thd++ = *x++;
  58. *thd++ = isc_spb_bkp_file;
  59. *thd++ = strlen (argv[2]);
  60. *thd++ = strlen (argv[2]) >> 8;
  61. for (x = argv[2]; *x;)
  62.   *thd++ = *x++;
  63. *thd++ = isc_spb_verbose;
  64.  
  65. thdlen = thd - thd_buff;
  66.  
  67. printf ("Attach succeed\n");
  68.  
  69. if (isc_service_start(status, &svc_handle, NULL, thdlen, thd_buff))
  70.     {
  71.     long *vector = status;
  72.     printf ("Unable to start service:\n");
  73.     while (isc_interprete (respbuf, &vector))
  74.         printf ("ERROR: %s\n", respbuf);
  75.     printf ("End of errors\n");
  76.     isc_service_detach (status, &svc_handle);
  77.     exit(1);
  78.     }
  79. printf ("Start succeed\n");
  80.  
  81. do
  82.     {
  83.     char sendbuf[] = {isc_info_svc_line};
  84.     ISC_STATUS  loc_status[20], *stat = loc_status;
  85.     if (isc_service_query (status, &svc_handle, NULL, 0, NULL, sizeof (sendbuf), sendbuf, RESPBUF, respbuf))
  86.         {
  87.         isc_print_status (status);
  88.         isc_service_detach (status, &svc_handle);
  89.         exit(1);
  90.         }
  91.     
  92.     x = p = respbuf;
  93.     
  94.     if (*p++ == isc_info_svc_line)
  95.         {
  96.         ISC_USHORT len = 0, chTmp = 0;
  97.         
  98.         len = (ISC_USHORT)isc_vax_integer(p, sizeof(ISC_USHORT));
  99.         p += sizeof (ISC_USHORT);
  100.         if (!len)
  101.             if (*p ==  isc_info_data_not_ready)
  102.                 {
  103.                 printf ("no data available at this moment\n");
  104.                 continue;
  105.                 }
  106.             else
  107.                 {
  108.                 if (*p != isc_info_end)
  109.                     printf ("Format error ... <%d>\n", *p);
  110.                 break;
  111.                 }
  112.             for (chTmp = 0; chTmp < len; chTmp++)
  113.                 printf("%c",p[chTmp]);
  114.             p += len;
  115.             if (*p != isc_info_truncated && *p != isc_info_end)
  116.                 {
  117.                 printf ("Format error ... encountered <%d>\n", *p);
  118.                 break;
  119.                 }
  120.             else
  121.                 {
  122.                 //                printf ("\nisc_info_truncated  || isc_info_end\n");
  123.                 }
  124.         }
  125.     else
  126.         printf ("not a isc_info_svc_line, but %d\n", *x);
  127.     }
  128.     while (*x == isc_info_svc_line);
  129.         
  130. isc_service_detach(status, &svc_handle);
  131. }
  132.