Happy new year
[yazpp-moved-to-github.git] / include / yazpp / z-assoc.h
1 /* This file is part of the yazpp toolkit.
2  * Copyright (C) 1998-2012 Index Data and Mike Taylor
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Index Data nor the names of its contributors
13  *       may be used to endorse or promote products derived from this
14  *       software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #ifndef YAZ_Z_ASSOC_INCLUDED
29 #define YAZ_Z_ASSOC_INCLUDED
30
31 #include <yaz/srw.h>
32 #include <yaz/proto.h>
33 #include <yaz/odr.h>
34 #include <yazpp/pdu-observer.h>
35
36 namespace yazpp_1 {
37 /** Z39.50 Assocation.
38     This object implements the client - and server role of a generic
39     Z39.50 Association.
40 */
41 class YAZ_EXPORT Z_Assoc : public IPDU_Observer {
42  public:
43     /// Create object using the PDU Observer specified
44     Z_Assoc(IPDU_Observable *the_PDU_Observable);
45     /// Destroy assocation and close PDU Observer
46     virtual ~Z_Assoc();
47     /// Receive PDU
48     void recv_PDU(const char *buf, int len);
49     /// Connect notification
50     virtual void connectNotify() = 0;
51     /// Failure notification
52     virtual void failNotify() = 0;
53     /// Timeout notification
54     virtual void timeoutNotify() = 0;
55     /// Timeout specify
56     void timeout(int timeout);
57     /// Begin Z39.50 client role
58     int client(const char *addr);
59     /// Begin Z39.50 server role
60     int server(const char *addr);
61     /// Close connection
62     void close();
63     /// Decode Z39.50 PDU.
64     Z_GDU *decode_GDU(const char *buf, int len);
65     /// Encode Z39.50 PDU.
66     int encode_GDU(Z_GDU *apdu, char **buf, int *len);
67     /// Send Z39.50 PDU
68     int send_Z_PDU(Z_APDU *apdu, int *len);
69     int send_GDU(Z_GDU *apdu, int *len);
70     /// Receive Z39.50 PDU
71     virtual void recv_GDU(Z_GDU *apdu, int len) = 0;
72     /// Create Z39.50 PDU with reasonable defaults
73     Z_APDU *create_Z_PDU(int type);
74     /// Request Alloc
75     ODR odr_encode ();
76     ODR odr_decode ();
77     ODR odr_print ();
78
79     void set_APDU_log(const char *fname);
80     const char *get_APDU_log();
81
82     /// OtherInformation
83     void get_otherInfoAPDU(Z_APDU *apdu, Z_OtherInformation ***oip);
84     Z_OtherInformationUnit *update_otherInformation (
85         Z_OtherInformation **otherInformationP, int createFlag,
86         const Odr_oid *oid, int categoryValue, int deleteFlag);
87     void set_otherInformationString(
88         Z_APDU *apdu,
89         const Odr_oid *oid, int categoryValue, const char *str);
90     void set_otherInformationString (
91         Z_OtherInformation **otherInformationP,
92         const Odr_oid *oid, int categoryValue,
93         const char *str);
94     Z_ReferenceId *getRefID(char* str);
95     Z_ReferenceId **get_referenceIdP(Z_APDU *apdu);
96     void transfer_referenceId(Z_APDU *from, Z_APDU *to);
97
98     const char *get_hostname();
99
100     int set_APDU_yazlog(int v);
101
102  private:
103     static int yaz_init_flag;
104     static int yaz_init_func();
105     IPDU_Observable *m_PDU_Observable;
106     ODR m_odr_in;
107     ODR m_odr_out;
108     ODR m_odr_print;
109     int m_log;
110     FILE *m_APDU_file;
111     char *m_APDU_fname;
112     char *m_hostname;
113     int m_APDU_yazlog;
114 };
115 };
116
117 #endif
118 /*
119  * Local variables:
120  * c-basic-offset: 4
121  * c-file-style: "Stroustrup"
122  * indent-tabs-mode: nil
123  * End:
124  * vim: shiftwidth=4 tabstop=8 expandtab
125  */
126