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