static void tst_srw(void) { const char *charset = 0; char *content_buf = 0; int content_len; int ret; ODR o = odr_createmem(ODR_ENCODE); Z_SOAP_Handler h[2] = { {"http://www.loc.gov/zing/srw/", 0, (Z_SOAP_fun) yaz_srw_codec}, {0, 0, 0} }; Z_SRW_PDU *sr = yaz_srw_get(o, Z_SRW_searchRetrieve_request); Z_SOAP *p = (Z_SOAP *) odr_malloc(o, sizeof(*p)); YAZ_CHECK(o); YAZ_CHECK(sr); YAZ_CHECK(p); #if 0 sr->u.request->query = "jordb" "\xe6" "r"; #else sr->u.request->query = "jordbaer"; #endif p->which = Z_SOAP_generic; p->u.generic = (Z_SOAP_Generic *) odr_malloc(o, sizeof(*p->u.generic)); p->u.generic->no = 0; p->u.generic->ns = 0; p->u.generic->p = sr; p->ns = "http://schemas.xmlsoap.org/soap/envelope/"; ret = z_soap_codec_enc(o, &p, &content_buf, &content_len, h, charset); odr_destroy(o); YAZ_CHECK(ret == 0); /* codec failed ? */ }
static void yaz_xml2query_rpnstructure(const xmlNode *ptr, Z_RPNStructure **zs, ODR odr, int *error_code, const char **addinfo) { while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; if (!ptr || ptr->type != XML_ELEMENT_NODE) { *error_code = 1; *addinfo = "missing rpn operator, rset, apt node"; return; } if (check_diagnostic(ptr, odr, error_code, addinfo)) return; *zs = (Z_RPNStructure *) odr_malloc(odr, sizeof(Z_RPNStructure)); if (!xmlStrcmp(ptr->name, BAD_CAST "operator")) { Z_Complex *zc = (Z_Complex *) odr_malloc(odr, sizeof(Z_Complex)); (*zs)->which = Z_RPNStructure_complex; (*zs)->u.complex = zc; yaz_xml2query_operator(ptr, &zc->roperator, odr, error_code, addinfo); ptr = ptr->children; while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; yaz_xml2query_rpnstructure(ptr, &zc->s1, odr, error_code, addinfo); if (ptr) ptr = ptr->next; while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; yaz_xml2query_rpnstructure(ptr, &zc->s2, odr, error_code, addinfo); } else { Z_Operand *s = (Z_Operand *) odr_malloc(odr, sizeof(Z_Operand)); (*zs)->which = Z_RPNStructure_simple; (*zs)->u.simple = s; if (!xmlStrcmp(ptr->name, BAD_CAST "apt")) { s->which = Z_Operand_APT; yaz_xml2query_apt(ptr, &s->u.attributesPlusTerm, odr, error_code, addinfo); } else if (!xmlStrcmp(ptr->name, BAD_CAST "rset")) { s->which = Z_Operand_resultSetId; yaz_xml2query_rset(ptr, &s->u.resultSetId, odr, error_code, addinfo); } else { *error_code = 1; *addinfo = "bad element: expected binary, apt or rset"; } } }
static Z_InitRequest *zget_InitRequest(ODR o) { Z_InitRequest *r = (Z_InitRequest *)odr_malloc(o, sizeof(*r)); r->referenceId = 0; r->options = (Odr_bitmask *)odr_malloc(o, sizeof(*r->options)); ODR_MASK_ZERO(r->options); r->protocolVersion = (Odr_bitmask *) odr_malloc(o, sizeof(*r->protocolVersion)); ODR_MASK_SET(r->options, Z_Options_search); ODR_MASK_SET(r->options, Z_Options_present); ODR_MASK_ZERO(r->protocolVersion); ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_1); ODR_MASK_SET(r->protocolVersion, Z_ProtocolVersion_2); r->preferredMessageSize = odr_intdup(o, 1024*1024); r->maximumRecordSize = odr_intdup(o, 1024*1024); r->idAuthentication = 0; r->implementationId = "81"; r->implementationName = "YAZ"; r->implementationVersion = YAZ_VERSION #ifdef YAZ_VERSION_SHA1 " " YAZ_VERSION_SHA1 #endif ; r->userInformationField = 0; r->otherInfo = 0; return r; }
static Z_OriginProposal_0 *z_get_OriginProposal_0(ODR o, const char *charset) { int form = get_form(charset); Z_OriginProposal_0 *p0 = (Z_OriginProposal_0*)odr_malloc(o, sizeof(*p0)); memset(p0, 0, sizeof(*p0)); if (form > 0) { /* ISO 10646 (UNICODE) */ char oidname[20]; Z_Iso10646 *is = (Z_Iso10646 *) odr_malloc(o, sizeof(*is)); p0->which = Z_OriginProposal_0_iso10646; p0->u.iso10646 = is; is->collections = 0; sprintf(oidname, "1.0.10646.1.0.%d", form); is->encodingLevel = odr_getoidbystr(o, oidname); } else { /* private ones */ Z_PrivateCharacterSet *pc = (Z_PrivateCharacterSet *)odr_malloc(o, sizeof(*pc)); memset(pc, 0, sizeof(*pc)); p0->which = Z_OriginProposal_0_private; p0->u.zprivate = pc; pc->which = Z_PrivateCharacterSet_externallySpecified; pc->u.externallySpecified = z_ext_record2(o, charset); } return p0; }
int yaz_decode_http_response(ODR o, Z_HTTP_Response **hr_p) { int i, po; Z_HTTP_Response *hr = (Z_HTTP_Response *) odr_malloc(o, sizeof(*hr)); *hr_p = hr; hr->content_buf = 0; hr->content_len = 0; po = i = 5; while (i < o->size-2 && !strchr(" \r\n", o->buf[i])) i++; hr->version = (char *) odr_malloc(o, i - po + 1); if (i - po) memcpy(hr->version, o->buf + po, i - po); hr->version[i-po] = 0; if (o->buf[i] != ' ') { o->error = OHTTP; return 0; } i++; hr->code = 0; while (i < o->size-2 && o->buf[i] >= '0' && o->buf[i] <= '9') { hr->code = hr->code*10 + (o->buf[i] - '0'); i++; } while (i < o->size-1 && o->buf[i] != '\n') i++; return decode_headers_content(o, i, &hr->headers, &hr->content_buf, &hr->content_len); }
static Z_OriginProposal *z_get_OriginProposal( ODR o, const char **charsets, int num_charsets, const char **langs, int num_langs, int selected) { int i; Z_OriginProposal *p = (Z_OriginProposal *) odr_malloc(o, sizeof(*p)); memset(p, 0, sizeof(*p)); p->recordsInSelectedCharSets = (bool_t *)odr_malloc(o, sizeof(bool_t)); *p->recordsInSelectedCharSets = (selected) ? 1 : 0; if (charsets && num_charsets) { p->num_proposedCharSets = num_charsets; p->proposedCharSets = (Z_OriginProposal_0**) odr_malloc(o, num_charsets*sizeof(Z_OriginProposal_0*)); for (i = 0; i < num_charsets; i++) p->proposedCharSets[i] = z_get_OriginProposal_0(o, charsets[i]); } if (langs && num_langs) { p->num_proposedlanguages = num_langs; p->proposedlanguages = (char **) odr_malloc(o, num_langs*sizeof(char *)); for (i = 0; i < num_langs; i++) p->proposedlanguages[i] = (char *)langs[i]; } return p; }
Z_External *zget_init_diagnostics_octet(ODR odr, int error, const char *addinfo) { Z_External *x, *x2; Z_OtherInformation *u; Z_OtherInformationUnit *l; Z_DiagnosticFormat *d; Z_DiagnosticFormat_s *e; char *octet_buf; int octet_len; ODR encode; u = (Z_OtherInformation *) odr_malloc(odr, sizeof *u); u->num_elements = 1; u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list); u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]); l = u->list[0]; l->category = 0; l->which = Z_OtherInfo_externallyDefinedInfo; x2 = (Z_External*) odr_malloc(odr, sizeof *x); l->information.externallyDefinedInfo = x2; x2->descriptor = 0; x2->indirect_reference = 0; x2->direct_reference = odr_oiddup(odr, yaz_oid_diagset_diag_1); x2->which = Z_External_diag1; d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d); x2->u.diag1 = d; d->num = 1; d->elements = (Z_DiagnosticFormat_s**) odr_malloc(odr, sizeof *d->elements); d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc(odr, sizeof *d->elements[0]); e = d->elements[0]; e->which = Z_DiagnosticFormat_s_defaultDiagRec; e->u.defaultDiagRec = zget_DefaultDiagFormat(odr, error, addinfo); e->message = 0; encode = odr_createmem(ODR_ENCODE); z_OtherInformation(encode, &u, 0, 0); octet_buf = odr_getbuf(encode, &octet_len, 0); x = (Z_External*) odr_malloc(odr, sizeof *x); x->descriptor = 0; x->indirect_reference = 0; x->direct_reference = odr_oiddup(odr, yaz_oid_userinfo_userinfo_1); x->which = Z_External_octet; x->u.octet_aligned = (Odr_oct *) odr_malloc(odr, sizeof(Odr_oct)); x->u.octet_aligned->buf = (unsigned char *) odr_malloc(odr, octet_len); memcpy(x->u.octet_aligned->buf, octet_buf, octet_len); x->u.octet_aligned->len = octet_len; odr_destroy(encode); return x; }
Z_FacetList* facet_list_create(ODR odr, int num_facets) { Z_FacetList *facet_list = odr_malloc(odr, sizeof(*facet_list)); facet_list->num = num_facets; facet_list->elements = odr_malloc(odr, facet_list->num * sizeof(*facet_list->elements)); return facet_list; }
Z_FacetTerm* facet_term_create(ODR odr, Z_Term *term, int freq) { Z_FacetTerm *facet_term = odr_malloc(odr, sizeof(*facet_term)); facet_term->count = odr_malloc(odr, sizeof(*facet_term->count)); facet_term->term = term; *facet_term->count = freq; return facet_term; }
Z_DiagRecs *zget_DiagRecs(ODR o, int error, const char *addinfo) { Z_DiagRecs *drecs = (Z_DiagRecs*) odr_malloc(o, sizeof(*drecs)); Z_DiagRec **dr = (Z_DiagRec**) odr_malloc(o, sizeof(**dr)); drecs->diagRecs = dr; dr[0] = zget_DiagRec(o, error, addinfo); drecs->num_diagRecs = 1; return drecs; }
Z_FacetField* facet_field_create(ODR odr, Z_AttributeList *attributes, int num_terms) { Z_FacetField *facet_field = odr_malloc(odr, sizeof(*facet_field)); facet_field->attributes = attributes; facet_field->num_terms = num_terms; facet_field->terms = odr_malloc(odr, num_terms * sizeof(*facet_field->terms)); return facet_field; }
Odr_oct *odr_create_Odr_oct(ODR o, const unsigned char *buf, int sz) { Odr_oct *p = (Odr_oct *) odr_malloc(o, sizeof(Odr_oct)); p->buf = (unsigned char *) odr_malloc(o, sz); memcpy(p->buf, buf, sz); p->size = sz; p->len = sz; return p; }
int yaz_decode_http_request(ODR o, Z_HTTP_Request **hr_p) { int i, po; Z_HTTP_Request *hr = (Z_HTTP_Request *) odr_malloc(o, sizeof(*hr)); *hr_p = hr; /* method .. */ for (i = 0; o->buf[i] != ' '; i++) if (i >= o->size-5 || i > 30) { o->error = OHTTP; return 0; } hr->method = (char *) odr_malloc(o, i+1); memcpy (hr->method, o->buf, i); hr->method[i] = '\0'; /* path */ po = i+1; for (i = po; o->buf[i] != ' '; i++) if (i >= o->size-5) { o->error = OHTTP; return 0; } hr->path = (char *) odr_malloc(o, i - po + 1); memcpy (hr->path, o->buf+po, i - po); hr->path[i - po] = '\0'; /* HTTP version */ i++; if (i > o->size-5 || memcmp(o->buf+i, "HTTP/", 5)) { o->error = OHTTP; return 0; } i+= 5; po = i; while (i < o->size && !strchr("\r\n", o->buf[i])) i++; hr->version = (char *) odr_malloc(o, i - po + 1); memcpy(hr->version, o->buf + po, i - po); hr->version[i - po] = '\0'; /* headers */ if (i < o->size-1 && o->buf[i] == '\r') i++; if (o->buf[i] != '\n') { o->error = OHTTP; return 0; } return decode_headers_content(o, i, &hr->headers, &hr->content_buf, &hr->content_len); }
static Z_Complex *rpn_complex(struct yaz_pqf_parser *li, ODR o, int num_attr, int max_attr, Odr_int *attr_list, char **attr_clist, Odr_oid **attr_set) { Z_Complex *zc; Z_Operator *zo; zc = (Z_Complex *)odr_malloc (o, sizeof(*zc)); zo = (Z_Operator *)odr_malloc (o, sizeof(*zo)); zc->roperator = zo; switch (li->query_look) { case 'a': zo->which = Z_Operator_and; zo->u.op_and = odr_nullval(); break; case 'o': zo->which = Z_Operator_or; zo->u.op_or = odr_nullval(); break; case 'n': zo->which = Z_Operator_and_not; zo->u.and_not = odr_nullval(); break; case 'p': zo->which = Z_Operator_prox; zo->u.prox = rpn_proximity (li, o); if (!zo->u.prox) return NULL; break; default: /* we're only called if one of the above types are seens so this shouldn't happen */ li->error = YAZ_PQF_ERROR_INTERNAL; return NULL; } lex (li); if (!(zc->s1 = rpn_structure(li, o, num_attr, max_attr, attr_list, attr_clist, attr_set))) return NULL; if (!(zc->s2 = rpn_structure(li, o, num_attr, max_attr, attr_list, attr_clist, attr_set))) return NULL; return zc; }
void yaz_mk_sru_surrogate(ODR o, Z_SRW_record *record, int pos, int code, const char *details) { const char *message = yaz_diag_srw_str(code); int len = 200; if (message) len += strlen(message); if (details) len += strlen(details); record->recordData_buf = (char *) odr_malloc(o, len); sprintf(record->recordData_buf, "<diagnostic " "xmlns=\"http://www.loc.gov/zing/srw/diagnostic/\">\n" " <uri>info:srw/diagnostic/1/%d</uri>\n", code); if (details) sprintf(record->recordData_buf + strlen(record->recordData_buf), " <details>%s</details>\n", details); if (message) sprintf(record->recordData_buf + strlen(record->recordData_buf), " <message>%s</message>\n", message); sprintf(record->recordData_buf + strlen(record->recordData_buf), "</diagnostic>\n"); record->recordData_len = strlen(record->recordData_buf); record->recordPosition = odr_intdup(o, pos); record->recordSchema = "info:srw/schema/1/diagnostics-v1.1"; }
void yaz_cookies_request(yaz_cookies_t yc, ODR odr, Z_HTTP_Request *req) { struct cookie *c; size_t sz = 0; for (c = yc->list; c; c = c->next) { if (c->name && c->value) sz += strlen(c->name) + strlen(c->value) + 3; } if (sz) { char *buf = odr_malloc(odr, sz + 1); *buf = '\0'; for (c = yc->list; c; c = c->next) { if (*buf) strcat(buf, "; "); strcat(buf, c->name); strcat(buf, "="); strcat(buf, c->value); } z_HTTP_header_add(odr, &req->headers, "Cookie", buf); } }
Z_GDU *z_get_HTTP_Request_host_path(ODR odr, const char *host, const char *path) { Z_GDU *p = z_get_HTTP_Request(odr); p->u.HTTP_Request->path = odr_strdup(odr, path); if (host) { const char *cp0 = strstr(host, "://"); const char *cp1 = 0; if (cp0) cp0 = cp0+3; else cp0 = host; cp1 = strchr(cp0, '/'); if (!cp1) cp1 = cp0+strlen(cp0); if (cp0 && cp1) { char *h = (char*) odr_malloc(odr, cp1 - cp0 + 1); memcpy (h, cp0, cp1 - cp0); h[cp1-cp0] = '\0'; z_HTTP_header_add(odr, &p->u.HTTP_Request->headers, "Host", h); } } return p; }
bend_initresult *bend_init(bend_initrequest *q) { bend_initresult *r = (bend_initresult *) odr_malloc (q->stream, sizeof(*r)); int *counter = (int *) xmalloc (sizeof(int)); *counter = 0; r->errcode = 0; r->errstring = 0; r->handle = counter; /* user handle, in this case a simple int */ q->bend_sort = ztest_sort; /* register sort handler */ q->bend_search = ztest_search; /* register search handler */ q->bend_present = ztest_present; /* register present handle */ q->bend_esrequest = ztest_esrequest; q->bend_delete = ztest_delete; q->bend_fetch = ztest_fetch; q->bend_scan = ztest_scan; q->bend_explain = ztest_explain; if (read_conf_file()) { yaz_log(LOG_LOG,"Can't handle configuration file"); r->errcode = 2; } return r; }
int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu, ODR encode, const char *charset) { char *name[MAX_SRU_PARAMETERS], *value[MAX_SRU_PARAMETERS]; /* definite upper limit for SRU params */ char *uri_args; char *path; char *cp; z_HTTP_header_add_basic_auth(encode, &hreq->headers, srw_pdu->username, srw_pdu->password); if (yaz_get_sru_parms(srw_pdu, encode, name, value, MAX_SRU_PARAMETERS)) return -1; yaz_array_to_uri(&uri_args, encode, name, value); hreq->method = "GET"; cp = strchr(hreq->path, '#'); if (cp) *cp = '\0'; path = (char *) odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4); sprintf(path, "%s%c%s", hreq->path, strchr(hreq->path, '?') ? '&' : '?', uri_args); hreq->path = path; z_HTTP_header_add_content_type(encode, &hreq->headers, "text/xml", charset); return 0; }
Odr_oct *odr_create_Odr_oct(ODR o, const char *buf, int sz) { Odr_oct *p = (Odr_oct *) odr_malloc(o, sizeof(Odr_oct)); p->buf = odr_strdupn(o, buf, sz); p->len = sz; return p; }
Z_Term *term_create(ODR odr, const char *cstr) { Z_Term *term = odr_malloc(odr, sizeof(*term)); term->which = Z_Term_characterString; term->u.characterString = odr_strdup(odr, cstr); return term; }
Z_NamePlusRecord *zget_surrogateDiagRec(ODR o, const char *dbname, int error, const char *addinfo) { Z_NamePlusRecord *rec = (Z_NamePlusRecord *) odr_malloc(o, sizeof(*rec)); Z_DiagRec *drec = (Z_DiagRec *)odr_malloc(o, sizeof(*drec)); if (dbname) rec->databaseName = odr_strdup(o, dbname); else rec->databaseName = 0; rec->which = Z_NamePlusRecord_surrogateDiagnostic; rec->u.surrogateDiagnostic = drec; drec->which = Z_DiagRec_defaultFormat; drec->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo); return rec; }
Z_DiagRec *zget_DiagRec(ODR o, int error, const char *addinfo) { Z_DiagRec *dr = (Z_DiagRec*) odr_malloc(o, sizeof(*dr)); dr->which = Z_DiagRec_defaultFormat; dr->u.defaultFormat = zget_DefaultDiagFormat(o, error, addinfo); return dr; }
Z_GDU *z_get_HTTP_Request(ODR o) { Z_GDU *p = (Z_GDU *) odr_malloc(o, sizeof(*p)); Z_HTTP_Request *hreq; p->which = Z_GDU_HTTP_Request; p->u.HTTP_Request = (Z_HTTP_Request *) odr_malloc(o, sizeof(*hreq)); hreq = p->u.HTTP_Request; hreq->headers = 0; hreq->content_len = 0; hreq->content_buf = 0; hreq->version = "1.1"; hreq->method = "POST"; hreq->path = "/"; z_HTTP_header_add(o, &hreq->headers, "User-Agent", "YAZ/" YAZ_VERSION); return p; }
Z_FacetTerm *facet_term_create_cstr(ODR odr, const char *cstr, Odr_int freq) { Z_FacetTerm *facet_term = odr_malloc(odr, sizeof(*facet_term)); Z_Term *term = z_Term_create(odr, Z_Term_general, cstr, strlen(cstr)); facet_term->term = term; facet_term->count = odr_intdup(odr, freq); return facet_term; }
/* * HTTP Basic authentication is described at: * http://tools.ietf.org/html/rfc1945#section-11.1 */ void z_HTTP_header_add_basic_auth(ODR o, Z_HTTP_Header **hp, const char *username, const char *password) { char *tmp, *buf; int len; if (username == 0) return; if (password == 0) password = ""; len = strlen(username) + strlen(password); tmp = (char *) odr_malloc(o, len+2); sprintf(tmp, "%s:%s", username, password); buf = (char *) odr_malloc(o, (len+1) * 8/6 + 12); strcpy(buf, "Basic "); yaz_base64encode(tmp, &buf[strlen(buf)]); z_HTTP_header_add(o, hp, "Authorization", buf); }
static Z_CharSetandLanguageNegotiation *z_get_CharSetandLanguageNegotiation( ODR o) { Z_CharSetandLanguageNegotiation *p = (Z_CharSetandLanguageNegotiation *) odr_malloc(o, sizeof(*p)); memset(p, 0, sizeof(*p)); return p; }
Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o) { Z_SRW_extra_record *res = (Z_SRW_extra_record *) odr_malloc(o, sizeof(*res)); res->extraRecordData_buf = 0; res->extraRecordData_len = 0; res->recordIdentifier = 0; return res; }
void z_HTTP_header_add(ODR o, Z_HTTP_Header **hp, const char *n, const char *v) { while (*hp) hp = &(*hp)->next; *hp = (Z_HTTP_Header *) odr_malloc(o, sizeof(**hp)); (*hp)->name = odr_strdup(o, n); (*hp)->value = odr_strdup(o, v); (*hp)->next = 0; }
static int p_query_parse_attr(struct yaz_pqf_parser *li, ODR o, int num_attr, Odr_int *attr_list, char **attr_clist, Odr_oid **attr_set) { const char *cp; if (!(cp = strchr (li->lex_buf, '=')) || (size_t) (cp-li->lex_buf) > li->lex_len) { attr_set[num_attr] = query_oid_getvalbyname (li, o); if (attr_set[num_attr] == 0) { li->error = YAZ_PQF_ERROR_ATTSET; return 0; } if (!lex (li)) { li->error = YAZ_PQF_ERROR_MISSING; return 0; } if (!(cp = strchr (li->lex_buf, '='))) { li->error = YAZ_PQF_ERROR_BADATTR; return 0; } } else { if (num_attr > 0) attr_set[num_attr] = attr_set[num_attr-1]; else attr_set[num_attr] = 0; } if (*li->lex_buf < '0' || *li->lex_buf > '9') { li->error = YAZ_PQF_ERROR_BAD_INTEGER; return 0; } attr_list[2*num_attr] = atoi(li->lex_buf); cp++; if (*cp >= '0' && *cp <= '9') { attr_list[2*num_attr+1] = atoi (cp); attr_clist[num_attr] = 0; } else { int len = li->lex_len - (cp - li->lex_buf); attr_list[2*num_attr+1] = 0; attr_clist[num_attr] = (char *) odr_malloc (o, len+1); len = escape_string(attr_clist[num_attr], cp, len); attr_clist[num_attr][len] = '\0'; } return 1; }