-
Notifications
You must be signed in to change notification settings - Fork 4
/
connection.hh
77 lines (58 loc) · 2.29 KB
/
connection.hh
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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include <strophe.h>
#include "xmpp/ns.hh"
#include "strophe.hh"
#include "config.hh"
namespace weechat {
class account;
class connection
{
private:
libstrophe::connection m_conn;
enum class event {
connect = XMPP_CONN_CONNECT,
raw_connect = XMPP_CONN_RAW_CONNECT,
disconnect = XMPP_CONN_DISCONNECT,
fail = XMPP_CONN_FAIL,
};
public:
weechat::account &account;
connection(weechat::account &acc, libstrophe::context &ctx)
: m_conn(ctx), account(acc) {
}
inline operator xmpp_conn_t*() {
return m_conn;
}
inline auto send(xmpp_stanza_t *stanza) {
m_conn.send(stanza);
}
inline auto context() {
return m_conn.get_context();
}
inline bool connect_client(const char* altdomain, unsigned short altport, xmpp_conn_handler callback) {
return m_conn.connect_client(altdomain, altport, callback, this) == XMPP_EOK;
}
inline auto handler_add(const char *name, const char *type, xmpp_handler callback) {
return m_conn.handler_add(callback, nullptr, name, type, this);
}
template <typename X, std::enable_if_t<std::is_base_of<xmlns,X>::value, int> = 0>
inline auto handler_add(const char *name, const char *type, xmpp_handler callback) {
return m_conn.handler_add(callback, X(), name, type, this);
}
static void init();
int connect(std::string jid, std::string password, weechat::tls_policy tls);
void process(xmpp_ctx_t *context, const unsigned long timeout);
bool version_handler(xmpp_stanza_t *stanza);
bool presence_handler(xmpp_stanza_t *stanza);
bool message_handler(xmpp_stanza_t *stanza);
bool iq_handler(xmpp_stanza_t *stanza);
bool conn_handler(event status, int error, xmpp_stream_error_t *stream_error);
xmpp_stanza_t *get_caps(xmpp_stanza_t *reply, char **hash);
};
}