summaryrefslogtreecommitdiffstats
path: root/ircxmpp.h
blob: da03aa52cc2dd69f830ad4f47171feecb2bda040 (plain) (blame)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <libircclient.h>
enum irc_numeric { /* numerics from rfc 1459 */
	ERR_NOSUCHNICK = 401,
	ERR_NOSUCHSERVER,
	ERR_NOSUCHCHANNEL,
	ERR_CANNOTSENDTOCHAN,
	ERR_TOOMANYCHANNELS,
	ERR_WASNOSUCHNICK,
	ERR_TOOMANYTARGETS,
	ERR_NOORIGIN = 409,
	ERR_NORECIPIENT = 411,
	ERR_NOTEXTTOSEND,
	ERR_NOTOPLEVEL,
	ERR_WILDTOPLEVEL,
	ERR_UNKNOWNCOMMAND = 421,
	ERR_NOMOTD,
	ERR_NOADMININFO,
	ERR_FILEERROR,
	ERR_NONICKNAMEGIVEN = 431,
	ERR_ERRONEUSNICKNAME,
	ERR_NICKNAMEINUSE,
	ERR_NICKCOLLISION = 436,
	ERR_USERNOTINCHANNEL = 441,
	ERR_NOTONCHANNEL,
	ERR_USERONCHANNEL,
	ERR_NOLOGIN,
	ERR_SUMMONDISABLED,
	ERR_USERDISABLED,
	ERR_NOTREGISTERED = 451,
	ERR_NEEDMOREPARAMS = 461,
	ERR_ALREADYREGISTERED,
	ERR_NOPERMFORHOST,
	ERR_PASSWDMISMATCH,
	ERR_YOUREBANNEDCREEP,
	ERR_KEYSET = 467,
	ERR_CHANNELISFULL = 471,
	ERR_UNKNOWNMODE,
	ERR_INVITEONLYCHAN,
	ERR_BANNEDFROMCHAN,
	ERR_BADCHANNELKEY,
	ERR_NOPRIVILEGES = 481,
	ERR_CHANOPRIVSNEEDED,
	ERR_CANTKILLSERVER,
	ERR_NOOPERHOST = 491,
	ERR_UMODEUNKNOWNFLAG = 501,
	ERR_USERSDONTMATCH,
	RPL_NONE = 300,
	RPL_AWAY,
	RPL_USERHOST,
	RPL_ISON,
	RPL_UNAWAY,
	RPL_NOWAWAY,
	RPL_WHOISUSER = 311,
	RPL_WHOISSERVER,
	RPL_WHOISOPERATOR,
	RPL_WHOISIDLE = 317,
	RPL_ENDOFWHOIS,
	RPL_WHOISCHANNELS,
	RPL_WHOWASUSER = 314,
	RPL_ENDOFWHOWAS = 369,
	RPL_LISTSTART = 321,
	RPL_LIST,
	RPL_LISTEND,
	RPL_CHANNELMODEIS,
	RPL_NOTOPIC = 331,
	RPL_TOPIC,
	RPL_INVITING = 341,
	RPL_SUMMONING = 342,
	RPL_VERSION = 351,
	RPL_WHOREPLY = 352,
	RPL_ENDOFWHO = 315,
	RPL_NAMREPLY = 353,
	RPL_ENDOFNAMES = 366,
	RPL_LINKS = 364,
	RPL_ENDOFLINKS,
	RPL_BANLIST = 367,
	RPL_ENDOFBANLIST,
	RPL_INFO = 371,
	RPL_ENDOFINFO = 374,
	RPL_MOTDSTART,
	RPL_MOTD = 372,
	RPL_ENDOFMOTD = 376,
	RPL_YOUREOPER = 381,
	RPL_REHASHING = 382,
	RPL_TIME = 391,
	RPL_USERSSTART,
	RPL_USERS,
	RPL_ENDOFUSERS,
	RPL_NOUSERS,
	RPL_TRACELINK = 200,
	RPL_TRACECONNECTING,
	RPL_TRACEHANDSHAKE,
	RPL_TRACEUNKNOWN,
	RPL_TRACEOPERATOR,
	RPL_TRACEUSER,
	RPL_TRACESERVER,
	RPL_TRACENEWTYPE = 208,
	RPL_TRACELOG = 261,
	RPL_STATSLINKINFO = 211,
	RPL_STATSCOMMANDS,
	RPL_STATSCLINE,
	RPL_STATSNLINE,
	RPL_STATSILINE,
	RPL_STATSKLINE,
	RPL_STATSYLINE = 218,
	RPL_ENDOFSTATS,
	RPL_STATSLLINE = 241,
	RPL_STATSUPTIME,
	RPL_STATSOLINE,
	RPL_STATSHLINE,
	RPL_UMODEIS = 221,
	RPL_LUSERCLIENT = 251,
	RPL_LUSEROP,
	RPL_LUSERUNKNOWN,
	RPL_LUSERCHANNELS,
	RPL_LUSERME,
	RPL_ADMINME,
	RPL_ADMINLOC1,
	RPL_ADMINLOC2,
	RPL_ADMINEMAIL,
	RPL_TRACECLASS = 209,
	RPL_SERVICEINFO = 231,
	RPL_SERVICE = 233,
	RPL_SERVLISTEND = 235,
	RPL_WHOISCHANOP = 316,
	RPL_CLOSING = 362,
	RPL_INFOSTART = 373,
	ERR_YOUWILLBEBANNED = 466,
	ERR_NOSERVICEHOST = 492,
	RPL_STATSQLINE = 217,
	RPL_ENDOFSERVICES = 232,
	RPL_SERVLIST = 234,
	RPL_KILLDONE = 361,
	RPL_CLOSEEND = 363,
	RPL_MYPORTIS = 384,
	ERR_BADCHANMASK = 476
};
enum side {
	IRC,
	XMPP
};
struct bridge {	// xmpp connection is the same for every user, only IRC connection differs
	struct ircxmpp * ircxmpp;
	struct bridge * next;
	struct bridge * prev;
	char * identifier; /* jid if side is XMPP or nickname if side is IRC */
	irc_session_t * irc;
	xmpp_conn_t * conn; /* isti xmpp_ctx_t ima lahko več connov */
	enum side side; /* which side is the real user */
	size_t messages_length;
	char ** messages;
};
struct ircxmpp {
	struct bridge * bridges;
	irc_session_t * irc;
	char * ircnick;
	char * irchost;
	xmpp_ctx_t * ctx;
	xmpp_conn_t * conn;
	char * jid;
	char * password;
	char * hostname;
	int port;
	char * channel;
	char * muc;
	char * channel_password;
};
void free_bridge (struct bridge **, const char *);
void free_bridges (struct bridge **);
struct bridge ** find_bridge (struct bridge **, const char *, enum side);
void jid2ircnick (char *);
void jid2ircuser (char *);
void bridge_forward (const char *, const char *, struct ircxmpp *, enum side);
int message_handler (xmpp_conn_t * const, xmpp_stanza_t * const, void * const);
int presence_handler (xmpp_conn_t * const, xmpp_stanza_t * const, void * const);
void conn_handler (xmpp_conn_t * const, const xmpp_conn_event_t, const int,
		xmpp_stream_error_t * const, void * const);
void conn_handler_bridge (xmpp_conn_t * const, const xmpp_conn_event_t, const int,
		xmpp_stream_error_t * const, void * const);
// IRC
void dump_event (irc_session_t *, const char *, const char *, const char **, unsigned);
void event_connect (irc_session_t *, const char *, const char *, const char **, unsigned);
void event_connect_control (irc_session_t *, const char *, const char *, const char **, unsigned);
void event_privmsg (irc_session_t *, const char *, const char *, const char **, unsigned);
void event_partquit_control (irc_session_t *, const char *, const char *, const char **, unsigned);
void event_join_control (irc_session_t *, const char *, const char *, const char **, unsigned);
void event_channel_control (irc_session_t *, const char *, const char *, const char **, unsigned);
void event_nick_control(irc_session_t *, const char *, const char *, const char **, unsigned);
void event_topic_control (irc_session_t *, const char *, const char *, const char **, unsigned);
void event_numeric (irc_session_t *, unsigned int, const char *, const char **, unsigned);
void event_numeric_control (irc_session_t *, unsigned int, const char *, const char **, unsigned);
int irc_run_once (struct bridge *);
void init_irc (struct bridge *);
void init_irc_control (struct ircxmpp *);
// /IRC
int main (void);