summaryrefslogtreecommitdiffstats
path: root/bindings/_common/Xcap.h
blob: 59376d6a025e85ce8ee0e1010fbc06dfd09c962b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
#ifndef TINYWRAP_XCAP_H
#define TINYWRAP_XCAP_H

#include "tinyxcap.h"

class XcapStack;

typedef tsk_list_t twrap_xcap_steps_L_t;

//
//	XcapSelector
//
class XcapSelector
{
public:
    XcapSelector(XcapStack* stack);
    virtual ~XcapSelector();

public: /* API functions */
    XcapSelector* setAUID(const char* auid);
    XcapSelector* setName(const char* qname);
    XcapSelector* setAttribute(const char* qname, const char* att_qname, const char* att_value);
    XcapSelector* setPos(const char* qname, unsigned pos);
    XcapSelector* setPosAttribute(const char* qname, unsigned pos, const char* att_qname, const char* att_value);
    XcapSelector* setNamespace(const char* prefix, const char* value);

    char* getString();// %newobject
    void reset();

private:
    txcap_stack_handle_t* stack_handle;
    char* auid;
    twrap_xcap_steps_L_t* steps;
};

//
//	XcapMessage
//
class XcapMessage
{
public:
    XcapMessage();
#if !defined(SWIG)
    XcapMessage(const thttp_message_t *httpmessage);
#endif
    virtual ~XcapMessage();

    short getCode() const;
    const char* getPhrase() const;

    char* getXcapHeaderValue(const char* name, unsigned index = 0);
    char* getXcapHeaderParamValue(const char* name, const char* param, unsigned index = 0);
    unsigned getXcapContentLength();
    unsigned getXcapContent(void* output, unsigned maxsize);

private:
    const thttp_message_t *httpmessage;
};

//
//	XcapEvent
//
class XcapEvent
{
public:
#if !defined(SWIG)
    XcapEvent(const thttp_event_t *httpevent);
#endif
    virtual ~XcapEvent();
    thttp_event_type_t getType();
    const XcapMessage* getXcapMessage() const;

private:
    const thttp_event_t *httpevent;
    const XcapMessage* httpmessage;
};


//
//	XcapCallback
//
class XcapCallback
{
public:
    XcapCallback();
    virtual ~XcapCallback();

    virtual int onEvent(const XcapEvent* e)const {
        return -1;
    }
};


//
//	XcapStack
//
class XcapStack
{
public:
    XcapStack(XcapCallback* callback, const char* xui, const char* password, const char* xcap_root);
    virtual ~XcapStack();

public: /* API functions */
    bool registerAUID(const char* id, const char* mime_type, const char* ns, const char* document_name, bool is_global);
    bool start();
    bool setCredentials(const char* xui, const char* password);
    bool setXcapRoot(const char* xcap_root);
    bool setLocalIP(const char* ip);
    bool setLocalPort(unsigned port);
    bool addHeader(const char* name, const char* value);
    bool removeHeader(const char* name);
    bool setTimeout(unsigned timeout);

    bool getDocument(const char* url);
    bool getElement(const char* url);
    bool getAttribute(const char* url);

    bool deleteDocument(const char* url);
    bool deleteElement(const char* url);
    bool deleteAttribute(const char* url);

    bool putDocument(const char* url, const void* payload, unsigned len, const char* contentType);
    bool putElement(const char* url, const void* payload, unsigned len);
    bool putAttribute(const char* url, const void* payload, unsigned len);

    bool stop();

public: /* Public helper function */
#if !defined(SWIG)
    txcap_stack_handle_t* getHandle() {
        return this->handle;
    }
    XcapCallback* getCallback()const {
        return this->callback;
    }
#endif

private:
    txcap_stack_handle_t* handle;
    XcapCallback* callback;

    static unsigned count;
};


#endif /* TINYWRAP_XCAP_H */
OpenPOWER on IntegriCloud