added first files for SRU to Z3950 filter module, much more work needed
[metaproxy-moved-to-github.git] / src / filter_sru_to_z3950.cpp
1 /* $Id: filter_sru_to_z3950.cpp,v 1.1 2006-09-13 10:43:24 marc Exp $
2    Copyright (c) 2005-2006, Index Data.
3
4    See the LICENSE file for details
5  */
6
7 #include "config.hpp"
8
9 #include "filter.hpp"
10 #include "package.hpp"
11
12 #include <boost/thread/mutex.hpp>
13
14 #include "util.hpp"
15 #include "filter_sru_to_z3950.hpp"
16
17 #include <yaz/zgdu.h>
18
19 namespace mp = metaproxy_1;
20 namespace yf = mp::filter;
21
22 namespace metaproxy_1 {
23     namespace filter {
24         class SRUtoZ3950::Rep {
25             friend class SRUtoZ3950;
26             //int dummy;
27         };
28     }
29 }
30
31 yf::SRUtoZ3950::SRUtoZ3950() : m_p(new Rep)
32 {
33     //m_p->dummy = 1;
34 }
35
36 yf::SRUtoZ3950::~SRUtoZ3950()
37 {  // must have a destructor because of boost::scoped_ptr
38 }
39
40 void yf::SRUtoZ3950::process(mp::Package &package) const
41 {
42     Z_GDU *zgdu_req = package.request().get();
43
44     // ignoring all non HTTP_Request packages
45     if (!zgdu_req || !(zgdu_req->which == Z_GDU_HTTP_Request)){
46         package.move();
47         return;
48     }
49     
50     // only working on  HTTP_Request packages now
51     Z_HTTP_Request* http_req =  zgdu_req->u.HTTP_Request;
52
53     // TODO: SRU package checking and translation to Z3950 package
54
55     // sending Z3950 package through pipeline
56     package.move();
57
58
59     // TODO: Z3950 response parsing and translation to SRU package
60     //Z_HTTP_Response* http_res = 0;
61
62
63     Z_GDU *zgdu_res = 0; 
64     metaproxy_1::odr odr; 
65     zgdu_res 
66        = odr.create_HTTP_Response(package.session(), 
67                                   zgdu_req->u.HTTP_Request, 200);
68
69     //zgdu_res->u.HTTP_Response->content_len = message.str().size();
70     //zgdu_res->u.HTTP_Response->content_buf 
71     //    = (char*) odr_malloc(odr, zgdu_res->u.HTTP_Response->content_len);
72
73     //strncpy(zgdu_res->u.HTTP_Response->content_buf, 
74     //        message.str().c_str(),  zgdu_res->u.HTTP_Response->content_len);
75     
76         // z_HTTP_header_add(o, &hres->headers,
77         //            "Content-Type", content_type.c_str());
78     package.response() = zgdu_res;
79
80 }
81
82 static mp::filter::Base* filter_creator()
83 {
84     return new mp::filter::SRUtoZ3950;
85 }
86
87 extern "C" {
88     struct metaproxy_1_filter_struct metaproxy_1_filter_sru_to_z3950 = {
89         0,
90         "SRUtoZ3950",
91         filter_creator
92     };
93 }
94
95
96 /*
97  * Local variables:
98  * c-basic-offset: 4
99  * indent-tabs-mode: nil
100  * c-file-style: "stroustrup"
101  * End:
102  * vim: shiftwidth=4 tabstop=8 expandtab
103  */