YAZ  5.34.0
zgdu.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 
13 #include <string.h>
14 #include "odr-priv.h"
15 #include <yaz/zgdu.h>
16 
17 int z_GDU(ODR o, Z_GDU **p, int opt, const char *name)
18 {
19  const char *buf = o->op->buf;
20  if (o->direction == ODR_DECODE) {
21  *p = (Z_GDU *) odr_malloc(o, sizeof(**p));
22  if (o->op->size > 10 && !memcmp(buf, "HTTP/", 5))
23  {
24  (*p)->which = Z_GDU_HTTP_Response;
25  return yaz_decode_http_response(o, &(*p)->u.HTTP_Response);
26 
27  }
28  else if (o->op->size > 5 &&
29  buf[0] >= 0x20 && buf[0] < 0x7f
30  && buf[1] >= 0x20 && buf[1] < 0x7f
31  && buf[2] >= 0x20 && buf[2] < 0x7f
32  && buf[3] >= 0x20 && buf[3] < 0x7f)
33  {
34  (*p)->which = Z_GDU_HTTP_Request;
35  return yaz_decode_http_request(o, &(*p)->u.HTTP_Request);
36  }
37  else
38  {
39  (*p)->which = Z_GDU_Z3950;
40  return z_APDU(o, &(*p)->u.z3950, opt, 0);
41  }
42  }
43  else /* ENCODE or PRINT */
44  {
45  switch((*p)->which)
46  {
48  return yaz_encode_http_response(o, (*p)->u.HTTP_Response);
49  case Z_GDU_HTTP_Request:
50  return yaz_encode_http_request(o, (*p)->u.HTTP_Request);
51  case Z_GDU_Z3950:
52  return z_APDU(o, &(*p)->u.z3950, opt, 0);
53  }
54  }
55  return 0;
56 }
57 
58 /*
59  * Local variables:
60  * c-basic-offset: 4
61  * c-file-style: "Stroustrup"
62  * indent-tabs-mode: nil
63  * End:
64  * vim: shiftwidth=4 tabstop=8 expandtab
65  */
66 
int yaz_decode_http_request(ODR o, Z_HTTP_Request **hr_p)
Definition: http.c:505
int yaz_encode_http_request(ODR o, Z_HTTP_Request *hr)
Definition: http.c:616
int yaz_decode_http_response(ODR o, Z_HTTP_Response **hr_p)
Definition: http.c:472
int yaz_encode_http_response(ODR o, Z_HTTP_Response *hr)
Definition: http.c:580
int opt
Definition: initopt.c:19
char * name
Definition: initopt.c:18
Internal ODR definitions.
#define ODR_DECODE
Definition: odr.h:95
void * odr_malloc(ODR o, size_t size)
Definition: odr_mem.c:31
char * buf
Definition: odr-priv.h:84
int size
Definition: odr-priv.h:88
Definition: zgdu.h:68
Definition: odr.h:125
struct Odr_private * op
Definition: odr.h:132
int direction
Definition: odr.h:126
int z_APDU(ODR o, Z_APDU **p, int opt, const char *name)
Definition: z-core.c:12
int z_GDU(ODR o, Z_GDU **p, int opt, const char *name)
Definition: zgdu.c:17
Header for the Z_GDU (HTTP or Z39.50 package)
#define Z_GDU_Z3950
Definition: zgdu.h:65
#define Z_GDU_HTTP_Response
Definition: zgdu.h:67
#define Z_GDU_HTTP_Request
Definition: zgdu.h:66