IRC client framework (wrapper around libircclient library).
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

libirc_events.h 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /*
  2. * Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
  3. *
  4. * This library is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  12. * License for more details.
  13. */
  14. #ifndef INCLUDE_IRC_EVENTS_H
  15. #define INCLUDE_IRC_EVENTS_H
  16. #ifndef IN_INCLUDE_LIBIRC_H
  17. #error This file should not be included directly, include just libircclient.h
  18. #endif
  19. /*!
  20. * \fn typedef void (*irc_event_callback_t) (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
  21. * \brief A most common event callback
  22. *
  23. * \param session the session, which generates an event
  24. * \param event the text name of the event. Useful in case you use a single
  25. * event handler for several events simultaneously.
  26. * \param origin the originator of the event. See the note below.
  27. * \param params a list of event params. Depending on the event nature, it
  28. * could have zero or more params. The actual number of params
  29. * is specified in count. None of the params can be NULL, but
  30. * 'params' pointer itself could be NULL for some events.
  31. * \param count the total number of params supplied.
  32. *
  33. * Every event generates a callback. This callback is generated by most events.
  34. * Depending on the event nature, it can provide zero or more params. For each
  35. * event, the number of provided params is fixed, and their meaning is
  36. * described.
  37. *
  38. * Every event has origin, though the \a origin variable may be NULL, which
  39. * means that event origin is unknown. The origin usually looks like
  40. * nick!host\@ircserver, i.e. like tim!home\@irc.krasnogorsk.ru. Such origins
  41. * can not be used in IRC commands, and need to be stripped (i.e. host and
  42. * server part should be cut off) before using. This can be done either
  43. * explicitly, by calling irc_target_get_nick(), or implicitly for all the
  44. * events - by setting the #LIBIRC_OPTION_STRIPNICKS option with irc_option_set().
  45. *
  46. * \ingroup events
  47. */
  48. typedef void (*irc_event_callback_t) (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
  49. /*!
  50. * \fn typedef void (*irc_eventcode_callback_t) (irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count)
  51. * \brief A numeric event callback
  52. *
  53. * \param session the session, which generates an event
  54. * \param event the numeric code of the event. Useful in case you use a
  55. * single event handler for several events simultaneously.
  56. * \param origin the originator of the event. See the note below.
  57. * \param params a list of event params. Depending on the event nature, it
  58. * could have zero or more params. The actual number of params
  59. * is specified in count. None of the params can be NULL, but
  60. * 'params' pointer itself could be NULL for some events.
  61. * \param count the total number of params supplied.
  62. *
  63. * Most times in reply to your actions the IRC server generates numeric
  64. * callbacks. Most of them are error codes, and some of them mark list start
  65. * and list stop markers. Every code has its own set of params; for details
  66. * you can either experiment, or read RFC 1459.
  67. *
  68. * Every event has origin, though the \a origin variable may be NULL, which
  69. * means that event origin is unknown. The origin usually looks like
  70. * nick!host\@ircserver, i.e. like tim!home\@irc.krasnogorsk.ru. Such origins
  71. * can not be used in IRC commands, and need to be stripped (i.e. host and
  72. * server part should be cut off) before using. This can be done either
  73. * explicitly, by calling irc_target_get_nick(), or implicitly for all the
  74. * events - by setting the #LIBIRC_OPTION_STRIPNICKS option with irc_option_set().
  75. *
  76. * \ingroup events
  77. */
  78. typedef void (*irc_eventcode_callback_t) (irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count);
  79. /*!
  80. * \fn typedef void (*irc_event_dcc_chat_t) (irc_session_t * session, const char * nick, const char * addr, irc_dcc_t dccid)
  81. * \brief A remote DCC CHAT request callback
  82. *
  83. * \param session the session, which generates an event
  84. * \param nick the person who requested DCC CHAT with you.
  85. * \param addr the person's IP address in decimal-dot notation.
  86. * \param dccid an id associated with this request. Use it in calls to
  87. * irc_dcc_accept() or irc_dcc_decline().
  88. *
  89. * This callback is called when someone requests DCC CHAT with you. In respond
  90. * you should call either irc_dcc_accept() to accept chat request, or
  91. * irc_dcc_decline() to decline chat request.
  92. *
  93. * \sa irc_dcc_accept or irc_dcc_decline
  94. * \ingroup events
  95. */
  96. typedef void (*irc_event_dcc_chat_t) (irc_session_t * session, const char * nick, const char * addr, irc_dcc_t dccid);
  97. /*!
  98. * \fn typedef void (*irc_event_dcc_send_t) (irc_session_t * session, const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid)
  99. * \brief A remote DCC CHAT request callback
  100. *
  101. * \param session the session, which generates an event
  102. * \param nick the person who requested DCC CHAT with you.
  103. * \param addr the person's IP address in decimal-dot notation.
  104. * \param filename the sent filename.
  105. * \param size the filename size.
  106. * \param dccid an id associated with this request. Use it in calls to
  107. * irc_dcc_accept() or irc_dcc_decline().
  108. *
  109. * This callback is called when someone wants to send a file to you using
  110. * DCC SEND. As with chat, in respond you should call either irc_dcc_accept()
  111. * to accept this request and receive the file, or irc_dcc_decline() to
  112. * decline this request.
  113. *
  114. * \sa irc_dcc_accept or irc_dcc_decline
  115. * \ingroup events
  116. */
  117. typedef void (*irc_event_dcc_send_t) (irc_session_t * session, const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid);
  118. /*! \brief Event callbacks structure.
  119. *
  120. * All the communication with the IRC network is based on events. Generally
  121. * speaking, event is anything generated by someone else in the network,
  122. * or by the IRC server itself. "Someone sends you a message", "Someone
  123. * has joined the channel", "Someone has quits IRC" - all these messages
  124. * are events.
  125. *
  126. * Every event has its own event handler, which is called when the
  127. * appropriate event is received. You don't have to define all the event
  128. * handlers; define only the handlers for the events you need to intercept.
  129. *
  130. * Most event callbacks are the types of ::irc_event_callback_t. There are
  131. * also events, which generate ::irc_eventcode_callback_t,
  132. * ::irc_event_dcc_chat_t and ::irc_event_dcc_send_t callbacks.
  133. *
  134. * \ingroup events
  135. */
  136. typedef struct
  137. {
  138. /*!
  139. * The "on_connect" event is triggered when the client successfully
  140. * connects to the server, and could send commands to the server.
  141. * No extra params supplied; \a params is 0.
  142. */
  143. irc_event_callback_t event_connect;
  144. /*!
  145. * The "nick" event is triggered when the client receives a NICK message,
  146. * meaning that someone (including you) on a channel with the client has
  147. * changed their nickname.
  148. *
  149. * \param origin the person, who changes the nick. Note that it can be you!
  150. * \param params[0] mandatory, contains the new nick.
  151. */
  152. irc_event_callback_t event_nick;
  153. /*!
  154. * The "quit" event is triggered upon receipt of a QUIT message, which
  155. * means that someone on a channel with the client has disconnected.
  156. *
  157. * \param origin the person, who is disconnected
  158. * \param params[0] optional, contains the reason message (user-specified).
  159. */
  160. irc_event_callback_t event_quit;
  161. /*!
  162. * The "join" event is triggered upon receipt of a JOIN message, which
  163. * means that someone has entered a channel that the client is on.
  164. *
  165. * \param origin the person, who joins the channel. By comparing it with
  166. * your own nickname, you can check whether your JOIN
  167. * command succeed.
  168. * \param params[0] mandatory, contains the channel name.
  169. */
  170. irc_event_callback_t event_join;
  171. /*!
  172. * The "part" event is triggered upon receipt of a PART message, which
  173. * means that someone has left a channel that the client is on.
  174. *
  175. * \param origin the person, who leaves the channel. By comparing it with
  176. * your own nickname, you can check whether your PART
  177. * command succeed.
  178. * \param params[0] mandatory, contains the channel name.
  179. * \param params[1] optional, contains the reason message (user-defined).
  180. */
  181. irc_event_callback_t event_part;
  182. /*!
  183. * The "mode" event is triggered upon receipt of a channel MODE message,
  184. * which means that someone on a channel with the client has changed the
  185. * channel's parameters.
  186. *
  187. * \param origin the person, who changed the channel mode.
  188. * \param params[0] mandatory, contains the channel name.
  189. * \param params[1] mandatory, contains the changed channel mode, like
  190. * '+t', '-i' and so on.
  191. * \param params[2] optional, contains the mode argument (for example, a
  192. * key for +k mode, or user who got the channel operator status for
  193. * +o mode)
  194. */
  195. irc_event_callback_t event_mode;
  196. /*!
  197. * The "umode" event is triggered upon receipt of a user MODE message,
  198. * which means that your user mode has been changed.
  199. *
  200. * \param origin the person, who changed the channel mode.
  201. * \param params[0] mandatory, contains the user changed mode, like
  202. * '+t', '-i' and so on.
  203. */
  204. irc_event_callback_t event_umode;
  205. /*!
  206. * The "topic" event is triggered upon receipt of a TOPIC message, which
  207. * means that someone on a channel with the client has changed the
  208. * channel's topic.
  209. *
  210. * \param origin the person, who changes the channel topic.
  211. * \param params[0] mandatory, contains the channel name.
  212. * \param params[1] optional, contains the new topic.
  213. */
  214. irc_event_callback_t event_topic;
  215. /*!
  216. * The "kick" event is triggered upon receipt of a KICK message, which
  217. * means that someone on a channel with the client (or possibly the
  218. * client itself!) has been forcibly ejected.
  219. *
  220. * \param origin the person, who kicked the poor.
  221. * \param params[0] mandatory, contains the channel name.
  222. * \param params[0] optional, contains the nick of kicked person.
  223. * \param params[1] optional, contains the kick text
  224. */
  225. irc_event_callback_t event_kick;
  226. /*!
  227. * The "channel" event is triggered upon receipt of a PRIVMSG message
  228. * to an entire channel, which means that someone on a channel with
  229. * the client has said something aloud. Your own messages don't trigger
  230. * PRIVMSG event.
  231. *
  232. * \param origin the person, who generates the message.
  233. * \param params[0] mandatory, contains the channel name.
  234. * \param params[1] optional, contains the message text
  235. */
  236. irc_event_callback_t event_channel;
  237. /*!
  238. * The "privmsg" event is triggered upon receipt of a PRIVMSG message
  239. * which is addressed to one or more clients, which means that someone
  240. * is sending the client a private message.
  241. *
  242. * \param origin the person, who generates the message.
  243. * \param params[0] mandatory, contains your nick.
  244. * \param params[1] optional, contains the message text
  245. */
  246. irc_event_callback_t event_privmsg;
  247. /*!
  248. * The "privmsg" event is triggered upon receipt of a PRIVMSG message
  249. * which is addressed to no one in particular, but it sent to the client
  250. * anyway.
  251. *
  252. * \param origin the person, who generates the message.
  253. * \param params optional, contains who knows what.
  254. */
  255. irc_event_callback_t event_server_msg;
  256. /*!
  257. * The "notice" event is triggered upon receipt of a NOTICE message
  258. * which means that someone has sent the client a public or private
  259. * notice. According to RFC 1459, the only difference between NOTICE
  260. * and PRIVMSG is that you should NEVER automatically reply to NOTICE
  261. * messages. Unfortunately, this rule is frequently violated by IRC
  262. * servers itself - for example, NICKSERV messages require reply, and
  263. * are NOTICEs.
  264. *
  265. * \param origin the person, who generates the message.
  266. * \param params[0] mandatory, contains the target nick name.
  267. * \param params[1] optional, contains the message text
  268. */
  269. irc_event_callback_t event_notice;
  270. /*!
  271. * The "channel_notice" event is triggered upon receipt of a NOTICE
  272. * message which means that someone has sent the client a public
  273. * notice. According to RFC 1459, the only difference between NOTICE
  274. * and PRIVMSG is that you should NEVER automatically reply to NOTICE
  275. * messages. Unfortunately, this rule is frequently violated by IRC
  276. * servers itself - for example, NICKSERV messages require reply, and
  277. * are NOTICEs.
  278. *
  279. * \param origin the person, who generates the message.
  280. * \param params[0] mandatory, contains the channel name.
  281. * \param params[1] optional, contains the message text
  282. */
  283. irc_event_callback_t event_channel_notice;
  284. /*!
  285. * The "server_notice" event is triggered upon receipt of a NOTICE
  286. * message which means that the server has sent the client a notice.
  287. * This notice is not necessarily addressed to the client's nick
  288. * (for example, AUTH notices, sent before the client's nick is known).
  289. * According to RFC 1459, the only difference between NOTICE
  290. * and PRIVMSG is that you should NEVER automatically reply to NOTICE
  291. * messages. Unfortunately, this rule is frequently violated by IRC
  292. * servers itself - for example, NICKSERV messages require reply, and
  293. * are NOTICEs.
  294. *
  295. * \param origin the person, who generates the message.
  296. * \param params optional, contains who knows what.
  297. */
  298. irc_event_callback_t event_server_notice;
  299. /*!
  300. * The "invite" event is triggered upon receipt of an INVITE message,
  301. * which means that someone is permitting the client's entry into a +i
  302. * channel.
  303. *
  304. * \param origin the person, who INVITEs you.
  305. * \param params[0] mandatory, contains your nick.
  306. * \param params[1] mandatory, contains the channel name you're invited into.
  307. *
  308. * \sa irc_cmd_invite irc_cmd_chanmode_invite
  309. */
  310. irc_event_callback_t event_invite;
  311. /*!
  312. * The "ctcp" event is triggered when the client receives the CTCP
  313. * request. By default, the built-in CTCP request handler is used. The
  314. * build-in handler automatically replies on most CTCP messages, so you
  315. * will rarely need to override it.
  316. *
  317. * \param origin the person, who generates the message.
  318. * \param params[0] mandatory, the complete CTCP message, including its
  319. * arguments.
  320. *
  321. * Mirc generates PING, FINGER, VERSION, TIME and ACTION messages,
  322. * check the source code of \c libirc_event_ctcp_internal function to
  323. * see how to write your own CTCP request handler. Also you may find
  324. * useful this question in FAQ: \ref faq4
  325. */
  326. irc_event_callback_t event_ctcp_req;
  327. /*!
  328. * The "ctcp" event is triggered when the client receives the CTCP reply.
  329. *
  330. * \param origin the person, who generates the message.
  331. * \param params[0] mandatory, the CTCP message itself with its arguments.
  332. */
  333. irc_event_callback_t event_ctcp_rep;
  334. /*!
  335. * The "action" event is triggered when the client receives the CTCP
  336. * ACTION message. These messages usually looks like:\n
  337. * \code
  338. * [23:32:55] * Tim gonna sleep.
  339. * \endcode
  340. *
  341. * \param origin the person, who generates the message.
  342. * \param params[0] mandatory, the ACTION message.
  343. */
  344. irc_event_callback_t event_ctcp_action;
  345. /*!
  346. * The "unknown" event is triggered upon receipt of any number of
  347. * unclassifiable miscellaneous messages, which aren't handled by the
  348. * library.
  349. */
  350. irc_event_callback_t event_unknown;
  351. /*!
  352. * The "numeric" event is triggered upon receipt of any numeric response
  353. * from the server. There is a lot of such responses, see the full list
  354. * here: \ref rfcnumbers.
  355. *
  356. * See the params in ::irc_eventcode_callback_t specification.
  357. */
  358. irc_eventcode_callback_t event_numeric;
  359. /*!
  360. * The "dcc chat" event is triggered when someone requests a DCC CHAT from
  361. * you.
  362. *
  363. * See the params in ::irc_event_dcc_chat_t specification.
  364. */
  365. irc_event_dcc_chat_t event_dcc_chat_req;
  366. /*!
  367. * The "dcc chat" event is triggered when someone wants to send a file
  368. * to you via DCC SEND request.
  369. *
  370. * See the params in ::irc_event_dcc_send_t specification.
  371. */
  372. irc_event_dcc_send_t event_dcc_send_req;
  373. } irc_callbacks_t;
  374. #endif /* INCLUDE_IRC_EVENTS_H */