fbdd367dfd841cfb590d7ce56a2413fc09d69ff9
[metaproxy-moved-to-github.git] / src / util.hpp
1 /* $Id: util.hpp,v 1.19 2006-09-29 08:42:47 marc Exp $
2    Copyright (c) 2005-2006, Index Data.
3
4    See the LICENSE file for details
5  */
6
7 #ifndef YP2_UTIL_HPP
8 #define YP2_UTIL_HPP
9
10 #include "package.hpp"
11
12 #include <yaz/z-core.h>
13
14 #include <boost/utility.hpp>
15 #include <boost/scoped_ptr.hpp>
16
17 #include <string>
18 #include <list>
19 #include <vector>
20 #include <sstream>
21 #include <string>
22
23
24 namespace metaproxy_1 {
25     namespace util  {
26
27         
28         template<typename T> 
29         std::string to_string(const T& t)
30         {
31             std::ostringstream o;
32             if(o << t)
33                 return o.str();    
34             return std::string();
35         };
36
37         std::string http_header_value(const Z_HTTP_Header* header, 
38                                                const std::string name);
39
40         int memcmp2(const void *buf1, int len1, const void *buf2, int len2);
41
42         std::string database_name_normalize(const std::string &s);
43
44         bool pqf(ODR odr, Z_APDU *apdu, const std::string &q);
45
46         std::string zQueryToString(Z_Query *query);
47
48         Z_ReferenceId **get_referenceId(const Z_APDU *apdu);
49
50         void transfer_referenceId(ODR odr, const Z_APDU *src, Z_APDU *dst);
51
52         Z_APDU *create_APDU(ODR odr, int type, const Z_APDU *in_apdu);
53
54         bool set_databases_from_zurl(ODR odr, std::string zurl,
55                                      int *db_num, char ***db_strings);
56
57         void split_zurl(std::string zurl, std::string &host,
58                         std::list<std::string> &db);
59         
60         void get_vhost_otherinfo(Z_OtherInformation *otherInformation,
61                                  std::list<std::string> &vhosts);
62         
63         int remove_vhost_otherinfo(Z_OtherInformation **otherInformation,
64                                    std::list<std::string> &vhosts);
65
66         void set_vhost_otherinfo(Z_OtherInformation **otherInformation,
67                                  ODR odr,
68                                  const std::list<std::string> &vhosts);
69
70         int get_or_remove_vhost_otherinfo(
71             Z_OtherInformation **otherInformation,
72             bool remove_flag,
73             std::list<std::string> &vhosts);
74
75         void get_init_diagnostics(Z_InitResponse *res,
76                                   int &error_code, std::string &addinfo);
77
78         void get_default_diag(Z_DefaultDiagFormat *r,
79                               int &error_code, std::string &addinfo);
80
81         void piggyback(int smallSetUpperBound,
82                        int largeSetLowerBound,
83                        int mediumSetPresentNumber,
84                        int result_set_size,
85                        int &number_to_present);
86     };
87
88     class odr : public boost::noncopyable {
89     public:
90         odr(int type);
91         odr();
92         ~odr();
93         operator ODR() const;
94         Z_APDU *create_close(const Z_APDU *in_apdu, 
95                              int reason, const char *addinfo);
96         Z_APDU *create_initResponse(const Z_APDU *in_apdu, 
97                                     int error, const char *addinfo);
98         Z_APDU *create_searchResponse(const Z_APDU *in_apdu,
99                                       int error, const char *addinfo);
100         Z_APDU *create_presentResponse(const Z_APDU *in_apdu,
101                                        int error, const char *addinfo);
102         Z_APDU *create_scanResponse(const Z_APDU *in_apdu,
103                                     int error, const char *addinfo);
104         Z_APDU *create_APDU(int type, const Z_APDU *in_apdu);
105
106         Z_GDU *create_HTTP_Response(metaproxy_1::Session &session,
107                                     Z_HTTP_Request *req, int code);
108     private:
109         ODR m_odr;
110     };
111
112     class PlainFile {
113         class Rep;
114         boost::scoped_ptr<Rep> m_p;
115     public:
116         PlainFile();
117         ~PlainFile();
118         bool open(const std::string &fname);
119         bool getline(std::vector<std::string> &args);
120     };
121 }
122 #endif
123 /*
124  * Local variables:
125  * c-basic-offset: 4
126  * indent-tabs-mode: nil
127  * c-file-style: "stroustrup"
128  * End:
129  * vim: shiftwidth=4 tabstop=8 expandtab
130  */