- *num_langs = pro->num_proposedlanguages;
-
- langs = (char **)nmem_malloc(mem, pro->num_proposedlanguages * sizeof(char *));
-
- for (i=0; i<pro->num_proposedlanguages; i++) {
-
- langs[i] = (char *)nmem_malloc(mem, strlen(pro->proposedlanguages[i])+1);
- memcpy (langs[i], pro->proposedlanguages[i], strlen(pro->proposedlanguages[i])+1);
- }
- }
-
- if(pro->recordsInSelectedCharSets && selected) {
-
- *selected = *pro->recordsInSelectedCharSets;
-
- }
+void yaz_get_proposal_charneg(NMEM mem, Z_CharSetandLanguageNegotiation *p,
+ char ***charsets, int *num_charsets,
+ char ***langs, int *num_langs, int *selected)
+{
+ int i;
+ Z_OriginProposal *pro = p->u.proposal;
+
+ if (num_charsets && charsets)
+ {
+ if (pro->num_proposedCharSets)
+ {
+ *num_charsets = pro->num_proposedCharSets;
+
+ (*charsets) = (char **)
+ nmem_malloc(mem, pro->num_proposedCharSets * sizeof(char *));
+
+ for (i=0; i<pro->num_proposedCharSets; i++)
+ {
+ (*charsets)[i] = 0;
+
+ if (pro->proposedCharSets[i]->which ==
+ Z_OriginProposal_0_private &&
+ pro->proposedCharSets[i]->u.zprivate->which ==
+ Z_PrivateCharacterSet_externallySpecified) {
+
+ Z_External *pext =
+ pro->proposedCharSets[i]->u.zprivate->u.externallySpecified;
+
+ if (pext->which == Z_External_octet) {
+
+ (*charsets)[i] = (char *)
+ nmem_malloc(mem, (1+pext->u.octet_aligned->len) *
+ sizeof(char));
+
+ memcpy ((*charsets)[i], pext->u.octet_aligned->buf,
+ pext->u.octet_aligned->len);
+ (*charsets)[i][pext->u.octet_aligned->len] = 0;
+
+ }
+ }
+ else if (pro->proposedCharSets[i]->which ==
+ Z_OriginProposal_0_iso10646)
+ (*charsets)[i] = set_form (
+ pro->proposedCharSets[i]->u.iso10646->encodingLevel);
+ }
+ }
+ else
+ *num_charsets = 0;
+ }
+
+ if (langs && num_langs)
+ {
+ if (pro->num_proposedlanguages)
+ {
+ *num_langs = pro->num_proposedlanguages;
+
+ (*langs) = (char **)
+ nmem_malloc(mem, pro->num_proposedlanguages * sizeof(char *));
+
+ for (i=0; i<pro->num_proposedlanguages; i++)
+ (*langs)[i] = nmem_strdup(mem, pro->proposedlanguages[i]);
+ }
+ else
+ *num_langs = 0;
+ }
+
+ if(pro->recordsInSelectedCharSets && selected)
+ *selected = *pro->recordsInSelectedCharSets;