Added code to enable sending of admin extended service requests
[yaz-moved-to-github.git] / client / admin.c
1 /*
2  * $Log: admin.c,v $
3  * Revision 1.1  2000-03-14 09:27:07  ian
4  * Added code to enable sending of admin extended service requests
5  *
6  *
7  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <time.h>
12
13 #include <yaz/yaz-util.h>
14
15 #include <yaz/tcpip.h>
16 #ifdef USE_XTIMOSI
17 #include <yaz/xmosi.h>
18 #endif
19
20 #include <yaz/proto.h>
21 #include <yaz/marcdisp.h>
22 #include <yaz/diagbib1.h>
23
24 #include <yaz/pquery.h>
25
26 #ifdef ASN_COMPILED
27 /* #include <yaz/esadmin.h> */
28 #endif
29
30
31 /* Helper functions to get to various statics in the client */
32 ODR getODROutputStream();
33 void send_apdu(Z_APDU *a);
34
35
36
37 int sendAdminES(int type, char* dbname)
38 {
39     ODR out = getODROutputStream();
40
41     /* Type: 1=reindex, 2=truncate, 3=delete, 4=create, 5=import, 6=refresh, 7=commit */
42     Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
43     Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
44     Z_External *r;
45     int oid[OID_SIZE];
46     Z_ESAdminOriginPartToKeep  *toKeep;
47     Z_ESAdminOriginPartNotToKeep  *notToKeep;
48     oident update_oid;
49     printf ("Admin request\n");
50     fflush(stdout);
51
52     update_oid.proto = PROTO_Z3950;
53     update_oid.oclass = CLASS_EXTSERV;
54     update_oid.value = VAL_ADMINSERVICE;
55
56     oid_ent_to_oid (&update_oid, oid);
57     req->packageType = odr_oiddup(out,oid);
58     req->packageName = "1.Extendedserveq";
59
60     r = req->taskSpecificParameters = (Z_External *)
61         odr_malloc (out, sizeof(*r));
62     r->direct_reference = odr_oiddup(out,oid);
63     r->indirect_reference = 0;
64     r->descriptor = 0;
65     r->which = Z_External_ESAdmin;
66     r->u.adminService = (Z_Admin *) odr_malloc(out, sizeof(*r->u.adminService));
67     r->u.adminService->which = Z_Admin_esRequest;
68     r->u.adminService->u.esRequest = (Z_AdminEsRequest *) odr_malloc(out, sizeof(*r->u.adminService->u.esRequest));
69
70     toKeep = r->u.adminService->u.esRequest->toKeep = (Z_ESAdminOriginPartToKeep *) 
71                      odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->toKeep));
72
73     switch ( type )
74     {
75         case 1:
76             toKeep->which=Z_ESAdminOriginPartToKeep_reIndex;
77             toKeep->u.reIndex=NULL;
78             break;
79         case 2:
80             toKeep->which=Z_ESAdminOriginPartToKeep_truncate;
81             toKeep->u.truncate=NULL;
82             break;
83         case 3:
84             toKeep->which=Z_ESAdminOriginPartToKeep_delete;
85             toKeep->u.delete=NULL;
86             break;
87         case 4:
88             toKeep->which=Z_ESAdminOriginPartToKeep_create;
89             toKeep->u.create=NULL;
90             break;
91         case 5:
92             toKeep->which=Z_ESAdminOriginPartToKeep_import;
93             toKeep->u.import=NULL;
94             break;
95         case 6:
96             toKeep->which=Z_ESAdminOriginPartToKeep_refresh;
97             toKeep->u.refresh=NULL;
98             break;
99         case 7:
100             toKeep->which=Z_ESAdminOriginPartToKeep_commit;
101             toKeep->u.commit=NULL;
102             break;
103     }
104
105
106     notToKeep = r->u.adminService->u.esRequest->notToKeep = (Z_ESAdminOriginPartNotToKeep *)
107         odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->notToKeep));
108     notToKeep->which=Z_ESAdminOriginPartNotToKeep_recordsWillFollow;
109     notToKeep->u.recordsWillFollow=NULL;
110     
111     send_apdu(apdu);
112
113     return 2;
114 }
115
116 /* cmd_adm_reindex <dbname>
117    Ask the specified database to fully reindex itself */
118 int cmd_adm_reindex(char* arg)
119 {
120     sendAdminES(1,arg);
121 }
122
123 /* cmd_adm_truncate <dbname>
124    Truncate the specified database, removing all records and index entries, but leaving 
125    the database & it's explain information intact ready for new records */
126 int cmd_adm_truncate(char* arg)
127 {
128     sendAdminES(2,arg);
129 }
130
131 /* cmd_adm_create <dbname>
132    Create a new database */
133 int cmd_adm_create(char* arg)
134 {
135     sendAdminES(4,arg);
136 }
137
138 /* cmd_adm_delete <dbname>
139    Delete a database */
140 int cmd_adm_delete(char* arg)
141 {
142     sendAdminES(3,arg);
143 }
144
145 /* cmd_adm_import <dbname> <rectype> <sourcefile>
146    Import the specified updated into the database
147    N.B. That in this case, the import may contain instructions to delete records as well as new or updates
148    to existing records */
149 int cmd_adm_import(char* arg)
150 {
151     sendAdminES(5,arg);
152 }
153
154 /* "Freshen" the specified database, by checking metadata records against the sources from which they were 
155    generated, and creating a new record if the source has been touched since the last extraction */
156 int cmd_adm_refresh(char* arg)
157 {
158     sendAdminES(6,arg);
159 }
160
161 /* cmd_adm_commit 
162    Make imported records a permenant & visible to the live system */
163 int cmd_adm_commit(char* arg)
164 {
165     sendAdminES(7,NULL);
166 }
167