2 $ $Id: charneg.c,v 1.1 2002-05-18 09:41:11 oleg Exp $
3 * Helper functions for Character Set and Language Negotiation - 3
8 #include <yaz/z-charneg.h>
9 #include <yaz/charneg.h>
11 static Z_External* z_ext_record2(ODR o, int oid_class, int oid_value,
12 const char *buf, int len)
17 if (!(p = (Z_External *)odr_malloc(o, sizeof(*p)))) return 0;
20 p->indirect_reference = 0;
22 oid.proto = PROTO_Z3950;
23 oid.oclass = oid_class;
24 oid.value = oid_value;
25 p->direct_reference = odr_oiddup(o, oid_getoidbyent(&oid));
27 p->which = Z_External_octet;
28 if (!(p->u.octet_aligned = (Odr_oct *)odr_malloc(o, sizeof(Odr_oct)))) {
31 if (!(p->u.octet_aligned->buf = (unsigned char *)odr_malloc(o, len))) {
34 p->u.octet_aligned->len = p->u.octet_aligned->size = len;
35 memcpy(p->u.octet_aligned->buf, buf, len);
39 static Z_OriginProposal_0 *z_get_OriginProposal_0(ODR o, const char *charset)
41 Z_OriginProposal_0 *p0 =
42 (Z_OriginProposal_0*)odr_malloc(o, sizeof(*p0));
43 Z_PrivateCharacterSet *pc =
44 (Z_PrivateCharacterSet *)odr_malloc(o, sizeof(*pc));
46 memset(p0, 0, sizeof(*p0));
47 memset(pc, 0, sizeof(*pc));
49 p0->which = Z_OriginProposal_0_private;
52 pc->which = Z_PrivateCharacterSet_externallySpecified;
53 pc->u.externallySpecified =
54 z_ext_record2(o, CLASS_RECSYN, VAL_NOP, charset, (strlen(charset)+1));
58 static Z_OriginProposal *z_get_OriginProposal(ODR o, const char **charsets,
59 int num_charsets, const char **langs, int num_langs)
62 Z_OriginProposal *p = (Z_OriginProposal *) odr_malloc(o, sizeof(*p));
64 memset(p, 0, sizeof(*p));
66 p->num_proposedCharSets = num_charsets;
67 p->num_proposedlanguages = num_langs;
68 p->recordsInSelectedCharSets = (bool_t *)odr_malloc(o, sizeof(bool_t));
69 *p->recordsInSelectedCharSets = 1;
72 (Z_OriginProposal_0**) odr_malloc(o,
73 num_charsets*sizeof(Z_OriginProposal_0*));
75 for (i = 0; i<num_charsets; i++) {
77 p->proposedCharSets[i] =
78 z_get_OriginProposal_0(o, charsets[i]);
81 p->proposedlanguages =
82 (char **) odr_malloc(o, num_langs*sizeof(char *));
84 for (i = 0; i<num_langs; i++) {
85 char *plang = (char *)langs[i];
87 p->proposedlanguages[i] = plang;
93 static Z_CharSetandLanguageNegotiation *z_get_CharSetandLanguageNegotiation(ODR o)
95 Z_CharSetandLanguageNegotiation *p =
96 (Z_CharSetandLanguageNegotiation *) odr_malloc(o, sizeof(*p));
98 memset(p, 0, sizeof(*p));
102 Z_External *yaz_set_charset_and_lang(ODR o, int oid_class, int oid_value,
103 const char **charsets, int num_charsets,
104 const char **langs, int num_langs)
106 Z_External *p = (Z_External *)odr_malloc(o, sizeof(*p));
110 p->indirect_reference = 0;
112 oid.proto = PROTO_Z3950;
113 oid.oclass = oid_class;
114 oid.value = oid_value;
115 p->direct_reference = odr_oiddup(o, oid_getoidbyent(&oid));
117 p->which = Z_External_charSetandLanguageNegotiation;
118 p->u.charNeg3 = z_get_CharSetandLanguageNegotiation(o);
119 p->u.charNeg3->which = Z_CharSetandLanguageNegotiation_proposal;
120 p->u.charNeg3->u.proposal =
121 z_get_OriginProposal(o, charsets, num_charsets,