Fixed Library add's for libyaz_la, libyaz_icu.la, libyaz_server.la.
[yaz-moved-to-github.git] / src / zgdu.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2008 Index Data
3  * See the file LICENSE for details.
4  */
5
6 /**
7  * \file zgdu.c
8  * \brief Implements HTTP and Z39.50 encoding and decoding.
9  */
10
11 #include <string.h>
12 #include <yaz/odr.h>
13 #include <yaz/zgdu.h>
14
15 int z_GDU (ODR o, Z_GDU **p, int opt, const char *name)
16 {
17     if (o->direction == ODR_DECODE) {
18         *p = (Z_GDU *) odr_malloc(o, sizeof(**p));
19         if (o->size > 10 && !memcmp(o->buf, "HTTP/", 5))
20         {
21             (*p)->which = Z_GDU_HTTP_Response;
22             return yaz_decode_http_response(o, &(*p)->u.HTTP_Response);
23
24         }
25         else if (o->size > 5 &&
26             o->buf[0] >= 0x20 && o->buf[0] < 0x7f
27             && o->buf[1] >= 0x20 && o->buf[1] < 0x7f
28             && o->buf[2] >= 0x20 && o->buf[2] < 0x7f
29             && o->buf[3] >= 0x20 && o->buf[3] < 0x7f)
30         {
31             (*p)->which = Z_GDU_HTTP_Request;
32             return yaz_decode_http_request(o, &(*p)->u.HTTP_Request);
33         }
34         else
35         {
36             (*p)->which = Z_GDU_Z3950;
37             return z_APDU(o, &(*p)->u.z3950, opt, 0);
38         }
39     }
40     else /* ENCODE or PRINT */
41     {
42         switch((*p)->which)
43         {
44         case Z_GDU_HTTP_Response:
45             return yaz_encode_http_response(o, (*p)->u.HTTP_Response);
46         case Z_GDU_HTTP_Request:
47             return yaz_encode_http_request(o, (*p)->u.HTTP_Request);
48         case Z_GDU_Z3950:
49             return z_APDU(o, &(*p)->u.z3950, opt, 0);
50         }
51     }
52     return 0;
53 }
54
55 /*
56  * Local variables:
57  * c-basic-offset: 4
58  * indent-tabs-mode: nil
59  * End:
60  * vim: shiftwidth=4 tabstop=8 expandtab
61  */
62