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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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 SEND request callback
  100. *
  101. * \param session the session, which generates an event
  102. * \param nick the person who requested DCC SEND to 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, size_t 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 "ping" event is triggered when the client receives a PING message.
  146. * It is only generated if the LIBIRC_OPTION_PING_PASSTHROUGH option is set;
  147. * otherwise, the library responds to PING messages automatically.
  148. *
  149. * \param origin the person, who generated the ping.
  150. * \param params[0] mandatory, contains who knows what.
  151. */
  152. irc_event_callback_t event_ping;
  153. /*!
  154. * The "nick" event is triggered when the client receives a NICK message,
  155. * meaning that someone (including you) on a channel with the client has
  156. * changed their nickname.
  157. *
  158. * \param origin the person, who changes the nick. Note that it can be you!
  159. * \param params[0] mandatory, contains the new nick.
  160. */
  161. irc_event_callback_t event_nick;
  162. /*!
  163. * The "quit" event is triggered upon receipt of a QUIT message, which
  164. * means that someone on a channel with the client has disconnected.
  165. *
  166. * \param origin the person, who is disconnected
  167. * \param params[0] optional, contains the reason message (user-specified).
  168. */
  169. irc_event_callback_t event_quit;
  170. /*!
  171. * The "join" event is triggered upon receipt of a JOIN message, which
  172. * means that someone has entered a channel that the client is on.
  173. *
  174. * \param origin the person, who joins the channel. By comparing it with
  175. * your own nickname, you can check whether your JOIN
  176. * command succeed.
  177. * \param params[0] mandatory, contains the channel name.
  178. */
  179. irc_event_callback_t event_join;
  180. /*!
  181. * The "part" event is triggered upon receipt of a PART message, which
  182. * means that someone has left a channel that the client is on.
  183. *
  184. * \param origin the person, who leaves the channel. By comparing it with
  185. * your own nickname, you can check whether your PART
  186. * command succeed.
  187. * \param params[0] mandatory, contains the channel name.
  188. * \param params[1] optional, contains the reason message (user-defined).
  189. */
  190. irc_event_callback_t event_part;
  191. /*!
  192. * The "mode" event is triggered upon receipt of a channel MODE message,
  193. * which means that someone on a channel with the client has changed the
  194. * channel's parameters.
  195. *
  196. * \param origin the person, who changed the channel mode.
  197. * \param params[0] mandatory, contains the channel name.
  198. * \param params[1] mandatory, contains the changed channel mode, like
  199. * '+t', '-i' and so on.
  200. * \param params[2] optional, contains the mode argument (for example, a
  201. * key for +k mode, or user who got the channel operator status for
  202. * +o mode)
  203. */
  204. irc_event_callback_t event_mode;
  205. /*!
  206. * The "umode" event is triggered upon receipt of a user MODE message,
  207. * which means that your user mode has been changed.
  208. *
  209. * \param origin the person, who changed the channel mode.
  210. * \param params[0] mandatory, contains the user changed mode, like
  211. * '+t', '-i' and so on.
  212. */
  213. irc_event_callback_t event_umode;
  214. /*!
  215. * The "topic" event is triggered upon receipt of a TOPIC message, which
  216. * means that someone on a channel with the client has changed the
  217. * channel's topic.
  218. *
  219. * \param origin the person, who changes the channel topic.
  220. * \param params[0] mandatory, contains the channel name.
  221. * \param params[1] optional, contains the new topic.
  222. */
  223. irc_event_callback_t event_topic;
  224. /*!
  225. * The "kick" event is triggered upon receipt of a KICK message, which
  226. * means that someone on a channel with the client (or possibly the
  227. * client itself!) has been forcibly ejected.
  228. *
  229. * \param origin the person, who kicked the poor.
  230. * \param params[0] mandatory, contains the channel name.
  231. * \param params[0] optional, contains the nick of kicked person.
  232. * \param params[1] optional, contains the kick text
  233. */
  234. irc_event_callback_t event_kick;
  235. /*!
  236. * The "error" event is triggered upon receipt of an ERROR message, which
  237. * (when sent to clients) usually means the client has been disconnected.
  238. *
  239. * \param origin the person, who generates the message.
  240. * \param params optional, contains who knows what.
  241. */
  242. irc_event_callback_t event_error;
  243. /*!
  244. * The "channel" event is triggered upon receipt of a PRIVMSG message
  245. * to an entire channel, which means that someone on a channel with
  246. * the client has said something aloud. Your own messages don't trigger
  247. * PRIVMSG event.
  248. *
  249. * \param origin the person, who generates the message.
  250. * \param params[0] mandatory, contains the channel name.
  251. * \param params[1] optional, contains the message text
  252. */
  253. irc_event_callback_t event_channel;
  254. /*!
  255. * The "privmsg" event is triggered upon receipt of a PRIVMSG message
  256. * which is addressed to one or more clients, which means that someone
  257. * is sending the client a private message.
  258. *
  259. * \param origin the person, who generates the message.
  260. * \param params[0] mandatory, contains your nick.
  261. * \param params[1] optional, contains the message text
  262. */
  263. irc_event_callback_t event_privmsg;
  264. /*!
  265. * The "privmsg" event is triggered upon receipt of a PRIVMSG message
  266. * which is addressed to no one in particular, but it sent to the client
  267. * anyway.
  268. *
  269. * \param origin the person, who generates the message.
  270. * \param params optional, contains who knows what.
  271. */
  272. irc_event_callback_t event_server_msg;
  273. /*!
  274. * The "notice" event is triggered upon receipt of a NOTICE message
  275. * which means that someone has sent the client a public or private
  276. * notice. According to RFC 1459, the only difference between NOTICE
  277. * and PRIVMSG is that you should NEVER automatically reply to NOTICE
  278. * messages. Unfortunately, this rule is frequently violated by IRC
  279. * servers itself - for example, NICKSERV messages require reply, and
  280. * are NOTICEs.
  281. *
  282. * \param origin the person, who generates the message.
  283. * \param params[0] mandatory, contains the target nick name.
  284. * \param params[1] optional, contains the message text
  285. */
  286. irc_event_callback_t event_notice;
  287. /*!
  288. * The "channel_notice" event is triggered upon receipt of a NOTICE
  289. * message which means that someone has sent the client a public
  290. * notice. According to RFC 1459, the only difference between NOTICE
  291. * and PRIVMSG is that you should NEVER automatically reply to NOTICE
  292. * messages. Unfortunately, this rule is frequently violated by IRC
  293. * servers itself - for example, NICKSERV messages require reply, and
  294. * are NOTICEs.
  295. *
  296. * \param origin the person, who generates the message.
  297. * \param params[0] mandatory, contains the channel name.
  298. * \param params[1] optional, contains the message text
  299. */
  300. irc_event_callback_t event_channel_notice;
  301. /*!
  302. * The "server_notice" event is triggered upon receipt of a NOTICE
  303. * message which means that the server has sent the client a notice.
  304. * This notice is not necessarily addressed to the client's nick
  305. * (for example, AUTH notices, sent before the client's nick is known).
  306. * According to RFC 1459, the only difference between NOTICE
  307. * and PRIVMSG is that you should NEVER automatically reply to NOTICE
  308. * messages. Unfortunately, this rule is frequently violated by IRC
  309. * servers itself - for example, NICKSERV messages require reply, and
  310. * are NOTICEs.
  311. *
  312. * \param origin the person, who generates the message.
  313. * \param params optional, contains who knows what.
  314. */
  315. irc_event_callback_t event_server_notice;
  316. /*!
  317. * The "invite" event is triggered upon receipt of an INVITE message,
  318. * which means that someone is permitting the client's entry into a +i
  319. * channel.
  320. *
  321. * \param origin the person, who INVITEs you.
  322. * \param params[0] mandatory, contains your nick.
  323. * \param params[1] mandatory, contains the channel name you're invited into.
  324. *
  325. * \sa irc_cmd_invite irc_cmd_chanmode_invite
  326. */
  327. irc_event_callback_t event_invite;
  328. /*!
  329. * The "ctcp" event is triggered when the client receives the CTCP
  330. * request. By default, the built-in CTCP request handler is used. The
  331. * build-in handler automatically replies on most CTCP messages, so you
  332. * will rarely need to override it.
  333. *
  334. * \param origin the person, who generates the message.
  335. * \param params[0] mandatory, the complete CTCP message, including its
  336. * arguments.
  337. *
  338. * Mirc generates PING, FINGER, VERSION, TIME and ACTION messages,
  339. * check the source code of \c libirc_event_ctcp_internal function to
  340. * see how to write your own CTCP request handler. Also you may find
  341. * useful this question in FAQ: \ref faq4
  342. */
  343. irc_event_callback_t event_ctcp_req;
  344. /*!
  345. * The "ctcp" event is triggered when the client receives the CTCP reply.
  346. *
  347. * \param origin the person, who generates the message.
  348. * \param params[0] mandatory, the CTCP message itself with its arguments.
  349. */
  350. irc_event_callback_t event_ctcp_rep;
  351. /*!
  352. * The "action" event is triggered when the client receives the CTCP
  353. * ACTION message. These messages usually looks like:\n
  354. * \code
  355. * [23:32:55] * Tim gonna sleep.
  356. * \endcode
  357. *
  358. * \param origin the person, who generates the message.
  359. * \param params[0] mandatory, the ACTION message.
  360. */
  361. irc_event_callback_t event_ctcp_action;
  362. /*!
  363. * The "unknown" event is triggered upon receipt of any number of
  364. * unclassifiable miscellaneous messages, which aren't handled by the
  365. * library.
  366. */
  367. irc_event_callback_t event_unknown;
  368. /*!
  369. * The "numeric" event is triggered upon receipt of any numeric response
  370. * from the server. There is a lot of such responses, see the full list
  371. * here: \ref rfcnumbers.
  372. *
  373. * See the params in ::irc_eventcode_callback_t specification.
  374. */
  375. irc_eventcode_callback_t event_numeric;
  376. /*!
  377. * The "dcc chat" event is triggered when someone requests a DCC CHAT from
  378. * you.
  379. *
  380. * See the params in ::irc_event_dcc_chat_t specification.
  381. */
  382. irc_event_dcc_chat_t event_dcc_chat_req;
  383. /*!
  384. * The "dcc send" event is triggered when someone wants to send a file
  385. * to you via DCC SEND request.
  386. *
  387. * See the params in ::irc_event_dcc_send_t specification.
  388. */
  389. irc_event_dcc_send_t event_dcc_send_req;
  390. } irc_callbacks_t;
  391. #endif /* INCLUDE_IRC_EVENTS_H */