int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu, Z_SOAP **soap_package, ODR decode, char **charset) { if (!strcmp(hreq->method, "POST")) { const char *content_type = z_HTTP_header_lookup(hreq->headers, "Content-Type"); if (content_type && (!yaz_strcmp_del("text/xml", content_type, "; ") || !yaz_strcmp_del("application/soap+xml", content_type, "; ") || !yaz_strcmp_del("text/plain", content_type, "; "))) { char *db = "Default"; const char *p0 = hreq->path, *p1; int ret = -1; static Z_SOAP_Handler soap_handlers[5] = { #if YAZ_HAVE_XML2 { YAZ_XMLNS_SRU_v1_1, 0, (Z_SOAP_fun) yaz_srw_codec }, { YAZ_XMLNS_SRU_v1_0, 0, (Z_SOAP_fun) yaz_srw_codec }, { YAZ_XMLNS_UPDATE_v0_9, 0, (Z_SOAP_fun) yaz_ucp_codec }, { YAZ_XMLNS_SRU_v2_mask, 0, (Z_SOAP_fun) yaz_srw_codec }, #endif {0, 0, 0} }; if (*p0 == '/') p0++; p1 = strchr(p0, '?'); if (!p1) p1 = p0 + strlen(p0); if (p1 != p0) db = yaz_decode_sru_dbpath_odr(decode, p0, p1 - p0); ret = z_soap_codec(decode, soap_package, &hreq->content_buf, &hreq->content_len, soap_handlers); if (ret == 0 && (*soap_package)->which == Z_SOAP_generic) { *srw_pdu = (Z_SRW_PDU*) (*soap_package)->u.generic->p; yaz_srw_decodeauth(*srw_pdu, hreq, 0, 0, decode); /* last entry in handlers - SRU 2.0 - is turned into offset 0.. due to other pieces relying on it */ if ((*soap_package)->u.generic->no == 3) (*soap_package)->u.generic->no = 0; if ((*srw_pdu)->which == Z_SRW_searchRetrieve_request && (*srw_pdu)->u.request->database == 0) (*srw_pdu)->u.request->database = db; if ((*srw_pdu)->which == Z_SRW_explain_request && (*srw_pdu)->u.explain_request->database == 0) (*srw_pdu)->u.explain_request->database = db; if ((*srw_pdu)->which == Z_SRW_scan_request && (*srw_pdu)->u.scan_request->database == 0) (*srw_pdu)->u.scan_request->database = db; if ((*srw_pdu)->which == Z_SRW_update_request && (*srw_pdu)->u.update_request->database == 0) (*srw_pdu)->u.update_request->database = db; return 0; } return 1; } } return 2; }
int main(int argc, char **argv) { char buf[163840]; char *content_buf = buf; int content_len; size_t no; Z_SOAP *soap_package = 0; ODR decode, encode; int debug = 0; if (argc == 2 && !strcmp(argv[1], "debug")) debug = 1; no = fread(buf, 1, sizeof(buf), stdin); if (no < 1 || no == sizeof(buf)) { fprintf(stderr, "Bad file or too big\n"); exit (1); } decode = odr_createmem(ODR_DECODE); encode = odr_createmem(ODR_ENCODE); content_len = no; z_soap_codec(decode, &soap_package, &content_buf, &content_len, h); if (!soap_package) { fprintf(stderr, "Decoding seriously failed\n"); exit(1); } if (debug) { fprintf(stderr, "got NS = %s\n", soap_package->ns); if (soap_package->which == Z_SOAP_generic && soap_package->u.generic->no == 0) { Z_SRW_PDU *sr = (Z_SRW_PDU *) soap_package->u.generic->p; if (sr->which == Z_SRW_searchRetrieve_request) { Z_SRW_searchRetrieveRequest *req = sr->u.request; switch(req->query_type) { case Z_SRW_query_type_cql: fprintf(stderr, "CQL: %s\n", req->query.cql); break; case Z_SRW_query_type_xcql: fprintf(stderr, "XCQL\n"); break; case Z_SRW_query_type_pqf: fprintf(stderr, "PQF: %s\n", req->query.pqf); break; } } else if (sr->which == Z_SRW_searchRetrieve_response) { Z_SRW_searchRetrieveResponse *res = sr->u.response; if (res->records && res->num_records) { int i; for (i = 0; i<res->num_records; i++) { fprintf (stderr, "%d\n", i); if (res->records[i].recordData_buf) { fprintf(stderr, "%.*s", res->records[i].recordData_len, res->records[i].recordData_buf); } } } } } } z_soap_codec(encode, &soap_package, &content_buf, &content_len, h); if (content_buf && content_len) { printf("%.*s", content_len, content_buf); } else { fprintf(stderr, "No output!\n"); exit(1); } odr_destroy(decode); odr_destroy(encode); exit(0); }