Esempio n. 1
0
File: charneg.c Progetto: nla/yaz
/* Delete negotiation from OtherInformation. Client&Server side */
int yaz_del_charneg_record(Z_OtherInformation **p)
{
    int i;

    if (!*p)
        return 0;

    for (i = 0; i < (*p)->num_elements; i++)
    {
        Z_External *pext;
        if (((*p)->list[i]->which == Z_OtherInfo_externallyDefinedInfo) &&
            (pext = (*p)->list[i]->information.externallyDefinedInfo))
        {
            if (!oid_oidcmp(pext->direct_reference, yaz_oid_negot_charset_3)
                && pext->which == Z_External_charSetandLanguageNegotiation)
            {
                if ((*p)->num_elements <= 1)
                    *p = 0;
                else
                {
                    --((*p)->num_elements);
                    for (; i < (*p)->num_elements; i++)
                        (*p)->list[i] = (*p)->list[i+1];
                }
                return 1;
            }
        }
    }
    return 0;
}
Esempio n. 2
0
/* 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;
}
Esempio n. 3
0
/* Get negotiation from OtherInformation. Client&Server side */
Z_CharSetandLanguageNegotiation *yaz_get_charneg_record(Z_OtherInformation *p)
{
    int i;
        
    if (!p)
        return 0;
        
    for (i = 0; i < p->num_elements; i++) {
        Z_External *pext;
        if ((p->list[i]->which == Z_OtherInfo_externallyDefinedInfo) &&
            (pext = p->list[i]->information.externallyDefinedInfo)) {
            
            if (!oid_oidcmp(pext->direct_reference, yaz_oid_negot_charset_3)
                && pext->which == Z_External_charSetandLanguageNegotiation)
            {
                return pext->u.charNeg3;
            }
        }
    }
    return 0;
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
File: otherinfo.c Progetto: nla/yaz
Z_OtherInformationUnit *yaz_oi_update(
    Z_OtherInformation **otherInformationP, ODR odr,
    const Odr_oid *oid, int categoryValue, int delete_flag)
{
    int i;
    Z_OtherInformation *otherInformation;

    if (!otherInformationP)
        return 0;
    otherInformation = *otherInformationP;
    if (!otherInformation)
    {
        if (!odr)
            return 0;
        otherInformation = *otherInformationP = (Z_OtherInformation *)
            odr_malloc (odr, sizeof(*otherInformation));
        otherInformation->num_elements = 0;
        otherInformation->list = 0;
    }
    for (i = 0; i<otherInformation->num_elements; i++)
    {
        if (!oid)
        {
            /*  DS: Want does this do? Returns the first element without a category */
            if (!otherInformation->list[i]->category)
                return otherInformation->list[i];
        }
        else
        {
            if (otherInformation->list[i]->category &&
                categoryValue ==
                *otherInformation->list[i]->category->categoryValue &&
                !oid_oidcmp (oid, otherInformation->list[i]->category->
                             categoryTypeId))
            {
                Z_OtherInformationUnit *this_list = otherInformation->list[i];

                if (delete_flag)
                {
                    (otherInformation->num_elements)--;
                    while (i < otherInformation->num_elements)
                    {
                        otherInformation->list[i] =
                            otherInformation->list[i+1];
                        i++;
                    }
                }
                return this_list;
            }
        }
    }
    if (!odr)
        return 0;
    else
    {
        Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
            odr_malloc(odr, (otherInformation->num_elements+1) *
                       sizeof(*newlist));
        for (i = 0; i<otherInformation->num_elements; i++)
            newlist[i] = otherInformation->list[i];
        otherInformation->list = newlist;

        otherInformation->list[i] = (Z_OtherInformationUnit*)
            odr_malloc (odr, sizeof(Z_OtherInformationUnit));
        if (oid)
        {
            otherInformation->list[i]->category = (Z_InfoCategory*)
                odr_malloc (odr, sizeof(Z_InfoCategory));
            otherInformation->list[i]->category->categoryTypeId = (Odr_oid*)
                odr_oiddup (odr, oid);
            otherInformation->list[i]->category->categoryValue =
                odr_intdup(odr, categoryValue);
        }
        else
            otherInformation->list[i]->category = 0;
        otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
        otherInformation->list[i]->information.characterInfo = 0;

        otherInformation->num_elements = i+1;
        return otherInformation->list[i];
    }
}