/* retrieval of a single record (present, and piggy back search) */ static int my_fetch(void *handle, bend_fetch_rr *r) { const Odr_oid *oid = r->request_format; r->last_in_set = 0; r->basename = "Default"; r->output_format = r->request_format; /* if no record syntax was given assume XML */ if (!oid || !oid_oidcmp(oid, yaz_oid_recsyn_xml)) { char buf[40]; yaz_snprintf(buf, sizeof(buf), "<record>%d</record>\n", r->number); r->output_format = odr_oiddup(r->stream, yaz_oid_recsyn_xml); r->record = odr_strdup(r->stream, buf); r->len = strlen(r->record); } else { /* only xml syntax supported . Return diagnostic */ char buf[OID_STR_MAX]; r->errcode = YAZ_BIB1_RECORD_SYNTAX_UNSUPP; r->errstring = odr_strdup(r->stream, oid_oid_to_dotstring(oid, buf)); } return 0; }
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; }
void yaz_mk_srw_diagnostic(ODR o, Z_SRW_diagnostic *d, const char *uri, const char *message, const char *details) { d->uri = odr_strdup(o, uri); if (message) d->message = odr_strdup(o, message); else d->message = 0; if (details) d->details = odr_strdup(o, details); else d->details = 0; }
static void grab_charset(ODR o, const char *content_type, char **charset) { if (charset) { const char *charset_p = 0; if (content_type && (charset_p = strstr(content_type, "; charset="))) { int j = 0, i = 0; int sep = 0; charset_p += 10; /* skip ; charset= */ if (charset_p[i] == '"' || charset_p[i] == '\'') sep = charset_p[i++]; *charset = odr_strdup(o, charset_p); while (charset_p[i] && charset_p[i] != sep) { if (!sep && strchr("; \n\r", charset_p[i])) break; if (charset_p[i] == '\\' && charset_p[i+1]) i++; (*charset)[j++] = charset_p[i++]; } (*charset)[j] = '\0'; } } }
void yf::HttpRewrite1::Rep::rewrite_response(mp::odr &o, Z_HTTP_Response *hres) { const char *ctype = z_HTTP_header_lookup(hres->headers, "Content-Type"); if (ctype && hres->content_buf) { std::string text(hres->content_buf, hres->content_len); std::list<Rule>::const_iterator it; int number_of_replaces = 0; for (it = rules.begin(); it != rules.end(); it++) { if (strcmp(ctype, it->content_type.c_str()) == 0) { boost::regex::flag_type b_mode = boost::regex::perl; if (it->mode.find_first_of('i') != std::string::npos) b_mode |= boost::regex::icase; boost::regex e(it->pattern, b_mode); boost::match_flag_type match_mode = boost::format_first_only; if (it->mode.find_first_of('g') != std::string::npos) match_mode = boost::format_all; text = regex_replace(text, e, it->replacement, match_mode); number_of_replaces++; } } if (number_of_replaces > 0) { hres->content_buf = odr_strdup(o, text.c_str()); hres->content_len = strlen(hres->content_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; }
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; }
static Z_SRW_PDU *yaz_srw_get_core_ver(ODR o, const char *version) { Z_SRW_PDU *p = (Z_SRW_PDU *) odr_malloc(o, sizeof(*p)); p->srw_version = odr_strdup(o, version); p->username = 0; p->password = 0; p->extra_args = 0; p->extraResponseData_buf = 0; p->extraResponseData_len = 0; return p; }
Z_DefaultDiagFormat *zget_DefaultDiagFormat(ODR o, int error, const char *addinfo) { Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *) odr_malloc(o, sizeof(*dr)); dr->diagnosticSetId = odr_oiddup(o, yaz_oid_diagset_bib_1); dr->condition = odr_intdup(o, error); dr->which = Z_DefaultDiagFormat_v2Addinfo; dr->u.v2Addinfo = odr_strdup (o, addinfo ? addinfo : ""); return dr; }
void yaz_oi_set_string_oid ( Z_OtherInformation **otherInformation, ODR odr, const Odr_oid *oid, int categoryValue, const char *str) { Z_OtherInformationUnit *oi = yaz_oi_update(otherInformation, odr, oid, categoryValue, 0); if (!oi) return; oi->which = Z_OtherInfo_characterInfo; oi->information.characterInfo = odr_strdup (odr, str); }
/** * Look for authentication tokens in HTTP Basic parameters or in x-username/x-password * parameters. Added by SH. */ static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq, char *username, char *password, ODR decode) { const char *basic = z_HTTP_header_lookup(hreq->headers, "Authorization"); if (username) sr->username = username; if (password) sr->password = password; if (basic) { int len; char out[256]; char ubuf[256] = "", pbuf[256] = "", *p; if (strncmp(basic, "Basic ", 6)) return; basic += 6; len = strlen(basic); if (!len || len > 256) return; yaz_base64decode(basic, out); /* Format of out should be username:password at this point */ strcpy(ubuf, out); if ((p = strchr(ubuf, ':'))) { *(p++) = '\0'; if (*p) strcpy(pbuf, p); } if (*ubuf) sr->username = odr_strdup(decode, ubuf); if (*pbuf) sr->password = odr_strdup(decode, pbuf); } }
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; }
/* used by yaz_set_response_charneg */ static Z_TargetResponse *z_get_TargetResponse(ODR o, const char *charset, const char *lang, int selected) { Z_TargetResponse *p = (Z_TargetResponse *) odr_malloc(o, sizeof(*p)); int form = get_form(charset); memset(p, 0, sizeof(*p)); if (form > 0) { char oidname[20]; Z_Iso10646 *is = (Z_Iso10646 *) odr_malloc (o, sizeof(*is)); p->which = Z_TargetResponse_iso10646; p->u.iso10646 = is; is->collections = 0; sprintf (oidname, "1.0.10646.1.0.%d", form); is->encodingLevel = odr_getoidbystr (o, oidname); } else { Z_PrivateCharacterSet *pc = (Z_PrivateCharacterSet *)odr_malloc(o, sizeof(*pc)); memset(pc, 0, sizeof(*pc)); p->which = Z_TargetResponse_private; p->u.zprivate = pc; pc->which = Z_PrivateCharacterSet_externallySpecified; pc->u.externallySpecified = z_ext_record2(o, charset); } p->recordsInSelectedCharSets = (bool_t *)odr_malloc(o, sizeof(bool_t)); *p->recordsInSelectedCharSets = (selected) ? 1:0; p->selectedLanguage = lang ? (char *)odr_strdup(o, lang) : 0; return p; }
static int check_diagnostic(const xmlNode *ptr, ODR odr, int *error_code, const char **addinfo) { if (ptr && ptr->type == XML_ELEMENT_NODE && !xmlStrcmp(ptr->name, BAD_CAST "diagnostic")) { struct _xmlAttr *attr; const char *code_str = 0; const char *addinfo_str = 0; for (attr = ptr->properties; attr; attr = attr->next) { if (!xmlStrcmp(attr->name, BAD_CAST "code") && attr->children && attr->children->type == XML_TEXT_NODE) code_str = (const char *) attr->children->content; else if (!xmlStrcmp(attr->name, BAD_CAST "addinfo") && attr->children && attr->children->type == XML_TEXT_NODE) addinfo_str = (const char *) attr->children->content; else { *error_code = 1; *addinfo = "bad attribute for diagnostic element"; return 1; } } if (!code_str) { *error_code = 1; *addinfo = "missing @code for diagnostic element"; return 1; } *error_code = atoi(code_str); if (addinfo_str) *addinfo = odr_strdup(odr, addinfo_str); return 1; } else return 0; }
Zlint_code Zlint_test_search_01::sendTest(Zlint *z) { if (!m_got_result_set) { Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_searchRequest); Z_SearchRequest *sr; sr = apdu->u.searchRequest; sr->query = (Z_Query *) odr_malloc(z->odr_encode(), sizeof(*sr->query)); if (try_query[m_query_no] && sr) { sr->query->which = Z_Query_type_1; Z_RPNQuery *rpn; YAZ_PQF_Parser pqf_parser = yaz_pqf_create (); z->getDatabase(&sr->databaseNames, &sr->num_databaseNames); rpn = yaz_pqf_parse(pqf_parser, z->odr_encode(), try_query[m_query_no]); yaz_pqf_destroy (pqf_parser); if (!rpn) { z->msg_check_fail("Query %s invalid", try_query[m_query_no]); return TEST_FINISHED; } int len; sr->query->u.type_1 = rpn; z->send_Z_PDU(apdu, &len); } else { z->msg_check_notapp(); z->msg_check_info("unable to get any hit count"); return TEST_FINISHED; } } else if (m_got_result_set && try_syntax[m_record_syntax_no]) { int len; Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_presentRequest); Z_PresentRequest *pr = apdu->u.presentRequest; *pr->numberOfRecordsRequested = 1; *pr->resultSetStartPoint = 1; z->msg_check_for("record syntax %s", try_syntax[m_record_syntax_no]); pr->preferredRecordSyntax = yaz_string_to_oid_odr(yaz_oid_std(), CLASS_RECSYN, try_syntax[m_record_syntax_no], z->odr_encode()); z->send_Z_PDU(apdu, &len); return TEST_CONTINUE; } else if(m_got_result_set && !try_syntax[m_record_syntax_no]) { Z_APDU *apdu = zget_APDU(z->odr_encode(), Z_APDU_sortRequest); if (apdu && try_sort[m_sort_no]) { z->msg_check_for("sort %s", try_sort[m_sort_no]); const char *setstring = "default"; int len; Z_SortRequest *sr = apdu->u.sortRequest; sr->num_inputResultSetNames = 1; sr->num_inputResultSetNames = 1; sr->inputResultSetNames = (Z_InternationalString **) odr_malloc (z->odr_encode(), sizeof(*sr->inputResultSetNames)); sr->inputResultSetNames[0] = odr_strdup (z->odr_encode(), setstring); sr->sortedResultSetName = odr_strdup(z->odr_encode(), setstring); sr->sortSequence = yaz_sort_spec(z->odr_encode(), try_sort[m_sort_no]); z->send_Z_PDU(apdu, &len); } else return TEST_FINISHED; } else { printf ("finished...\n"); return TEST_FINISHED; } return TEST_CONTINUE; }
Z_SortKeySpecList *yaz_sort_spec (ODR out, const char *arg) { char sort_string_buf[64], sort_flags[64]; Z_SortKeySpecList *sksl = (Z_SortKeySpecList *) odr_malloc (out, sizeof(*sksl)); int off; sksl->num_specs = 0; sksl->specs = (Z_SortKeySpec **)odr_malloc (out, sizeof(sksl->specs) * 20); while ((sscanf (arg, "%63s %63s%n", sort_string_buf, sort_flags, &off)) == 2 && off > 1) { int i; char *sort_string_sep; char *sort_string = sort_string_buf; Z_SortKeySpec *sks = (Z_SortKeySpec *)odr_malloc (out, sizeof(*sks)); Z_SortKey *sk = (Z_SortKey *)odr_malloc (out, sizeof(*sk)); arg += off; sksl->specs[sksl->num_specs++] = sks; sks->sortElement = (Z_SortElement *) odr_malloc (out, sizeof(*sks->sortElement)); sks->sortElement->which = Z_SortElement_generic; sks->sortElement->u.generic = sk; if ((sort_string_sep = strchr (sort_string, '='))) { int i = 0; sk->which = Z_SortKey_sortAttributes; sk->u.sortAttributes = (Z_SortAttributes *) odr_malloc (out, sizeof(*sk->u.sortAttributes)); sk->u.sortAttributes->id = odr_oiddup(out, yaz_oid_attset_bib_1); sk->u.sortAttributes->list = (Z_AttributeList *) odr_malloc (out, sizeof(*sk->u.sortAttributes->list)); sk->u.sortAttributes->list->attributes = (Z_AttributeElement **) odr_malloc (out, 10 * sizeof(*sk->u.sortAttributes->list->attributes)); while (i < 10 && sort_string && sort_string_sep) { Z_AttributeElement *el = (Z_AttributeElement *) odr_malloc (out, sizeof(*el)); sk->u.sortAttributes->list->attributes[i] = el; el->attributeSet = 0; el->attributeType = odr_intdup (out, atoi (sort_string)); el->which = Z_AttributeValue_numeric; el->value.numeric = odr_intdup (out, atoi (sort_string_sep + 1)); i++; sort_string = strchr(sort_string, ','); if (sort_string) { sort_string++; sort_string_sep = strchr (sort_string, '='); } } sk->u.sortAttributes->list->num_attributes = i; } else { sk->which = Z_SortKey_sortField; sk->u.sortField = odr_strdup (out, sort_string); } sks->sortRelation = odr_intdup (out, Z_SortKeySpec_ascending); sks->caseSensitivity = odr_intdup (out, Z_SortKeySpec_caseSensitive); sks->which = Z_SortKeySpec_null; sks->u.null = odr_nullval (); for (i = 0; sort_flags[i]; i++) { switch (sort_flags[i]) { case 'd': case 'D': case '>': *sks->sortRelation = Z_SortKeySpec_descending; break; case 'a': case 'A': case '<': *sks->sortRelation = Z_SortKeySpec_ascending; break; case 'i': case 'I': *sks->caseSensitivity = Z_SortKeySpec_caseInsensitive; break; case 'S': case 's': *sks->caseSensitivity = Z_SortKeySpec_caseSensitive; break; case '!': sks->which = Z_SortKeySpec_abort; sks->u.abort = odr_nullval(); break; case '=': sks->which = Z_SortKeySpec_missingValueData; sks->u.missingValueData = (Odr_oct*) odr_malloc(out, sizeof(Odr_oct)); i++; sks->u.missingValueData->len = strlen(sort_flags+i); sks->u.missingValueData->size = sks->u.missingValueData->len; sks->u.missingValueData->buf = (unsigned char*) odr_strdup(out, sort_flags+i); i += strlen(sort_flags+i); } } } if (!sksl->num_specs) return 0; return sksl; }
static void yaz_xml2query_attribute_element(const xmlNode *ptr, Z_AttributeElement **elem, ODR odr, int *error_code, const char **addinfo) { int i; xmlChar *set = 0; xmlChar *type = 0; xmlChar *value = 0; int num_values = 0; struct _xmlAttr *attr; for (attr = ptr->properties; attr; attr = attr->next) { if (!xmlStrcmp(attr->name, BAD_CAST "set") && attr->children && attr->children->type == XML_TEXT_NODE) set = attr->children->content; else if (!xmlStrcmp(attr->name, BAD_CAST "type") && attr->children && attr->children->type == XML_TEXT_NODE) type = attr->children->content; else if (!xmlStrcmp(attr->name, BAD_CAST "value") && attr->children && attr->children->type == XML_TEXT_NODE) { value = attr->children->content; num_values++; } else { *error_code = 1; *addinfo = "bad attribute for attr content"; return; } } if (!type) { *error_code = 1; *addinfo = "missing type attribute for att content"; return; } if (!value) { *error_code = 1; *addinfo = "missing value attribute for att content"; return; } *elem = (Z_AttributeElement *) odr_malloc(odr, sizeof(**elem)); if (set) (*elem)->attributeSet = yaz_string_to_oid_odr(yaz_oid_std(), CLASS_ATTSET, (const char *) set, odr); else (*elem)->attributeSet = 0; (*elem)->attributeType = intVal(odr, (const char *) type); /* looks like a number ? */ for (i = 0; value[i] && value[i] >= '0' && value[i] <= '9'; i++) ; if (num_values > 1 || value[i]) { /* multiple values or string, so turn to complex attribute */ (*elem)->which = Z_AttributeValue_complex; (*elem)->value.complex = (Z_ComplexAttribute*) odr_malloc(odr, sizeof(Z_ComplexAttribute)); (*elem)->value.complex->num_list = num_values; (*elem)->value.complex->list = (Z_StringOrNumeric **) odr_malloc(odr, sizeof(Z_StringOrNumeric*) * num_values); /* second pass over attr values */ i = 0; for (attr = ptr->properties; attr; attr = attr->next) { if (!xmlStrcmp(attr->name, BAD_CAST "value") && attr->children && attr->children->type == XML_TEXT_NODE) { const char *val = (const char *) attr->children->content; assert (i < num_values); (*elem)->value.complex->list[i] = (Z_StringOrNumeric *) odr_malloc(odr, sizeof(Z_StringOrNumeric)); (*elem)->value.complex->list[i]->which = Z_StringOrNumeric_string; (*elem)->value.complex->list[i]->u.string = odr_strdup(odr, val); i++; } } (*elem)->value.complex->num_semanticAction = 0; (*elem)->value.complex->semanticAction = 0; } else { /* good'ld numeric value */ (*elem)->which = Z_AttributeValue_numeric; (*elem)->value.numeric = intVal(odr, (const char *) value); } }
/* this huge function handles extended services */ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) { /* user-defined handle - created in bend_init */ int *counter = (int*) handle; yaz_log(LOG_LOG, "ESRequest no %d", *counter); (*counter)++; if (rr->esr->packageName) yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName); yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction); yaz_log(LOG_LOG, "function: %d", *rr->esr->function); if (!rr->esr->taskSpecificParameters) { yaz_log (LOG_WARN, "No task specific parameters"); } else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder) { Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder; yaz_log (LOG_LOG, "Received ItemOrder"); if (it->which == Z_IOItemOrder_esRequest) { Z_IORequest *ir = it->u.esRequest; Z_IOOriginPartToKeep *k = ir->toKeep; Z_IOOriginPartNotToKeep *n = ir->notToKeep; if (k && k->contact) { if (k->contact->name) yaz_log(LOG_LOG, "contact name %s", k->contact->name); if (k->contact->phone) yaz_log(LOG_LOG, "contact phone %s", k->contact->phone); if (k->contact->email) yaz_log(LOG_LOG, "contact email %s", k->contact->email); } if (k->addlBilling) { yaz_log(LOG_LOG, "Billing info (not shown)"); } if (n->resultSetItem) { yaz_log(LOG_LOG, "resultsetItem"); yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId); yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item); } if (n->itemRequest) { Z_External *r = (Z_External*) n->itemRequest; ILL_ItemRequest *item_req = 0; ILL_APDU *ill_apdu = 0; if (r->direct_reference) { oident *ent = oid_getentbyoid(r->direct_reference); if (ent) yaz_log(LOG_LOG, "OID %s", ent->desc); if (ent && ent->value == VAL_TEXT_XML) { yaz_log (LOG_LOG, "ILL XML request"); if (r->which == Z_External_octet) yaz_log (LOG_LOG, "%.*s", r->u.octet_aligned->len, r->u.octet_aligned->buf); } if (ent && ent->value == VAL_ISO_ILL_1) { yaz_log (LOG_LOG, "Decode ItemRequest begin"); if (r->which == ODR_EXTERNAL_single) { odr_setbuf(rr->decode, (char *) r->u.single_ASN1_type->buf, r->u.single_ASN1_type->len, 0); if (!ill_ItemRequest (rr->decode, &item_req, 0, 0)) { yaz_log (LOG_LOG, "Couldn't decode ItemRequest %s near %d", odr_errmsg(odr_geterror(rr->decode)), odr_offset(rr->decode)); } else yaz_log(LOG_LOG, "Decode ItemRequest OK"); if (rr->print) { ill_ItemRequest (rr->print, &item_req, 0, "ItemRequest"); odr_reset (rr->print); } } if (!item_req && r->which == ODR_EXTERNAL_single) { yaz_log (LOG_LOG, "Decode ILL APDU begin"); odr_setbuf(rr->decode, (char*) r->u.single_ASN1_type->buf, r->u.single_ASN1_type->len, 0); if (!ill_APDU (rr->decode, &ill_apdu, 0, 0)) { yaz_log (LOG_LOG, "Couldn't decode ILL APDU %s near %d", odr_errmsg(odr_geterror(rr->decode)), odr_offset(rr->decode)); yaz_log(LOG_LOG, "PDU dump:"); odr_dumpBER(yaz_log_file(), (char *) r->u.single_ASN1_type->buf, r->u.single_ASN1_type->len); } else yaz_log(LOG_LOG, "Decode ILL APDU OK"); if (rr->print) { ill_APDU (rr->print, &ill_apdu, 0, "ILL APDU"); odr_reset (rr->print); } } } } if (item_req) { yaz_log (LOG_LOG, "ILL protocol version = %d", *item_req->protocol_version_num); } } if (k) { Z_External *ext = (Z_External *) odr_malloc (rr->stream, sizeof(*ext)); Z_IUOriginPartToKeep *keep = (Z_IUOriginPartToKeep *) odr_malloc (rr->stream, sizeof(*keep)); Z_IOTargetPart *targetPart = (Z_IOTargetPart *) odr_malloc (rr->stream, sizeof(*targetPart)); rr->taskPackage = (Z_TaskPackage *) odr_malloc (rr->stream, sizeof(*rr->taskPackage)); rr->taskPackage->packageType = odr_oiddup (rr->stream, rr->esr->packageType); rr->taskPackage->packageName = 0; rr->taskPackage->userId = 0; rr->taskPackage->retentionTime = 0; rr->taskPackage->permissions = 0; rr->taskPackage->description = 0; rr->taskPackage->targetReference = (Odr_oct *) odr_malloc (rr->stream, sizeof(Odr_oct)); rr->taskPackage->targetReference->buf = (unsigned char *) odr_strdup (rr->stream, "911"); rr->taskPackage->targetReference->len = rr->taskPackage->targetReference->size = strlen((char *) (rr->taskPackage->targetReference->buf)); rr->taskPackage->creationDateTime = 0; rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0); rr->taskPackage->packageDiagnostics = 0; rr->taskPackage->taskSpecificParameters = ext; ext->direct_reference = odr_oiddup (rr->stream, rr->esr->packageType); ext->indirect_reference = 0; ext->descriptor = 0; ext->which = Z_External_itemOrder; ext->u.itemOrder = (Z_ItemOrder *) odr_malloc (rr->stream, sizeof(*ext->u.update)); ext->u.itemOrder->which = Z_IOItemOrder_taskPackage; ext->u.itemOrder->u.taskPackage = (Z_IOTaskPackage *) odr_malloc (rr->stream, sizeof(Z_IOTaskPackage)); ext->u.itemOrder->u.taskPackage->originPart = k; ext->u.itemOrder->u.taskPackage->targetPart = targetPart; targetPart->itemRequest = 0; targetPart->statusOrErrorReport = 0; targetPart->auxiliaryStatus = 0; } } } else if (rr->esr->taskSpecificParameters->which == Z_External_update) { Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update; yaz_log (LOG_LOG, "Received DB Update"); if (up->which == Z_IUUpdate_esRequest) { Z_IUUpdateEsRequest *esRequest = up->u.esRequest; Z_IUOriginPartToKeep *toKeep = esRequest->toKeep; Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep; yaz_log (LOG_LOG, "action"); if (toKeep->action) { switch (*toKeep->action) { case Z_IUOriginPartToKeep_recordInsert: yaz_log (LOG_LOG, " recordInsert"); break; case Z_IUOriginPartToKeep_recordReplace: yaz_log (LOG_LOG, " recordReplace"); break; case Z_IUOriginPartToKeep_recordDelete: yaz_log (LOG_LOG, " recordDelete"); break; case Z_IUOriginPartToKeep_elementUpdate: yaz_log (LOG_LOG, " elementUpdate"); break; case Z_IUOriginPartToKeep_specialUpdate: yaz_log (LOG_LOG, " specialUpdate"); break; default: yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action); } } if (toKeep->databaseName) { yaz_log (LOG_LOG, "database: %s", toKeep->databaseName); if (!strcmp(toKeep->databaseName, "fault")) { rr->errcode = 109; rr->errstring = toKeep->databaseName; } if (!strcmp(toKeep->databaseName, "accept")) rr->errcode = -1; } if (toKeep) { Z_External *ext = (Z_External *) odr_malloc (rr->stream, sizeof(*ext)); Z_IUOriginPartToKeep *keep = (Z_IUOriginPartToKeep *) odr_malloc (rr->stream, sizeof(*keep)); Z_IUTargetPart *targetPart = (Z_IUTargetPart *) odr_malloc (rr->stream, sizeof(*targetPart)); rr->taskPackage = (Z_TaskPackage *) odr_malloc (rr->stream, sizeof(*rr->taskPackage)); rr->taskPackage->packageType = odr_oiddup (rr->stream, rr->esr->packageType); rr->taskPackage->packageName = 0; rr->taskPackage->userId = 0; rr->taskPackage->retentionTime = 0; rr->taskPackage->permissions = 0; rr->taskPackage->description = 0; rr->taskPackage->targetReference = (Odr_oct *) odr_malloc (rr->stream, sizeof(Odr_oct)); rr->taskPackage->targetReference->buf = (unsigned char *) odr_strdup (rr->stream, "123"); rr->taskPackage->targetReference->len = rr->taskPackage->targetReference->size = strlen((char *) (rr->taskPackage->targetReference->buf)); rr->taskPackage->creationDateTime = 0; rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0); rr->taskPackage->packageDiagnostics = 0; rr->taskPackage->taskSpecificParameters = ext; ext->direct_reference = odr_oiddup (rr->stream, rr->esr->packageType); ext->indirect_reference = 0; ext->descriptor = 0; ext->which = Z_External_update; ext->u.update = (Z_IUUpdate *) odr_malloc (rr->stream, sizeof(*ext->u.update)); ext->u.update->which = Z_IUUpdate_taskPackage; ext->u.update->u.taskPackage = (Z_IUUpdateTaskPackage *) odr_malloc (rr->stream, sizeof(Z_IUUpdateTaskPackage)); ext->u.update->u.taskPackage->originPart = keep; ext->u.update->u.taskPackage->targetPart = targetPart; keep->action = (int *) odr_malloc (rr->stream, sizeof(int)); *keep->action = *toKeep->action; keep->databaseName = odr_strdup (rr->stream, toKeep->databaseName); keep->schema = 0; keep->elementSetName = 0; keep->actionQualifier = 0; targetPart->updateStatus = odr_intdup (rr->stream, 1); targetPart->num_globalDiagnostics = 0; targetPart->globalDiagnostics = (Z_DiagRec **) odr_nullval(); targetPart->num_taskPackageRecords = 1; targetPart->taskPackageRecords = (Z_IUTaskPackageRecordStructure **) odr_malloc (rr->stream, sizeof(Z_IUTaskPackageRecordStructure *)); targetPart->taskPackageRecords[0] = (Z_IUTaskPackageRecordStructure *) odr_malloc (rr->stream, sizeof(Z_IUTaskPackageRecordStructure)); targetPart->taskPackageRecords[0]->which = Z_IUTaskPackageRecordStructure_record; targetPart->taskPackageRecords[0]->u.record = z_ext_record (rr->stream, VAL_SUTRS, "test", 4); targetPart->taskPackageRecords[0]->correlationInfo = 0; targetPart->taskPackageRecords[0]->recordStatus = odr_intdup (rr->stream, Z_IUTaskPackageRecordStructure_success); targetPart->taskPackageRecords[0]->num_supplementalDiagnostics = 0; targetPart->taskPackageRecords[0]->supplementalDiagnostics = 0; } if (notToKeep) { int i; for (i = 0; i < notToKeep->num; i++) { Z_External *rec = notToKeep->elements[i]->record; if (rec->direct_reference) { struct oident *oident; oident = oid_getentbyoid(rec->direct_reference); if (oident) yaz_log (LOG_LOG, "record %d type %s", i, oident->desc); } switch (rec->which) { case Z_External_sutrs: if (rec->u.octet_aligned->len > 170) yaz_log (LOG_LOG, "%d bytes:\n%.168s ...", rec->u.sutrs->len, rec->u.sutrs->buf); else yaz_log (LOG_LOG, "%d bytes:\n%s", rec->u.sutrs->len, rec->u.sutrs->buf); break; case Z_External_octet : if (rec->u.octet_aligned->len > 170) yaz_log (LOG_LOG, "%d bytes:\n%.168s ...", rec->u.octet_aligned->len, rec->u.octet_aligned->buf); else yaz_log (LOG_LOG, "%d bytes\n%s", rec->u.octet_aligned->len, rec->u.octet_aligned->buf); } } } } } else if (rr->esr->taskSpecificParameters->which == Z_External_update0) { yaz_log(LOG_LOG, "Received DB Update (version 0)"); } else { yaz_log (LOG_WARN, "Unknown Extended Service(%d)", rr->esr->taskSpecificParameters->which); } return 0; }
int sendAdminES(int type, char* param1) { ODR out = getODROutputStream(); char *dbname = odr_strdup (out, databaseNames[0]); /* Type: 1=reindex, 2=truncate, 3=delete, 4=create, 5=import, 6=refresh, 7=commit */ Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest ); Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest; Z_External *r; Odr_oid *oid; Z_ESAdminOriginPartToKeep *toKeep; Z_ESAdminOriginPartNotToKeep *notToKeep; printf ("Admin request\n"); fflush(stdout); oid = odr_oiddup(out, yaz_oid_extserv_admin); req->packageType = oid; req->packageName = "1.Extendedserveq"; /* Allocate the external */ r = req->taskSpecificParameters = (Z_External *) odr_malloc (out, sizeof(*r)); r->direct_reference = odr_oiddup(out,oid); r->indirect_reference = 0; r->descriptor = 0; r->which = Z_External_ESAdmin; r->u.adminService = (Z_Admin *) odr_malloc(out, sizeof(*r->u.adminService)); r->u.adminService->which = Z_Admin_esRequest; r->u.adminService->u.esRequest = (Z_AdminEsRequest *) odr_malloc(out, sizeof(*r->u.adminService->u.esRequest)); toKeep = r->u.adminService->u.esRequest->toKeep = (Z_ESAdminOriginPartToKeep *) odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->toKeep)); toKeep->which=type; toKeep->databaseName = dbname; switch ( type ) { case Z_ESAdminOriginPartToKeep_reIndex: toKeep->u.reIndex=odr_nullval(); break; case Z_ESAdminOriginPartToKeep_truncate: toKeep->u.truncate=odr_nullval(); break; case Z_ESAdminOriginPartToKeep_drop: toKeep->u.drop=odr_nullval(); break; case Z_ESAdminOriginPartToKeep_create: toKeep->u.create=odr_nullval(); break; case Z_ESAdminOriginPartToKeep_import: toKeep->u.import = (Z_ImportParameters*) odr_malloc(out, sizeof(*toKeep->u.import)); toKeep->u.import->recordType=param1; /* Need to add additional setup of records here */ break; case Z_ESAdminOriginPartToKeep_refresh: toKeep->u.refresh=odr_nullval(); break; case Z_ESAdminOriginPartToKeep_commit: toKeep->u.commit=odr_nullval(); break; case Z_ESAdminOriginPartToKeep_shutdown: toKeep->u.commit=odr_nullval(); break; case Z_ESAdminOriginPartToKeep_start: toKeep->u.commit=odr_nullval(); break; default: /* Unknown admin service */ break; } notToKeep = r->u.adminService->u.esRequest->notToKeep = (Z_ESAdminOriginPartNotToKeep *) odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->notToKeep)); notToKeep->which=Z_ESAdminOriginPartNotToKeep_recordsWillFollow; notToKeep->u.recordsWillFollow=odr_nullval(); send_apdu(apdu); return 0; }
Z_HTTP_Response *yaz_url_exec(yaz_url_t p, const char *uri, const char *method, Z_HTTP_Header *user_headers, const char *buf, size_t len) { Z_HTTP_Response *res = 0; int number_of_redirects = 0; yaz_cookies_reset(p->cookies); wrbuf_rewind(p->w_error); while (1) { void *add; COMSTACK conn = 0; int code; const char *location = 0; char *http_user = 0; char *http_pass = 0; char *uri_lean = 0; Z_GDU *gdu; extract_user_pass(p->odr_out->mem, uri, &uri_lean, &http_user, &http_pass); gdu = z_get_HTTP_Request_uri(p->odr_out, uri_lean, 0, p->proxy ? 1 : 0); gdu->u.HTTP_Request->method = odr_strdup(p->odr_out, method); yaz_cookies_request(p->cookies, p->odr_out, gdu->u.HTTP_Request); for ( ; user_headers; user_headers = user_headers->next) { /* prefer new Host over user-supplied Host */ if (!strcmp(user_headers->name, "Host")) ; /* prefer user-supplied User-Agent over YAZ' own */ else if (!strcmp(user_headers->name, "User-Agent")) z_HTTP_header_set(p->odr_out, &gdu->u.HTTP_Request->headers, user_headers->name, user_headers->value); else z_HTTP_header_add(p->odr_out, &gdu->u.HTTP_Request->headers, user_headers->name, user_headers->value); } if (http_user && http_pass) z_HTTP_header_add_basic_auth(p->odr_out, &gdu->u.HTTP_Request->headers, http_user, http_pass); res = 0; if (buf && len) { gdu->u.HTTP_Request->content_buf = (char *) buf; gdu->u.HTTP_Request->content_len = len; } if (!z_GDU(p->odr_out, &gdu, 0, 0)) { wrbuf_printf(p->w_error, "Can not encode HTTP request for URL %s", uri); log_warn(p); return 0; } conn = cs_create_host_proxy(uri_lean, 1, &add, p->proxy); if (!conn) { wrbuf_printf(p->w_error, "Can not resolve URL %s", uri); log_warn(p); } else if (cs_connect(conn, add) < 0) { wrbuf_printf(p->w_error, "Can not connect to URL %s", uri); log_warn(p); } else { int len; char *buf = odr_getbuf(p->odr_out, &len, 0); if (p->verbose) fwrite(buf, 1, len, stdout); if (cs_put(conn, buf, len) < 0) { wrbuf_printf(p->w_error, "cs_put fail for URL %s", uri); log_warn(p); } else { char *netbuffer = 0; int netlen = 0; int cs_res = cs_get(conn, &netbuffer, &netlen); if (cs_res <= 0) { wrbuf_printf(p->w_error, "cs_get failed for URL %s", uri); log_warn(p); } else { Z_GDU *gdu; if (p->verbose) fwrite(netbuffer, 1, cs_res, stdout); odr_setbuf(p->odr_in, netbuffer, cs_res, 0); if (!z_GDU(p->odr_in, &gdu, 0, 0) || gdu->which != Z_GDU_HTTP_Response) { wrbuf_printf(p->w_error, "HTTP decoding fail for " "URL %s", uri); log_warn(p); } else { res = gdu->u.HTTP_Response; } } xfree(netbuffer); } } if (conn) cs_close(conn); if (!res) break; code = res->code; location = z_HTTP_header_lookup(res->headers, "Location"); if (++number_of_redirects <= p->max_redirects && location && (code == 301 || code == 302 || code == 307)) { int host_change = 0; const char *nlocation = yaz_check_location(p->odr_in, uri, location, &host_change); odr_reset(p->odr_out); uri = odr_strdup(p->odr_out, nlocation); } else break; yaz_cookies_response(p->cookies, res); odr_reset(p->odr_in); } return res; }
static Z_GenericRecord *read_grs1(FILE *f, ODR o) { char line[512], *buf; int type, ivalue; char value[512]; Z_GenericRecord *r = 0; for (;;) { Z_TaggedElement *t; Z_ElementData *c; while (fgets(buf = line, 512, f)) { while (*buf && isspace(*(unsigned char *) buf)) buf++; if (!*buf || *buf == '#') continue; break; } if (*buf == '}') return r; if (sscanf(buf, "(%d,%[^)])", &type, value) != 2) { yaz_log(YLOG_WARN, "Bad data in '%s'", buf); return 0; } if (!type && *value == '0') return r; if (!(buf = strchr(buf, ')'))) return 0; buf++; while (*buf && isspace(*(unsigned char *) buf)) buf++; if (!*buf) return 0; if (!r) { r = (Z_GenericRecord *)odr_malloc(o, sizeof(*r)); r->elements = (Z_TaggedElement **) odr_malloc(o, sizeof(Z_TaggedElement*) * GRS_MAX_FIELDS); r->num_elements = 0; } r->elements[r->num_elements] = t = (Z_TaggedElement *) odr_malloc(o, sizeof(Z_TaggedElement)); t->tagType = odr_intdup(o, type); t->tagValue = (Z_StringOrNumeric *) odr_malloc(o, sizeof(Z_StringOrNumeric)); if ((ivalue = atoi(value))) { t->tagValue->which = Z_StringOrNumeric_numeric; t->tagValue->u.numeric = odr_intdup(o, ivalue); } else { t->tagValue->which = Z_StringOrNumeric_string; t->tagValue->u.string = (char *)odr_malloc(o, strlen(value)+1); strcpy(t->tagValue->u.string, value); } t->tagOccurrence = 0; t->metaData = 0; t->appliedVariant = 0; t->content = c = (Z_ElementData *)odr_malloc(o, sizeof(Z_ElementData)); if (*buf == '{') { c->which = Z_ElementData_subtree; c->u.subtree = read_grs1(f, o); } else { c->which = Z_ElementData_string; buf[strlen(buf)-1] = '\0'; c->u.string = odr_strdup(o, buf); } r->num_elements++; } }