+Z_External *yaz_set_proposal_charneg(ODR o,
+ const char **charsets, int num_charsets,
+ const char **langs, int num_langs,
+ int selected)
+{
+ Z_External *p = (Z_External *)odr_malloc(o, sizeof(*p));
+ oident oid;
+
+ p->descriptor = 0;
+ p->indirect_reference = 0;
+
+ oid.proto = PROTO_Z3950;
+ oid.oclass = CLASS_NEGOT;
+ oid.value = VAL_CHARNEG3;
+ p->direct_reference = odr_oiddup(o, oid_getoidbyent(&oid));
+
+ p->which = Z_External_charSetandLanguageNegotiation;
+ p->u.charNeg3 = z_get_CharSetandLanguageNegotiation(o);
+ p->u.charNeg3->which = Z_CharSetandLanguageNegotiation_proposal;
+ p->u.charNeg3->u.proposal =
+ z_get_OriginProposal(o, charsets, num_charsets,
+ langs, num_langs, selected);
+
+ return p;
+}
+
+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, CLASS_RECSYN, VAL_NOP, charset, strlen(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;
+}
+
+Z_External *yaz_set_response_charneg(ODR o, const char *charset,
+ const char *lang, int selected)
+{
+ Z_External *p = (Z_External *)odr_malloc(o, sizeof(*p));
+ oident oid;
+
+ p->descriptor = 0;
+ p->indirect_reference = 0;
+
+ oid.proto = PROTO_Z3950;
+ oid.oclass = CLASS_NEGOT;
+ oid.value = VAL_CHARNEG3;
+ p->direct_reference = odr_oiddup(o, oid_getoidbyent(&oid));
+
+ p->which = Z_External_charSetandLanguageNegotiation;
+ p->u.charNeg3 = z_get_CharSetandLanguageNegotiation(o);
+ p->u.charNeg3->which = Z_CharSetandLanguageNegotiation_response;
+ p->u.charNeg3->u.response = z_get_TargetResponse(o, charset, lang, selected);
+
+ return p;