Remove 'and Mike Taylor' clause from copyright
[yazpp-moved-to-github.git] / zlint / test-init-07.cpp
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) Index Data 
3  * See the file LICENSE for details.
4  */
5
6 #if HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9 #include <yaz/log.h>
10 #include <yaz/charneg.h>
11 #include <yaz/otherinfo.h>
12
13 #include <zlint.h>
14
15 Zlint_test_init_07::Zlint_test_init_07()
16 {
17 }
18
19 Zlint_test_init_07::~Zlint_test_init_07()
20 {
21 }
22
23 Zlint_code Zlint_test_init_07::init(Zlint *z)
24 {
25     int len;
26     Z_APDU *apdu = z->create_Z_PDU(Z_APDU_initRequest);
27     Z_InitRequest *init = apdu->u.initRequest;
28     Z_OtherInformation **oi;
29
30     z->msg_check_for("for character set negotiation");
31
32     /* set all options.. see what target really supports .. */
33     ODR_MASK_SET(init->protocolVersion, Z_ProtocolVersion_3);
34     yaz_oi_APDU(apdu, &oi);
35     if (!oi)
36     {
37         z->msg_check_fail("encoding failure");
38         return TEST_FINISHED;
39     }
40     else
41     {
42         Z_OtherInformationUnit *p0;
43         const char *negotiationCharset[] = {
44             "UTF-8",
45             "UTF-16",
46             "UCS-2",
47             "UCS-4",
48             "ISO-8859-1"
49         };
50         char *yazLang = 0;
51
52         if ((p0=yaz_oi_update(oi, z->odr_encode(), NULL, 0, 0))) {
53             ODR_MASK_SET(init->options, Z_Options_negotiationModel);
54
55             p0->which = Z_OtherInfo_externallyDefinedInfo;
56             p0->information.externallyDefinedInfo =
57
58                 yaz_set_proposal_charneg(
59                     z->odr_encode(),
60                     negotiationCharset, 5,
61                     (const char**)&yazLang, yazLang ? 1 : 0, 1);
62         }
63     }
64     int r = z->send_Z_PDU(apdu, &len);
65     if (r < 0)
66     {
67         z->msg_check_fail("unable to send init request");
68         return TEST_FINISHED;
69     }
70     return TEST_CONTINUE;
71 }
72
73 Zlint_code Zlint_test_init_07::recv_gdu(Zlint *z, Z_GDU *gdu)
74 {
75     if (gdu->which == Z_GDU_Z3950 &&
76         gdu->u.z3950 && gdu->u.z3950->which == Z_APDU_initResponse)
77     {
78         Z_InitResponse *init = gdu->u.z3950->u.initResponse;
79
80         if (ODR_MASK_GET(init->options, Z_Options_negotiationModel))
81         {
82             Z_CharSetandLanguageNegotiation *p =
83                 yaz_get_charneg_record(init->otherInfo);
84
85             if (p) {
86
87                 char *charset=NULL, *lang=NULL;
88                 int selected;
89                 NMEM m = nmem_create();
90
91                 yaz_get_response_charneg(m, p, &charset, &lang,
92                                          &selected);
93                 z->msg_check_ok();
94                 z->msg_check_info("Accepted character set : %s", charset);
95                 z->msg_check_info("Accepted code language : %s", lang ? lang : "none");
96                 z->msg_check_info("Accepted records in ...: %d", selected );
97                 nmem_destroy(m);
98                 return TEST_FINISHED;
99             }
100         }
101         z->msg_check_notapp();
102     }
103     else
104         z->msg_check_fail("did not receive init response as expected");
105     return TEST_FINISHED;
106 }
107
108
109 /*
110  * Local variables:
111  * c-basic-offset: 4
112  * c-file-style: "Stroustrup"
113  * indent-tabs-mode: nil
114  * End:
115  * vim: shiftwidth=4 tabstop=8 expandtab
116  */
117