static Odr_oid *query_oid_getvalbyname(struct yaz_pqf_parser *li, ODR o) { char buf[32]; if (li->lex_len >= sizeof(buf)-1) return 0; memcpy (buf, li->lex_buf, li->lex_len); buf[li->lex_len] = '\0'; return yaz_string_to_oid_odr(yaz_oid_std(), CLASS_ATTSET, buf, o); }
static void yaz_xml2query_rpn(const xmlNode *ptr, Z_RPNQuery **query, ODR odr, int *error_code, const char **addinfo) { const char *set = yaz_xml_get_prop((xmlNodePtr) ptr, "set"); *query = (Z_RPNQuery*) odr_malloc(odr, sizeof(Z_RPNQuery)); if (set) { (*query)->attributeSetId = yaz_string_to_oid_odr(yaz_oid_std(), CLASS_ATTSET, set, odr); } else (*query)->attributeSetId = 0; yaz_xml2query_rpnstructure(ptr->children, &(*query)->RPNStructure, odr, error_code, addinfo); }
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; }
Zlint_code Zlint_test_search_01::recv_gdu(Zlint *z, Z_GDU *gdu) { if (gdu->which == Z_GDU_Z3950 && gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse) { Z_InitResponse *init = gdu->u.z3950->u.initResponse; int result = init->result ? *init->result : 0; if (!result) { z->msg_check_notapp(); z->msg_check_info ("init rejected (result false)"); return TEST_FINISHED; } return sendTest(z); } else if (gdu->which == Z_GDU_Z3950 && gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_searchResponse) { Z_SearchResponse *sr = gdu->u.z3950->u.searchResponse; if (sr->records && (sr->records->which == Z_Records_NSD || sr->records->which == Z_Records_multipleNSD)) m_query_no++; else if (!sr->resultCount || *sr->resultCount == 0) m_query_no++; else { z->msg_check_ok(); z->msg_check_info("got %d result count with %s", *sr->resultCount, try_query[m_query_no]); m_got_result_set = 1; } return sendTest(z); } else if (gdu->which == Z_GDU_Z3950 && gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_presentResponse) { Z_PresentResponse *sr = gdu->u.z3950->u.presentResponse; if (sr->records && (sr->records->which == Z_Records_NSD || sr->records->which == Z_Records_multipleNSD)) { z->msg_check_ok(); z->msg_check_info("present returned NSD for %s", try_syntax[m_record_syntax_no]); } else if (sr->records && sr->records->which == Z_Records_DBOSD && sr->records->u.databaseOrSurDiagnostics->num_records>0 && sr->records->u.databaseOrSurDiagnostics->records[0]) { if (sr->records->u.databaseOrSurDiagnostics->records[0]->which == Z_NamePlusRecord_databaseRecord) { Z_External *ext = sr->records->u.databaseOrSurDiagnostics->records[0]->u.databaseRecord; Odr_oid *expectRecordSyntax = yaz_string_to_oid_odr( yaz_oid_std(), CLASS_RECSYN, try_syntax[m_record_syntax_no], z->odr_decode()); if (oid_oidcmp(expectRecordSyntax, ext->direct_reference)) { z->msg_check_fail("Got Record in different syntax " "from that requested %s", try_syntax[m_record_syntax_no]); } else z->msg_check_ok(); } else if (sr->records->u.databaseOrSurDiagnostics->records[0]->which == Z_NamePlusRecord_surrogateDiagnostic) { z->msg_check_ok(); z->msg_check_info("present returned SD %s", try_syntax[m_record_syntax_no]); } else { z->msg_check_ok(); z->msg_check_info("present returned fragment %s", try_syntax[m_record_syntax_no]); } } else { z->msg_check_fail("present returned no records or diagnostics"); } m_record_syntax_no++; return sendTest(z); } else if (gdu->which == Z_GDU_Z3950 && gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_sortResponse) { Z_SortResponse *sr = gdu->u.z3950->u.sortResponse; z->msg_check_ok(); if (sr->diagnostics) z->msg_check_info( "sort NSD for %s", try_sort[m_sort_no]); m_sort_no++; return sendTest(z); } else z->msg_check_fail("did not receive init/search/present response " "as expected"); return TEST_FINISHED; }
static int cql_transform_parse_tok_line(cql_transform_t ct, const char *pattern, yaz_tok_parse_t tp) { int ae_num = 0; Z_AttributeElement *ae[20]; int ret = 0; /* 0=OK, != 0 FAIL */ int t; t = yaz_tok_move(tp); while (t == YAZ_TOK_STRING && ae_num < 20) { WRBUF type_str = wrbuf_alloc(); WRBUF set_str = 0; Z_AttributeElement *elem = 0; const char *value_str = 0; /* attset type=value OR type=value */ elem = (Z_AttributeElement *) nmem_malloc(ct->nmem, sizeof(*elem)); elem->attributeSet = 0; ae[ae_num] = elem; wrbuf_puts(ct->w, yaz_tok_parse_string(tp)); wrbuf_puts(type_str, yaz_tok_parse_string(tp)); t = yaz_tok_move(tp); if (t == YAZ_TOK_EOF) { wrbuf_destroy(type_str); if (set_str) wrbuf_destroy(set_str); break; } if (t == YAZ_TOK_STRING) { wrbuf_puts(ct->w, " "); wrbuf_puts(ct->w, yaz_tok_parse_string(tp)); set_str = type_str; elem->attributeSet = yaz_string_to_oid_nmem(yaz_oid_std(), CLASS_ATTSET, wrbuf_cstr(set_str), ct->nmem); type_str = wrbuf_alloc(); wrbuf_puts(type_str, yaz_tok_parse_string(tp)); t = yaz_tok_move(tp); } elem->attributeType = nmem_intdup(ct->nmem, 0); if (sscanf(wrbuf_cstr(type_str), ODR_INT_PRINTF, elem->attributeType) != 1) { wrbuf_destroy(type_str); if (set_str) wrbuf_destroy(set_str); yaz_log(YLOG_WARN, "Expected numeric attribute type"); ret = -1; break; } wrbuf_destroy(type_str); if (set_str) wrbuf_destroy(set_str); if (t != '=') { yaz_log(YLOG_WARN, "Expected = after after attribute type"); ret = -1; break; } t = yaz_tok_move(tp); if (t != YAZ_TOK_STRING) /* value */ { yaz_log(YLOG_WARN, "Missing attribute value"); ret = -1; break; } value_str = yaz_tok_parse_string(tp); if (yaz_isdigit(*value_str)) { elem->which = Z_AttributeValue_numeric; elem->value.numeric = nmem_intdup(ct->nmem, atoi(value_str)); } else { Z_ComplexAttribute *ca = (Z_ComplexAttribute *) nmem_malloc(ct->nmem, sizeof(*ca)); elem->which = Z_AttributeValue_complex; elem->value.complex = ca; ca->num_list = 1; ca->list = (Z_StringOrNumeric **) nmem_malloc(ct->nmem, sizeof(Z_StringOrNumeric *)); ca->list[0] = (Z_StringOrNumeric *) nmem_malloc(ct->nmem, sizeof(Z_StringOrNumeric)); ca->list[0]->which = Z_StringOrNumeric_string; ca->list[0]->u.string = nmem_strdup(ct->nmem, value_str); ca->num_semanticAction = 0; ca->semanticAction = 0; } wrbuf_puts(ct->w, "="); wrbuf_puts(ct->w, yaz_tok_parse_string(tp)); t = yaz_tok_move(tp); wrbuf_puts(ct->w, " "); ae_num++; } if (ret == 0) /* OK? */ { struct cql_prop_entry **pp = &ct->entry; while (*pp) pp = &(*pp)->next; *pp = (struct cql_prop_entry *) xmalloc(sizeof(**pp)); (*pp)->pattern = xstrdup(pattern); (*pp)->value = xstrdup(wrbuf_cstr(ct->w)); (*pp)->attr_list.num_attributes = ae_num; if (ae_num == 0) (*pp)->attr_list.attributes = 0; else { (*pp)->attr_list.attributes = (Z_AttributeElement **) nmem_malloc(ct->nmem, ae_num * sizeof(Z_AttributeElement *)); memcpy((*pp)->attr_list.attributes, ae, ae_num * sizeof(Z_AttributeElement *)); } (*pp)->next = 0; if (0) { ODR pr = odr_createmem(ODR_PRINT); Z_AttributeList *alp = &(*pp)->attr_list; odr_setprint(pr, yaz_log_file()); z_AttributeList(pr, &alp, 0, 0); odr_setprint(pr, 0); odr_destroy(pr); } } return ret; }
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); } }