+/* Makes a Z39.50-like prompt package with username and password */
+Z_PromptObject1 *makeprompt(struct prog_args *args, ODR odr) {
+ Z_PromptObject1 *p = (Z_PromptObject1 *) odr_malloc(odr, sizeof(*p) );
+ Z_ResponseUnit1 *ru = (Z_ResponseUnit1 *) odr_malloc(odr, sizeof(*ru) );
+
+ p->which=Z_PromptObject1_response;
+ p->u.response = (Z_Response1*) odr_malloc(odr, sizeof(*(p->u.response)) );
+ p->u.response->num=2;
+ p->u.response->elements= (Z_ResponseUnit1 **) odr_malloc(odr,
+ p->u.response->num*sizeof(*(p->u.response->elements)) );
+ /* user id, aka "oclc authorization number" */
+ p->u.response->elements[0] = ru;
+ ru->promptId = (Z_PromptId *) odr_malloc(odr, sizeof(*(ru->promptId) ));
+ ru->promptId->which = Z_PromptId_enumeratedPrompt;
+ ru->promptId->u.enumeratedPrompt = (Z_PromptIdEnumeratedPrompt *)
+ odr_malloc(odr, sizeof(*(ru->promptId->u.enumeratedPrompt) ));
+ ru->promptId->u.enumeratedPrompt->type =
+ odr_intdup(odr,Z_PromptIdEnumeratedPrompt_userId);
+ ru->promptId->u.enumeratedPrompt->suggestedString = 0 ;
+ ru->which = Z_ResponseUnit1_string ;
+ ru->u.string = odr_strdup(odr, args->auth_userid);
+ /* password */
+ ru = (Z_ResponseUnit1 *) odr_malloc(odr, sizeof(*ru) );
+ p->u.response->elements[1] = ru;
+ ru->promptId = (Z_PromptId *) odr_malloc(odr, sizeof(*(ru->promptId) ));
+ ru->promptId->which = Z_PromptId_enumeratedPrompt;
+ ru->promptId->u.enumeratedPrompt = (Z_PromptIdEnumeratedPrompt *)
+ odr_malloc(odr, sizeof(*(ru->promptId->u.enumeratedPrompt) ));
+ ru->promptId->u.enumeratedPrompt->type =
+ odr_intdup(odr,Z_PromptIdEnumeratedPrompt_password);
+ ru->promptId->u.enumeratedPrompt->suggestedString = 0 ;
+ ru->which = Z_ResponseUnit1_string ;
+ ru->u.string = odr_strdup(odr, args->auth_passwd);
+ return p;
+} /* makeprompt */
+
+ILL_Extension *makepromptextension(struct prog_args *args, ODR odr) {
+ ODR odr_ext = odr_createmem(ODR_ENCODE);
+ ODR odr_prt = odr_createmem(ODR_PRINT);
+ ILL_Extension *e = (ILL_Extension *) odr_malloc(odr, sizeof(*e));
+ Z_PromptObject1 *p = makeprompt(args,odr_ext);
+ char * buf;
+ int siz;
+ Z_External *ext = (Z_External *) odr_malloc(odr, sizeof(*ext));
+ ext->direct_reference = odr_getoidbystr(odr,"1.2.840.10003.8.1");
+ ext->indirect_reference=0;
+ ext->descriptor=0;
+ ext->which=Z_External_single;
+ if ( ! z_PromptObject1(odr_ext, &p, 0,0 ) ) {
+ yaz_log(YLOG_FATAL,"Encoding of z_PromptObject1 failed ");
+ exit (6);
+ }
+
+ printf ("Prompt: \n"); /*!*/
+ z_PromptObject1(odr_prt, &p, 0,0 ); /*!*/
+
+ buf= odr_getbuf(odr_ext,&siz,0);
+ ext->u.single_ASN1_type=(Odr_any *)
+ odr_malloc(odr,sizeof(*ext->u.single_ASN1_type));
+ ext->u.single_ASN1_type->buf= (unsigned char *) odr_malloc(odr, siz);
+ memcpy(ext->u.single_ASN1_type->buf,buf, siz );
+ ext->u.single_ASN1_type->len = ext->u.single_ASN1_type->size = siz;
+ odr_reset(odr_ext);
+ odr_reset(odr_prt); /*!*/
+
+ e->identifier = odr_intdup(odr,1);
+ e->critical = odr_intdup(odr,0);
+ e->item = (Odr_any *) odr_malloc(odr,sizeof(*e->item));
+ if ( ! z_External(odr_ext, &ext,0,0) ) {
+ yaz_log(YLOG_FATAL,"Encoding of z_External failed ");
+ exit (6);
+ }
+ printf("External: \n");
+ z_External(odr_prt, &ext,0,0); /*!*/
+ buf= odr_getbuf(odr_ext,&siz,0);
+ e->item->buf= (unsigned char *) odr_malloc(odr, siz);
+ memcpy(e->item->buf,buf, siz );
+ e->item->len = e->item->size = siz;
+
+ odr_destroy(odr_prt);
+ odr_destroy(odr_ext);
+ return e;
+} /* makepromptextension */
+
+ILL_Extension *makeoclcextension(struct prog_args *args, ODR odr) {
+ /* The oclc extension is required, but only contains optional */
+ /* fields. Here we just null them all out */
+ ODR odr_ext = odr_createmem(ODR_ENCODE);
+ ODR odr_prt = odr_createmem(ODR_PRINT);
+ ILL_Extension *e = (ILL_Extension *) odr_malloc(odr, sizeof(*e));
+ ILL_OCLCILLRequestExtension *oc = (ILL_OCLCILLRequestExtension *)
+ odr_malloc(odr_ext, sizeof(*oc));
+ char * buf;
+ int siz;
+ Z_External *ext = (Z_External *) odr_malloc(odr, sizeof(*ext));
+ oc->clientDepartment = 0;
+ oc->paymentMethod = 0;
+ oc->uniformTitle = 0;
+ oc->dissertation = 0;
+ oc->issueNumber = 0;
+ oc->volume = 0;
+ oc->affiliations = 0;
+ oc->source = 0;
+ ext->direct_reference = odr_getoidbystr(odr,"1.0.10161.13.2");
+ ext->indirect_reference=0;
+ ext->descriptor=0;
+ ext->which=Z_External_single;
+ if ( ! ill_OCLCILLRequestExtension(odr_ext, &oc, 0,0 ) ) {
+ yaz_log(YLOG_FATAL,"Encoding of ill_OCLCILLRequestExtension failed ");
+ exit (6);
+ }
+
+ printf ("OCLC: \n"); /*!*/
+ ill_OCLCILLRequestExtension(odr_prt, &oc, 0,0 ); /*!*/
+
+ buf= odr_getbuf(odr_ext,&siz,0);
+ ext->u.single_ASN1_type = (Odr_any*)
+ odr_malloc(odr,sizeof(*ext->u.single_ASN1_type));
+ ext->u.single_ASN1_type->buf = (unsigned char *) odr_malloc(odr, siz);
+ memcpy(ext->u.single_ASN1_type->buf,buf, siz );
+ ext->u.single_ASN1_type->len = ext->u.single_ASN1_type->size = siz;
+ odr_reset(odr_ext);
+ odr_reset(odr_prt); /*!*/
+
+ e->identifier = odr_intdup(odr,1);
+ e->critical = odr_intdup(odr,0);
+ e->item = (Odr_any *) odr_malloc(odr,sizeof(*e->item));
+ if ( ! z_External(odr_ext, &ext,0,0) ) {
+ yaz_log(YLOG_FATAL,"Encoding of z_External failed ");
+ exit (6);
+ }
+ printf("External: \n");
+ z_External(odr_prt, &ext,0,0); /*!*/
+ buf= odr_getbuf(odr_ext,&siz,0);
+ e->item->buf= (unsigned char *) odr_malloc(odr, siz);
+ memcpy(e->item->buf, buf, siz);
+ e->item->len = e->item->size = siz;
+
+ odr_destroy(odr_prt);
+ odr_destroy(odr_ext);
+ return e;
+
+} /* makeoclcextension */
+
+ILL_APDU *createrequest( struct prog_args *args, ODR odr) {