IRC client framework (wrapper around libircclient library).
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

libircclient.h 60KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  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. /*!
  15. * \file libircclient.h
  16. * \author George Yunaev
  17. * \version 1.9
  18. * \date 01.2012
  19. * \brief This file defines all prototypes and functions to use libircclient.
  20. *
  21. * libircclient is a small but powerful library, which implements client-server IRC
  22. * protocol. It is designed to be small, fast, portable and compatible to RFC
  23. * standards, and most IRC clients. libircclient features include:
  24. * - Full multi-threading support.
  25. * - Single threads handles all the IRC processing.
  26. * - Support for single-threaded applications, and socket-based applications,
  27. * which use select()
  28. * - Synchronous and asynchronous interfaces.
  29. * - CTCP support with optional build-in reply code.
  30. * - Flexible DCC support, including both DCC chat, and DCC file transfer.
  31. * - Can both initiate and react to initiated DCC.
  32. * - Can accept or decline DCC sessions asynchronously.
  33. * - Plain C interface and implementation (possible to use from C++ code,
  34. * obviously)
  35. * - Compatible with RFC 1459 and most IRC clients.
  36. * - SSL support if compiled with --enable-openssl.
  37. * - Free, licensed under LGPL license.
  38. *
  39. * Note that to use libircclient, only libircclient.h should be included into your
  40. * program. Do not include other libirc_* headers.
  41. */
  42. #ifndef INCLUDE_LIBIRC_H
  43. #define INCLUDE_LIBIRC_H
  44. #include <stdlib.h>
  45. #if !defined (_WIN32)
  46. #include <sys/select.h> /* fd_set */
  47. #else
  48. #include <winsock2.h>
  49. #include <ws2tcpip.h>
  50. #if defined (ENABLE_IPV6)
  51. typedef int (WSAAPI * getaddrinfo_ptr_t) (const char *, const char* , const struct addrinfo *, struct addrinfo **);
  52. typedef void (WSAAPI * freeaddrinfo_ptr_t) (struct addrinfo*);
  53. #endif
  54. #endif
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif
  58. /*! \brief A libircclient IRC session.
  59. *
  60. * This structure describes an IRC session. Its members are internal to
  61. * libircclient, and should not be used directly.
  62. */
  63. typedef struct irc_session_s irc_session_t;
  64. /*! \brief A libircclient DCC session.
  65. *
  66. * This structure describes a DCC session used by libircclient.
  67. * Its members are internal to libircclient, and should not be used directly.
  68. */
  69. typedef struct irc_dcc_session_s irc_dcc_session_t;
  70. /*! \brief A DCC session identifier.
  71. *
  72. * The irc_dcc_t type is a DCC session identifier, used to identify the
  73. * DCC sessions in callbacks and various functions.
  74. */
  75. typedef unsigned int irc_dcc_t;
  76. /*!
  77. * \fn typedef void (*irc_dcc_callback_t) (irc_session_t * session, irc_dcc_t id, int status, void * ctx, const char * data, unsigned int length)
  78. * \brief A common DCC callback, used to inform you about the current DCC state or event.
  79. *
  80. * \param session An IRC session which generates the callback
  81. * \param id A DCC session id.
  82. * \param status An error status. 0 means no error, otherwise error code.
  83. * \param ctx A user-supplied context.
  84. * \param data Data supplied (if available)
  85. * \param length data length (if available)
  86. *
  87. * This callback is called for all DCC functions when state change occurs.
  88. *
  89. * For DCC CHAT, the callback is called in next circumstances:
  90. * - \a status is LIBIRC_ERR_CLOSED: connection is closed by remote peer.
  91. * After returning from the callback, the DCC session is automatically
  92. * destroyed.
  93. * - \a status is neither 0 nor LIBIRC_ERR_CLOSED: socket I/O error
  94. * (connect error, accept error, recv error, send error). After returning
  95. * from the callback, the DCC session is automatically destroyed.
  96. * - \a status is 0: new chat message received, \a data contains the message
  97. * (null-terminated string), \a length contains the message length.
  98. *
  99. * For DCC SEND, while file is sending, callback called in next circumstances:
  100. * - \a status is neither 0 nor LIBIRC_ERR_CLOSED: socket I/O error
  101. * (connect error, accept error, recv error, send error). After returning
  102. * from the callback, the DCC session is automatically destroyed.
  103. * - \a status is 0: new data received, \a data contains the data received,
  104. * \a length contains the amount of data received.
  105. *
  106. * For DCC RECV, while file is sending, callback called in next circumstances:
  107. * - \a status is neither 0 nor LIBIRC_ERR_CLOSED: socket I/O error
  108. * (connect error, accept error, recv error, send error). After returning
  109. * from the callback, the DCC session is automatically destroyed.
  110. * - \a status is 0, and \a data is 0: file has been received successfully.
  111. * After returning from the callback, the DCC session is automatically
  112. * destroyed.
  113. * - \a status is 0, and \a data is not 0: new data received, \a data contains
  114. * the data received, \a length contains the amount of data received.
  115. *
  116. * \ingroup dccstuff
  117. */
  118. typedef void (*irc_dcc_callback_t) (irc_session_t *session, irc_dcc_t id, int status, void *ctx, const char *data, size_t length);
  119. #define IN_INCLUDE_LIBIRC_H
  120. #include "libirc_errors.h"
  121. #include "libirc_events.h"
  122. #include "libirc_options.h"
  123. #undef IN_INCLUDE_LIBIRC_H
  124. /*!
  125. * \fn irc_session_t * irc_create_session (irc_callbacks_t * callbacks)
  126. * \brief Creates and initiates a new IRC session.
  127. *
  128. * \param callbacks A structure, which defines several callbacks, which will
  129. * be called on appropriate events. Must not be NULL.
  130. *
  131. * \return An ::irc_session_t object, or 0 if creation failed. Usually,
  132. * failure is caused by out of memory error.
  133. *
  134. * Every ::irc_session_t object describes a single IRC session - a connection
  135. * to an IRC server, and possibly to some DCC clients. Almost every irc_*
  136. * function requires this object to be passed to, and therefore this function
  137. * should be called first.
  138. *
  139. * Every session created must be destroyed when it is not needed anymore
  140. * by calling irc_destroy_session().
  141. *
  142. * The most common function sequence is:
  143. * \code
  144. * ... prepare irc_callbacks_t structure ...
  145. * irc_create_session();
  146. * irc_connect();
  147. * irc_run();
  148. * irc_destroy_session();
  149. * \endcode
  150. *
  151. * \sa irc_destroy_session
  152. * \ingroup initclose
  153. */
  154. irc_session_t* irc_create_session (irc_callbacks_t *callbacks);
  155. /*!
  156. * \fn void irc_destroy_session (irc_session_t * session)
  157. * \brief Destroys previously created IRC session.
  158. *
  159. * \param session A session to destroy. Must not be NULL.
  160. *
  161. * This function should be used to destroy an IRC session, close the
  162. * connection to the IRC server, and free all the used resources. After
  163. * calling this function, you should not use this session object anymore.
  164. *
  165. * \ingroup initclose
  166. */
  167. void irc_destroy_session (irc_session_t *session);
  168. /*!
  169. * \fn int irc_connect (irc_session_t * session, const char * server, unsigned short port, const char * server_password, const char * nick, const char * username, const char * realname);
  170. * \brief Initiates a connection to IRC server.
  171. *
  172. * \param session A session to initiate connections on. Must not be NULL.
  173. * \param server A domain name or an IP address of the IRC server to connect to. Cannot be NULL.
  174. * If the library is built with SSL support and the first character is hash, tries to establish the SSL connection.
  175. * For example, the connection to "irc.example.com" is assumed to be plaintext, and connection to "#irc.example.com"
  176. * is assumed to be secured by SSL. Note that SSL will only work if the library is built with the SSL support.
  177. * \param port An IRC server port, usually 6667.
  178. * \param server_password An IRC server password, if the server requires it.
  179. * May be NULL, in this case password will not be send to the
  180. * IRC server. Vast majority of IRC servers do not require passwords.
  181. * \param nick A nick, which libircclient will use to login to the IRC server.
  182. * Must not be NULL.
  183. * \param username A username of the account, which is used to connect to the
  184. * IRC server. This is for information only, will be shown in
  185. * "user properties" dialogs and returned by /whois request.
  186. * May be NULL, in this case 'nobody' will be sent as username.
  187. * \param realname A real name of the person, who connects to the IRC. Usually
  188. * people put some wide-available information here (URL, small
  189. * description or something else). This information also will
  190. * be shown in "user properties" dialogs and returned by /whois
  191. * request. May be NULL, in this case 'noname' will be sent as
  192. * username.
  193. *
  194. * \return Return code 0 means success. Other value means error, the error
  195. * code may be obtained through irc_errno(). Any error, generated by the
  196. * IRC server, is available through irc_callbacks_t::event_numeric.
  197. *
  198. * This function prepares and initiates a connection to the IRC server. The
  199. * connection is done asynchronously (see irc_callbacks_t::event_connect), so the success
  200. * return value means that connection was initiated (but not completed!)
  201. * successfully.
  202. *
  203. * \sa irc_run
  204. * \ingroup conndisc
  205. */
  206. int irc_connect (irc_session_t *session,
  207. const char *server,
  208. unsigned short port,
  209. const char *server_password,
  210. const char *nick,
  211. const char *username,
  212. const char *realname);
  213. /*!
  214. * \fn int irc_connect6 (irc_session_t * session, const char * server, unsigned short port, const char * server_password, const char * nick, const char * username, const char * realname);
  215. * \brief Initiates a connection to IRC server using IPv6.
  216. *
  217. * \param session A session to initiate connections on. Must not be NULL.
  218. * \param server A domain name or an IP address of the IRC server to connect to. Cannot be NULL.
  219. * If the library is built with SSL support and the first character is hash, tries to establish the SSL connection.
  220. * For example, the connection to "irc.example.com" is assumed to be plaintext, and connection to "#irc.example.com"
  221. * is assumed to be secured by SSL. Note that SSL will only work if the library is built with the SSL support.
  222. * \param port An IRC server port, usually 6667.
  223. * \param server_password An IRC server password, if the server requires it.
  224. * May be NULL, in this case password will not be send to the
  225. * IRC server. Vast majority of IRC servers do not require passwords.
  226. * \param nick A nick, which libircclient will use to login to the IRC server.
  227. * Must not be NULL.
  228. * \param username A username of the account, which is used to connect to the
  229. * IRC server. This is for information only, will be shown in
  230. * "user properties" dialogs and returned by /whois request.
  231. * May be NULL, in this case 'nobody' will be sent as username.
  232. * \param realname A real name of the person, who connects to the IRC. Usually
  233. * people put some wide-available information here (URL, small
  234. * description or something else). This information also will
  235. * be shown in "user properties" dialogs and returned by /whois
  236. * request. May be NULL, in this case 'noname' will be sent as
  237. * username.
  238. *
  239. * \return Return code 0 means success. Other value means error, the error
  240. * code may be obtained through irc_errno(). Any error, generated by the
  241. * IRC server, is available through irc_callbacks_t::event_numeric.
  242. *
  243. * This function prepares and initiates a connection to the IRC server. The
  244. * connection is done asynchronously (see irc_callbacks_t::event_connect), so the success
  245. * return value means that connection was initiated (but not completed!)
  246. * successfully.
  247. *
  248. * \sa irc_run
  249. * \ingroup conndisc
  250. */
  251. int irc_connect6 (irc_session_t *session,
  252. const char *server,
  253. unsigned short port,
  254. const char *server_password,
  255. const char *nick,
  256. const char *username,
  257. const char *realname);
  258. /*!
  259. * \fn void irc_disconnect (irc_session_t * session)
  260. * \brief Disconnects a connection to IRC server.
  261. *
  262. * \param session An IRC session.
  263. *
  264. * \return Return code 0 means success. Other value means error, the error
  265. * code may be obtained through irc_errno().
  266. *
  267. * This function closes the IRC connection. After that connection is closed,
  268. * libircclient automatically leaves irc_run loop.
  269. *
  270. * \sa irc_connect irc_run
  271. * \ingroup conndisc
  272. */
  273. void irc_disconnect (irc_session_t *session);
  274. /*!
  275. * \fn int irc_is_connected (irc_session_t * session)
  276. * \brief Checks whether the session is connecting/connected to the IRC server.
  277. *
  278. * \param session An initialized IRC session.
  279. *
  280. * \return Return code 1 means that session is connecting or connected to the
  281. * IRC server, zero value means that the session has been disconnected.
  282. *
  283. * \sa irc_connect irc_run
  284. * \ingroup conndisc
  285. */
  286. int irc_is_connected (irc_session_t *session);
  287. /*!
  288. * \fn int irc_run (irc_session_t * session)
  289. * \brief Goes into forever-loop, processing IRC events and generating
  290. * callbacks.
  291. *
  292. * \param session An initiated and connected session.
  293. *
  294. * \return Return code 0 means success. Other value means error, the error
  295. * code may be obtained through irc_errno().
  296. *
  297. * This function goes into forever loop, processing the IRC events, and
  298. * calling appropriate callbacks. This function will not return until the
  299. * server connection is terminated - either by server, or by calling
  300. * irc_cmd_quit. This function should be used, if you don't need asynchronous
  301. * request processing (i.e. your bot just reacts on the events, and doesn't
  302. * generate it asynchronously). Even in last case, you still can call irc_run,
  303. * and start the asynchronous thread in event_connect handler. See examples.
  304. *
  305. * \ingroup running
  306. */
  307. int irc_run (irc_session_t *session);
  308. /*!
  309. * \fn int irc_add_select_descriptors (irc_session_t * session, fd_set *in_set, fd_set *out_set, int * maxfd)
  310. * \brief Adds IRC socket(s) for the descriptor set to use in select().
  311. *
  312. * \param session An initiated and connected session.
  313. * \param in_set A FD_IN descriptor set for select()
  314. * \param out_set A FD_OUT descriptor set for select()
  315. * \param maxfd A max descriptor found.
  316. *
  317. * \return Return code 0 means success. Other value means error, the error
  318. * code may be obtained through irc_errno().
  319. *
  320. * This function should be used when you already have a program with select()
  321. * based data processing. You prepare your descriptors, call this function
  322. * to add session's descriptor(s) into set, and then call select(). When it
  323. * returns, you should call irc_add_select_descriptors, which sends/recvs all
  324. * available data, parses received data, calls your callbacks(!), and returns.
  325. * Then you can process your sockets from set. See the example.
  326. *
  327. * \sa irc_process_select_descriptors
  328. * \ingroup running
  329. */
  330. int irc_add_select_descriptors (irc_session_t *session,
  331. fd_set *in_set,
  332. fd_set *out_set,
  333. int *maxfd);
  334. /*!
  335. * \fn int irc_process_select_descriptors (irc_session_t * session, fd_set *in_set, fd_set *out_set)
  336. * \brief Processes the IRC socket(s), which descriptor(s) are set.
  337. *
  338. * \param session An initiated and connected session.
  339. * \param in_set A FD_IN descriptor set for select()
  340. * \param out_set A FD_OUT descriptor set for select()
  341. *
  342. * \return Return code 0 means success. Other value means error, the error
  343. * code may be obtained through irc_errno().
  344. *
  345. * This function should be used in pair with irc_add_select_descriptors
  346. * function. See irc_add_select_descriptors description.
  347. *
  348. * \sa irc_add_select_descriptors
  349. * \ingroup running
  350. */
  351. int irc_process_select_descriptors (irc_session_t *session,
  352. fd_set *in_set,
  353. fd_set *out_set);
  354. /*!
  355. * \fn int irc_send_raw (irc_session_t * session, const char * format, ...)
  356. * \brief Sends raw data to the IRC server.
  357. *
  358. * \param session An initiated and connected session.
  359. * \param format A printf-formatted string, followed by function args.
  360. *
  361. * \return Return code 0 means success. Other value means error, the error
  362. * code may be obtained through irc_errno(). Any error, generated by the
  363. * IRC server, is available through irc_callbacks_t::event_numeric.
  364. *
  365. * This function sends the raw data as-is to the IRC server. Use it to
  366. * generate a server command, which is not (yet) provided by libircclient
  367. * directly.
  368. *
  369. * \ingroup ircmd_oth
  370. */
  371. int irc_send_raw (irc_session_t *session,
  372. const char *format,
  373. ...);
  374. /*!
  375. * \fn int irc_cmd_quit (irc_session_t * session, const char * reason)
  376. * \brief Sends QUIT command to the IRC server.
  377. *
  378. * \param session An initiated and connected session.
  379. * \param reason A reason to quit. May be NULL.
  380. *
  381. * \return Return code 0 means success. Other value means error, the error
  382. * code may be obtained through irc_errno(). Any error, generated by the
  383. * IRC server, is available through irc_callbacks_t::event_numeric.
  384. *
  385. * This function sends the QUIT command to the IRC server. This command
  386. * forces the IRC server to close the IRC connection, and terminate the
  387. * session.
  388. *
  389. * \ingroup ircmd_oth
  390. */
  391. int irc_cmd_quit (irc_session_t *session,
  392. const char *reason);
  393. /*!
  394. * \fn int irc_cmd_join (irc_session_t * session, const char * channel, const char * key)
  395. * \brief Joins the new IRC channel.
  396. *
  397. * \param session An initiated and connected session.
  398. * \param channel A channel name to join to. Must not be NULL.
  399. * \param key Channel password. May be NULL.
  400. *
  401. * \return Return code 0 means success. Other value means error, the error
  402. * code may be obtained through irc_errno(). Any error, generated by the
  403. * IRC server, is available through irc_callbacks_t::event_numeric.
  404. *
  405. * This function is used to JOIN the IRC channel. If the channel is not exist,
  406. * it will be automatically created by the IRC server. Note that to JOIN the
  407. * password-protected channel, you must know the password, and specify it in
  408. * the \a key argument.
  409. *
  410. * If join is successful, the irc_callbacks_t::event_join is called (with \a origin ==
  411. * your nickname), then you are sent the channel's topic
  412. * (using ::LIBIRC_RFC_RPL_TOPIC) and the list of users who are on the
  413. * channel (using ::LIBIRC_RFC_RPL_NAMREPLY), which includes the user
  414. * joining - namely you.
  415. *
  416. * Possible error responces for this command from the RFC1459:
  417. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  418. * - ::LIBIRC_RFC_ERR_BANNEDFROMCHAN
  419. * - ::LIBIRC_RFC_ERR_INVITEONLYCHAN
  420. * - ::LIBIRC_RFC_ERR_BADCHANNELKEY
  421. * - ::LIBIRC_RFC_ERR_CHANNELISFULL
  422. * - ::LIBIRC_RFC_ERR_BADCHANMASK
  423. * - ::LIBIRC_RFC_ERR_NOSUCHCHANNEL
  424. * - ::LIBIRC_RFC_ERR_TOOMANYCHANNELS
  425. *
  426. * And on success the following replies returned:
  427. * - ::LIBIRC_RFC_RPL_TOPIC
  428. * - ::LIBIRC_RFC_RPL_NAMREPLY
  429. *
  430. * \ingroup ircmd_ch
  431. */
  432. int irc_cmd_join (irc_session_t *session,
  433. const char *channel,
  434. const char *key);
  435. /*!
  436. * \fn int irc_cmd_part (irc_session_t * session, const char * channel)
  437. * \brief Leaves the IRC channel.
  438. *
  439. * \param session An initiated and connected session.
  440. * \param channel A channel name to leave. Must not be NULL.
  441. *
  442. * \return Return code 0 means success. Other value means error, the error
  443. * code may be obtained through irc_errno(). Any error, generated by the
  444. * IRC server, is available through irc_callbacks_t::event_numeric.
  445. *
  446. * This function is used to leave the IRC channel you've already joined to.
  447. * An attempt to leave the channel you aren't in results a ::LIBIRC_RFC_ERR_NOTONCHANNEL
  448. * server error.
  449. *
  450. * Possible error responces for this command from the RFC1459:
  451. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  452. * - ::LIBIRC_RFC_ERR_NOSUCHCHANNEL
  453. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  454. *
  455. * \ingroup ircmd_ch
  456. */
  457. int irc_cmd_part (irc_session_t *session,
  458. const char *channel);
  459. /*!
  460. * \fn int irc_cmd_invite (irc_session_t * session, const char * nick, const char * channel)
  461. * \brief Invites a user to invite-only channel.
  462. *
  463. * \param session An initiated and connected session.
  464. * \param nick A nick to invite. Must not be NULL.
  465. * \param channel A channel name to invite to. Must not be NULL.
  466. *
  467. * \return Return code 0 means success. Other value means error, the error
  468. * code may be obtained through irc_errno(). Any error, generated by the
  469. * IRC server, is available through irc_callbacks_t::event_numeric.
  470. *
  471. * This function is used to invite someone to invite-only channel.
  472. * "Invite-only" is a channel mode, which restricts anyone, except invided,
  473. * to join this channel. After invitation, the user could join this channel.
  474. * The user, who is invited, will receive the irc_callbacks_t::event_invite event.
  475. * Note that you must be a channel operator to INVITE the users.
  476. *
  477. * Possible error responces for this command from the RFC1459:
  478. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  479. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  480. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  481. * - ::LIBIRC_RFC_ERR_ERR_USERONCHANNEL
  482. * - ::LIBIRC_RFC_ERR_ERR_CHANOPRIVSNEEDED
  483. *
  484. * And on success one of the following replies returned:
  485. * - ::LIBIRC_RFC_RPL_INVITING
  486. * - ::LIBIRC_RFC_RPL_AWAY
  487. *
  488. * \sa irc_callbacks_t::event_invite irc_cmd_channel_mode
  489. * \ingroup ircmd_ch
  490. */
  491. int irc_cmd_invite (irc_session_t *session,
  492. const char *nick,
  493. const char *channel);
  494. /*!
  495. * \fn int irc_cmd_names (irc_session_t * session, const char * channel)
  496. * \brief Obtains a list of users who're in channel.
  497. *
  498. * \param session An initiated and connected session.
  499. * \param channel A channel name(s) to obtain user list. Must not be NULL.
  500. * It is possible to specify more than a single channel, but
  501. * several channel names should be separated by a comma.
  502. *
  503. * \return Return code 0 means success. Other value means error, the error
  504. * code may be obtained through irc_errno(). Any error, generated by the
  505. * IRC server, is available through irc_callbacks_t::event_numeric.
  506. *
  507. * This function is used to ask the IRC server for the list of the users
  508. * who're in specified channel. You can list all nicknames that are visible
  509. * to you on any channel that you can see. The list of users will be returned
  510. * using ::RPL_NAMREPLY and ::RPL_ENDOFNAMES numeric codes.
  511. *
  512. * The channel names are returned by irc_callbacks_t::event_numeric
  513. * using the following reply codes:
  514. * - ::LIBIRC_RFC_RPL_NAMREPLY
  515. * - ::LIBIRC_RFC_RPL_ENDOFNAMES
  516. *
  517. * \ingroup ircmd_ch
  518. */
  519. int irc_cmd_names (irc_session_t *session,
  520. const char *channel);
  521. /*!
  522. * \fn int irc_cmd_list (irc_session_t * session, const char * channel)
  523. * \brief Obtains a list of active server channels with their topics.
  524. *
  525. * \param session An initiated and connected session.
  526. * \param channel A channel name(s) to list. May be NULL, in which case all the
  527. * channels will be listed. It is possible to specify more than
  528. * a single channel, but several channel names should be
  529. * separated by a comma.
  530. *
  531. * \return Return code 0 means success. Other value means error, the error
  532. * code may be obtained through irc_errno(). Any error, generated by the
  533. * IRC server, is available through irc_callbacks_t::event_numeric.
  534. *
  535. * This function is used to ask the IRC server for the active (existing)
  536. * channels list. The list will be returned using ::LIBIRC_RFC_RPL_LISTSTART -
  537. * ::LIBIRC_RFC_RPL_LIST - ::LIBIRC_RFC_RPL_LISTEND sequence.
  538. * Note that "private" channels are listed (without their topics) as channel
  539. * "Prv" unless the client generating the LIST query is actually on that
  540. * channel. Likewise, secret channels are
  541. * not listed at all unless the client is a member of the channel in question.
  542. *
  543. * Possible error responces for this command from the RFC1459:
  544. * - ::LIBIRC_RFC_ERR_NOSUCHSERVER
  545. *
  546. * And the channel list is returned using the following reply codes:
  547. * - ::LIBIRC_RFC_RPL_LISTSTART
  548. * - ::LIBIRC_RFC_RPL_LISTEND
  549. * - ::LIBIRC_RFC_RPL_LIST
  550. *
  551. * \ingroup ircmd_ch
  552. */
  553. int irc_cmd_list (irc_session_t *session,
  554. const char *channel);
  555. /*!
  556. * \fn int irc_cmd_topic (irc_session_t * session, const char * channel, const char * topic)
  557. * \brief Views or changes the channel topic.
  558. *
  559. * \param session An initiated and connected session.
  560. * \param channel A channel name to invite to. Must not be NULL.
  561. * \param topic A new topic to change. If NULL, the old topic will be
  562. * returned, and topic won't changed.
  563. *
  564. * \return Return code 0 means success. Other value means error, the error
  565. * code may be obtained through irc_errno(). Any error, generated by the
  566. * IRC server, is available through irc_callbacks_t::event_numeric.
  567. *
  568. * The irc_cmd_topic() is used to change or view the topic of a channel.
  569. * The topic for \a channel is returned if \a topic is NULL. If the \a topic
  570. * is not NULL, the topic for the \a channel will be changed. Note that,
  571. * depending on \a +t channel mode, you may be required to be a channel
  572. * operator to change the channel topic.
  573. *
  574. * If the command succeed, the IRC server will generate a ::RPL_NOTOPIC or
  575. * ::RPL_TOPIC message, containing either old or changed topic. Also the IRC
  576. * server can (but not have to) generate the non-RFC ::RPL_TOPIC_EXTRA message,
  577. * containing the nick of person, who's changed the topic, and the time of
  578. * latest topic change.
  579. *
  580. * Possible error responces for this command from the RFC1459:
  581. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  582. * - ::LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
  583. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  584. *
  585. * And the topic information is returned using one of following reply codes:
  586. * - ::LIBIRC_RFC_RPL_NOTOPIC
  587. * - ::LIBIRC_RFC_RPL_TOPIC
  588. *
  589. * \sa irc_callbacks_t::event_topic irc_cmd_channel_mode
  590. * \ingroup ircmd_ch
  591. */
  592. int irc_cmd_topic (irc_session_t *session,
  593. const char *channel,
  594. const char *topic);
  595. /*!
  596. * \fn int irc_cmd_channel_mode (irc_session_t * session, const char * channel, const char * mode)
  597. * \brief Views or changes the channel mode.
  598. *
  599. * \param session An initiated and connected session.
  600. * \param channel A channel name to invite to. Must not be NULL.
  601. * \param mode A channel mode, described below. If NULL, the channel mode is
  602. * not changed, just the old mode is returned.
  603. *
  604. * \return Return code 0 means success. Other value means error, the error
  605. * code may be obtained through irc_errno(). Any error, generated by the
  606. * IRC server, is available through irc_callbacks_t::event_numeric.
  607. *
  608. * The irc_cmd_channel_mode() is used to change or view the channel modes.
  609. * The \a channel mode is returned if the \a mode is NULL. If the \a mode
  610. * is not NULL, the mode for the \a channel will be changed. Note that,
  611. * only channel operators can change the channel modes.
  612. *
  613. * Channel mode is represended by the letters combination. Every letter has
  614. * its own meaning in channel modes. Most channel mode letters are boolean
  615. * (i.e. could only be set or reset), but a few channel mode letters accept a
  616. * parameter. All channel options are set by adding a plus sign before the
  617. * letter, and reset by adding a minus sign before the letter.
  618. *
  619. * Here is the list of 'standard' channel modes:
  620. *
  621. * - \a o \a nickname - gives (+o nick) or takes (-o nick) the channel
  622. * operator privileges from a \a nickname. This mode affects the
  623. * users in channel, not the channel itself.
  624. * Examples: "+o tim", "-o watson".
  625. *
  626. * - \a p - sets (+p) or resets (-p) private channel flag.
  627. * Private channels are shown in channel list as 'Prv', without the topic.
  628. *
  629. * - \a s - sets (+p) or resets (-p) secret channel flag.
  630. * Secret channels aren't shown in channel list at all.
  631. *
  632. * - \a i - sets (+i) or resets (-i) invite-only channel flag. When the flag
  633. * is set, only the people who are invited by irc_cmd_invite(), can
  634. * join this channel.
  635. *
  636. * - \a t - sets (+t) or resets (-t) topic settable by channel operator only
  637. * flag. When the flag is set, only the channel operators can change the
  638. * channel topic.
  639. *
  640. * - \a n - sets (+n) or resets (-n) the protection from the clients outside
  641. * the channel. When the \a +n mode is set, only the clients, who are in
  642. * channel, can send the messages to the channel.
  643. *
  644. * - \a m - sets (+m) or resets (-m) the moderation of the channel. When the
  645. * moderation mode is set, only channel operators and the users who have
  646. * the \a +v user mode can speak in the channel.
  647. *
  648. * - \a v \a nickname - gives (+v nick) or takes (-v nick) from user the
  649. * ability to speak on a moderated channel.
  650. * Examples: "+v tim", "-v watson".
  651. *
  652. * - \a l \a number - sets (+l 20) or removes (-l) the restriction of maximum
  653. * users in channel. When the restriction is set, and there is a number
  654. * of users in the channel, no one can join the channel anymore.
  655. *
  656. * - \a k \a key - sets (+k secret) or removes (-k) the password from the
  657. * channel. When the restriction is set, any user joining the channel
  658. * required to provide a channel key.
  659. *
  660. * - \a b \a mask - sets (+b *!*@*.mil) or removes (-b *!*@*.mil) the ban mask
  661. * on a user to keep him out of channel. Note that to remove the ban you
  662. * must specify the ban mask to remove, not just "-b".
  663. *
  664. * Note that the actual list of channel modes depends on the IRC server, and
  665. * can be bigger. If you know the popular channel modes, which aren't
  666. * mentioned here - please contact me at tim@krasnogorsk.ru
  667. *
  668. * Possible error responces for this command from the RFC1459:
  669. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  670. * - ::LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
  671. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  672. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  673. * - ::LIBIRC_RFC_ERR_KEYSET
  674. * - ::LIBIRC_RFC_ERR_UNKNOWNMODE
  675. * - ::LIBIRC_RFC_ERR_NOSUCHCHANNEL
  676. *
  677. * And the mode information is given using following reply codes:
  678. * - ::LIBIRC_RFC_RPL_CHANNELMODEIS
  679. * - ::LIBIRC_RFC_RPL_BANLIST
  680. * - ::LIBIRC_RFC_RPL_ENDOFBANLIST
  681. *
  682. * \sa irc_cmd_topic irc_cmd_list
  683. * \ingroup ircmd_ch
  684. */
  685. int irc_cmd_channel_mode (irc_session_t *session,
  686. const char *channel,
  687. const char *mode);
  688. /*!
  689. * \fn int irc_cmd_user_mode (irc_session_t * session, const char * mode)
  690. * \brief Views or changes your own user mode.
  691. *
  692. * \param session An initiated and connected session.
  693. * \param mode A user mode, described below. If NULL, the user mode is
  694. * not changed, just the old mode is returned.
  695. *
  696. * \return Return code 0 means success. Other value means error, the error
  697. * code may be obtained through irc_errno(). Any error, generated by the
  698. * IRC server, is available through irc_callbacks_t::event_numeric.
  699. *
  700. * The irc_cmd_user_mode() is used to change or view the user modes.
  701. * Note that, unlike channel modes, not all user modes can be changed.
  702. * The user mode is returned if the \a mode is NULL. If the \a mode
  703. * is not NULL, the mode for you will be changed, and new mode will be
  704. * returned.
  705. *
  706. * Like channel mode, user mode is also represended by the letters combination.
  707. * All the user mode letters are boolean (i.e. could only be set or reset),
  708. * they are set by adding a plus sign before the letter, and reset by adding
  709. * a minus sign before the letter.
  710. *
  711. * Here is the list of 'standard' user modes:
  712. *
  713. * - \a o - represents an IRC operator status. Could not be set directly (but
  714. * can be reset though), to set it use the IRC \a OPER command.
  715. *
  716. * - \a i - if set, marks a user as 'invisible' - that is, not seen by lookups
  717. * if the user is not in a channel.
  718. *
  719. * - \a w - if set, marks a user as 'receiving wallops' - special messages
  720. * generated by IRC operators using WALLOPS command.
  721. *
  722. * - \a s - if set, marks a user for receipt of server notices.
  723. *
  724. * - \a r - NON-STANDARD MODE. If set, user has been authenticated with
  725. * NICKSERV IRC service.
  726. *
  727. * - \a x - NON-STANDARD MODE. If set, user's real IP is hidden by IRC
  728. * servers, to prevent scriptkiddies to do nasty things to the user's
  729. * computer.
  730. *
  731. * Note that the actual list of user modes depends on the IRC server, and
  732. * can be bigger. If you know the popular user modes, which aren't
  733. * mentioned here - please contact me at tim@krasnogorsk.ru
  734. *
  735. * Possible error responces for this command from the RFC1459:
  736. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  737. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  738. * - ::LIBIRC_RFC_ERR_UNKNOWNMODE
  739. * - ::LIBIRC_RFC_ERR_USERSDONTMATCH
  740. * - ::LIBIRC_RFC_ERR_UMODEUNKNOWNFLAG
  741. *
  742. * And the mode information is given using reply code ::LIBIRC_RFC_RPL_UMODEIS
  743. *
  744. * \ingroup ircmd_oth
  745. */
  746. int irc_cmd_user_mode (irc_session_t *session,
  747. const char *mode);
  748. /*!
  749. * \fn int irc_cmd_nick (irc_session_t * session, const char * newnick)
  750. * \brief Changes your nick.
  751. *
  752. * \param session An initiated and connected session.
  753. * \param newnick A new nick. Must not be NULL.
  754. *
  755. * \return Return code 0 means success. Other value means error, the error
  756. * code may be obtained through irc_errno(). Any error, generated by the
  757. * IRC server, is available through irc_callbacks_t::event_numeric.
  758. *
  759. * This function is used to change your current nick to another nick. Note
  760. * that such a change is not always possible; for example you cannot change
  761. * nick to the existing nick, or (on some servers) to the registered nick.
  762. *
  763. * Possible error responces for this command from the RFC1459:
  764. * - ::LIBIRC_RFC_ERR_NONICKNAMEGIVEN
  765. * - ::LIBIRC_RFC_ERR_ERRONEUSNICKNAME
  766. * - ::LIBIRC_RFC_ERR_NICKNAMEINUSE
  767. * - ::LIBIRC_RFC_ERR_NICKCOLLISION
  768. *
  769. * \ingroup ircmd_oth
  770. */
  771. int irc_cmd_nick (irc_session_t *session,
  772. const char *newnick);
  773. /*!
  774. * \fn int irc_cmd_whois (irc_session_t * session, const char * nick)
  775. * \brief Queries the information about the nick.
  776. *
  777. * \param session An initiated and connected session.
  778. * \param nick A nick to query the information abour. Must not be NULL.
  779. * A comma-separated list of several nicknames may be given.
  780. *
  781. * \return Return code 0 means success. Other value means error, the error
  782. * code may be obtained through irc_errno(). Any error, generated by the
  783. * IRC server, is available through irc_callbacks_t::event_numeric.
  784. *
  785. * This function queries various information about the nick: username, real
  786. * name, the IRC server used, the channels user is in, idle time, away mode and so on.
  787. *
  788. * Possible error responces for this command from the RFC1459:
  789. * - ::LIBIRC_RFC_ERR_NOSUCHSERVER
  790. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  791. * - ::LIBIRC_RFC_ERR_NONICKNAMEGIVEN
  792. *
  793. * And the information is returned using the following reply codes. The whois
  794. * query is completed when ::LIBIRC_RFC_RPL_ENDOFWHOIS message is received.
  795. * - ::LIBIRC_RFC_RPL_WHOISUSER
  796. * - ::LIBIRC_RFC_RPL_WHOISCHANNELS
  797. * - ::LIBIRC_RFC_RPL_WHOISSERVER
  798. * - ::LIBIRC_RFC_RPL_AWAY
  799. * - ::LIBIRC_RFC_RPL_WHOISOPERATOR
  800. * - ::LIBIRC_RFC_RPL_WHOISIDLE
  801. * - ::LIBIRC_RFC_RPL_ENDOFWHOIS
  802. *
  803. * \ingroup ircmd_oth
  804. */
  805. int irc_cmd_whois (irc_session_t *session,
  806. const char *nick);
  807. /*!
  808. * \fn irc_cmd_msg (irc_session_t * session, const char * nch, const char * text)
  809. * \brief Sends the message to the nick or to the channel.
  810. *
  811. * \param session An initiated and connected session.
  812. * \param nch A target nick or channel. Must not be NULL.
  813. * \param text Message text. Must not be NULL.
  814. *
  815. * \return Return code 0 means success. Other value means error, the error
  816. * code may be obtained through irc_errno(). Any error, generated by the
  817. * IRC server, is available through irc_callbacks_t::event_numeric.
  818. *
  819. * This function is used to send the channel or private messages. The target
  820. * is determined by \a nch argument: if it describes nick, this will be a
  821. * private message, if a channel name - public (channel) message. Note that
  822. * depending on channel modes, you may be required to join the channel to
  823. * send the channel messages.
  824. *
  825. * Possible error responces for this command from the RFC1459:
  826. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  827. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  828. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  829. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  830. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  831. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  832. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  833. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  834. *
  835. * On success there is NOTHING generated.
  836. *
  837. * \ingroup ircmd_msg
  838. */
  839. int irc_cmd_msg (irc_session_t *session,
  840. const char *nch,
  841. const char *text);
  842. /*!
  843. * \fn int irc_cmd_me (irc_session_t * session, const char * nch, const char * text)
  844. * \brief Sends the /me (CTCP ACTION) message to the nick or to the channel.
  845. *
  846. * \param session An initiated and connected session.
  847. * \param nch A target nick or channel. Must not be NULL.
  848. * \param text Action message text. Must not be NULL.
  849. *
  850. * \return Return code 0 means success. Other value means error, the error
  851. * code may be obtained through irc_errno(). Any error, generated by the
  852. * IRC server, is available through irc_callbacks_t::event_numeric.
  853. *
  854. * This function is used to send the /me message to channel or private.
  855. * As for irc_cmd_msg, the target is determined by \a nch argument.
  856. *
  857. * Possible error responces for this command from the RFC1459:
  858. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  859. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  860. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  861. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  862. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  863. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  864. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  865. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  866. *
  867. * On success there is NOTHING generated.
  868. * However, a ::LIBIRC_RFC_RPL_AWAY reply can be also generated.
  869. *
  870. * \sa irc_cmd_msg
  871. * \ingroup ircmd_msg
  872. */
  873. int irc_cmd_me (irc_session_t *session,
  874. const char *nch,
  875. const char *text);
  876. /*!
  877. * \fn int irc_cmd_notice (irc_session_t * session, const char * nch, const char * text)
  878. * \brief Sends the notice to the nick or to the channel.
  879. *
  880. * \param session An initiated and connected session.
  881. * \param nch A target nick or channel. Must not be NULL.
  882. * \param text Notice text. Must not be NULL.
  883. *
  884. * \return Return code 0 means success. Other value means error, the error
  885. * code may be obtained through irc_errno(). Any error, generated by the
  886. * IRC server, is available through irc_callbacks_t::event_numeric.
  887. *
  888. * This function is used to send the channel or private notices. The target
  889. * is determined by \a nch argument: if it describes nick, this will be a
  890. * private message, if a channel name - public (channel) message. Note that
  891. * depending on channel modes, you may be required to join the channel to
  892. * send the channel notices.
  893. *
  894. * The only difference between message and notice is that, according to RFC
  895. * 1459, you must not automatically reply to NOTICE messages.
  896. *
  897. * Possible error responces for this command from the RFC1459:
  898. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  899. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  900. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  901. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  902. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  903. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  904. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  905. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  906. *
  907. * On success there is NOTHING generated. On notices sent to target nick,
  908. * a ::LIBIRC_RFC_RPL_AWAY reply may be generated.
  909. *
  910. * \sa irc_cmd_msg
  911. * \ingroup ircmd_msg
  912. */
  913. int irc_cmd_notice (irc_session_t *session,
  914. const char *nch,
  915. const char *text);
  916. /*!
  917. * \fn int irc_cmd_kick (irc_session_t * session, const char * nick, const char * channel, const char * reason)
  918. * \brief Kick some lazy ass out of channel.
  919. *
  920. * \param session An initiated and connected session.
  921. * \param nick A nick to kick. Must not be NULL.
  922. * \param channel A channel to kick this nick out of. Must not be NULL.
  923. * \param reason A reason to kick. May be NULL.
  924. *
  925. * \return Return code 0 means success. Other value means error, the error
  926. * code may be obtained through irc_errno(). Any error, generated by the
  927. * IRC server, is available through irc_callbacks_t::event_numeric.
  928. *
  929. * This function is used to kick a person out of channel. Note that you must
  930. * be a channel operator to kick anyone.
  931. *
  932. * Possible error responces for this command from the RFC1459:
  933. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  934. * - ::LIBIRC_RFC_ERR_BADCHANMASK
  935. * - ::LIBIRC_RFC_ERR_NOSUCHCHANNEL
  936. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  937. * - ::LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
  938. *
  939. * On success the irc_callbacks_t::event_kick event will be generated.
  940. *
  941. * \sa irc_callbacks_t::event_numeric
  942. * \ingroup ircmd_ch
  943. */
  944. int irc_cmd_kick (irc_session_t *session,
  945. const char *nick,
  946. const char *channel,
  947. const char *reason);
  948. /*!
  949. * \fn int irc_cmd_ctcp_request (irc_session_t * session, const char * nick, const char * request)
  950. * \brief Generates a CTCP request.
  951. *
  952. * \param session An initiated and connected session.
  953. * \param nick A target nick to send request to. Must not be NULL.
  954. * \param request A request string. Must not be NULL.
  955. *
  956. * \return Return code 0 means success. Other value means error, the error
  957. * code may be obtained through irc_errno(). Any error, generated by the
  958. * IRC server, is available through irc_callbacks_t::event_numeric.
  959. *
  960. * This function is used to send a CTCP request. There are four CTCP requests
  961. * supported by Mirc:
  962. * VERSION - get the client software name and version
  963. * FINGER - get the client username, host and real name.
  964. * PING - get the client delay.
  965. * TIME - get the client local time.
  966. *
  967. * A reply to the CTCP request will be sent by the irc_callbacks_t::event_ctcp_rep callback;
  968. * be sure to define it.
  969. *
  970. * Possible error responces for this command from the RFC1459:
  971. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  972. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  973. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  974. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  975. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  976. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  977. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  978. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  979. *
  980. * \sa irc_callbacks_t::event_ctcp_rep irc_callbacks_t::event_numeric
  981. * \ingroup ctcp
  982. */
  983. int irc_cmd_ctcp_request (irc_session_t *session,
  984. const char *nick,
  985. const char *request);
  986. /*!
  987. * \fn int irc_cmd_ctcp_reply (irc_session_t * session, const char * nick, const char * reply)
  988. * \brief Generates a reply to the CTCP request.
  989. *
  990. * \param session An initiated and connected session.
  991. * \param nick A target nick to send request to. Must not be NULL.
  992. * \param reply A reply string. Must not be NULL.
  993. *
  994. * \return Return code 0 means success. Other value means error, the error
  995. * code may be obtained through irc_errno(). Any error, generated by the
  996. * IRC server, is available through irc_callbacks_t::event_numeric.
  997. *
  998. * This function is used to send a reply to the CTCP request, generated by
  999. * irc_callbacks_t::event_ctcp_req. Note that you will not receive this event
  1000. * unless you specify your own handler as \c event_ctcp_req callback during
  1001. * the IRC session initialization.
  1002. *
  1003. * Possible error responces for this command from the RFC1459:
  1004. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  1005. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  1006. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  1007. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  1008. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  1009. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  1010. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  1011. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  1012. *
  1013. * \ingroup ctcp
  1014. */
  1015. int irc_cmd_ctcp_reply (irc_session_t *session,
  1016. const char *nick,
  1017. const char *reply);
  1018. /*!
  1019. * \fn void irc_target_get_nick (const char * target, char *nick, size_t size)
  1020. * \brief Gets the nick part from the target
  1021. *
  1022. * \param target A nick in common IRC server form like tim!root\@mycomain.com; cannot be NULL
  1023. * \param nick A buffer to hold the nickname.
  1024. * \param size A buffer size. If nick is longer than buffer size, it will
  1025. * be truncated.
  1026. *
  1027. * For most events IRC server returns 'origin' (i.e. the person, who
  1028. * generated this event) in i.e. "common" form, like nick!host\@domain.
  1029. * However, all the irc_cmd_* functions require just a nick.
  1030. * This function parses this origin, and gets the nick, storing it into
  1031. * user-provided buffer.
  1032. * A buffer of size 90 should be enough for most nicks :)
  1033. *
  1034. * \ingroup nnparse
  1035. */
  1036. void irc_target_get_nick (const char *target,
  1037. char *nick,
  1038. size_t size);
  1039. /*!
  1040. * \fn void irc_target_get_host (const char * target, char *nick, size_t size)
  1041. * \brief Gets the host part from the target
  1042. *
  1043. * \param target A nick in common IRC server form like tim!root\@mydomain.com
  1044. * \param nick A buffer to hold the nickname.
  1045. * \param size A buffer size. If nick is longer than buffer size, it will
  1046. * be truncated.
  1047. *
  1048. * For most events IRC server returns 'origin' (i.e. the person, who
  1049. * generated this event) in i.e. "common" form, like nick!host\@domain.
  1050. * I don't know any command, which requires host, but it may be useful :)
  1051. * This function parses this origin, and gets the host, storing it into
  1052. * user-provided buffer.
  1053. *
  1054. * \ingroup nnparse
  1055. */
  1056. void irc_target_get_host (const char *target,
  1057. char *nick,
  1058. size_t size);
  1059. /*!
  1060. * \fn int irc_dcc_chat(irc_session_t * session, void * ctx, const char * nick, irc_dcc_callback_t callback, irc_dcc_t * dccid)
  1061. * \brief Initiates a DCC CHAT.
  1062. *
  1063. * \param session An initiated and connected session.
  1064. * \param ctx A user-supplied DCC session context, which will be passed to
  1065. * the DCC callback function. May be NULL.
  1066. * \param nick A nick to DCC CHAT with.
  1067. * \param callback A DCC callback function, which will be called when
  1068. * anything is said by other party. Must not be NULL.
  1069. * \param dccid On success, DCC session ID will be stored in this var.
  1070. *
  1071. * \return Return code 0 means success. Other value means error, the error
  1072. * code may be obtained through irc_errno(). Any error, generated by the
  1073. * IRC server, is available through irc_callbacks_t::event_numeric.
  1074. *
  1075. * This function requests a DCC CHAT between you and other user. For
  1076. * newbies, DCC chat is like private chat, but it goes directly between
  1077. * two users, and bypasses IRC server. DCC CHAT request must be accepted
  1078. * by other side before you can send anything.
  1079. *
  1080. * When the chat is accepted, terminated, or some data is received, the
  1081. * callback function is called. See the details in irc_dcc_callback_t
  1082. * declaration.
  1083. *
  1084. * Possible error responces for this command from the RFC1459:
  1085. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  1086. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  1087. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  1088. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  1089. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  1090. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  1091. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  1092. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  1093. *
  1094. * \sa irc_dcc_callback_t irc_dcc_msg
  1095. * \ingroup dccstuff
  1096. */
  1097. int irc_dcc_chat (irc_session_t *session,
  1098. void *ctx,
  1099. const char *nick,
  1100. irc_dcc_callback_t
  1101. callback,
  1102. irc_dcc_t *dccid);
  1103. /*!
  1104. * \fn int irc_dcc_msg (irc_session_t * session, irc_dcc_t dccid, const char * text)
  1105. * \brief Sends the message to the specific DCC CHAT
  1106. *
  1107. * \param session An IRC session.
  1108. * \param dccid A DCC session ID, which chat request must have been accepted.
  1109. * \param text Message text. Must not be NULL.
  1110. *
  1111. * \return Return code 0 means success. Other value means error, the error
  1112. * code may be obtained through irc_errno().
  1113. *
  1114. * This function is used to send the DCC CHAT messages. DCC CHAT request
  1115. * must be initiated and accepted first (or just accepted, if initiated by
  1116. * other side).
  1117. *
  1118. * \sa irc_dcc_chat
  1119. * \ingroup dccstuff
  1120. */
  1121. int irc_dcc_msg (irc_session_t *session,
  1122. irc_dcc_t dccid,
  1123. const char *text);
  1124. /*!
  1125. * \fn int irc_dcc_accept (irc_session_t * session, irc_dcc_t dccid, void * ctx, irc_dcc_callback_t callback)
  1126. * \brief Accepts a remote DCC CHAT or DCC RECVFILE request.
  1127. *
  1128. * \param session An initiated and connected session.
  1129. * \param dccid A DCC session ID, returned by appropriate callback.
  1130. * \param ctx A user-supplied DCC session context, which will be passed
  1131. * to the DCC callback function. May be NULL.
  1132. * \param callback A DCC callback function, which will be called when
  1133. * anything is said by other party. Must not be NULL.
  1134. *
  1135. * \return Return code 0 means success. Other value means error, the error
  1136. * code may be obtained through irc_errno().
  1137. *
  1138. * This function accepts a remote DCC request - either DCC CHAT or DCC FILE.
  1139. * After the request is accepted, the supplied callback will be called,
  1140. * and you can start sending messages or receiving the file.
  1141. *
  1142. * This function should be called only after either event_dcc_chat_req or
  1143. * event_dcc_send_req events are generated, and should react to them. It is
  1144. * possible not to call irc_dcc_accept or irc_dcc_decline immediately in
  1145. * callback function - you may just return, and call it later. However, to
  1146. * prevent memory leaks, you must call either irc_dcc_decline or
  1147. * irc_dcc_accept for any incoming DCC request.
  1148. *
  1149. * \sa irc_dcc_decline event_dcc_chat_req event_dcc_send_req
  1150. * \ingroup dccstuff
  1151. */
  1152. int irc_dcc_accept (irc_session_t *session,
  1153. irc_dcc_t dccid,
  1154. void *ctx,
  1155. irc_dcc_callback_t callback);
  1156. /*!
  1157. * \fn int irc_dcc_decline (irc_session_t * session, irc_dcc_t dccid)
  1158. * \brief Declines a remote DCC CHAT or DCC RECVFILE request.
  1159. *
  1160. * \param session An initiated and connected session.
  1161. * \param dccid A DCC session ID, returned by appropriate callback.
  1162. *
  1163. * \return Return code 0 means success. Other value means error, the error
  1164. * code may be obtained through irc_errno().
  1165. *
  1166. * This function declines a remote DCC request - either DCC CHAT or DCC FILE.
  1167. *
  1168. * This function should be called only after either event_dcc_chat_req or
  1169. * event_dcc_send_req events are generated, and should react to them. It is
  1170. * possible not to call irc_dcc_accept or irc_dcc_decline immediately in
  1171. * callback function - you may just return, and call it later. However, to
  1172. * prevent memory leaks, you must call either irc_dcc_decline or
  1173. * irc_dcc_accept for any incoming DCC request.
  1174. *
  1175. * Do not use this function to close the accepted or initiated DCC session.
  1176. * Use irc_dcc_destroy instead.
  1177. *
  1178. * \sa irc_dcc_accept irc_callbacks_t::event_dcc_chat_req irc_callbacks_t::event_dcc_send_req irc_dcc_destroy
  1179. * \ingroup dccstuff
  1180. */
  1181. int irc_dcc_decline (irc_session_t *session,
  1182. irc_dcc_t dccid);
  1183. /*!
  1184. * \fn int irc_dcc_sendfile (irc_session_t * session, void * ctx, const char * nick, const char * filename, irc_dcc_callback_t callback, irc_dcc_t * dccid)
  1185. * \brief Sends a file via DCC.
  1186. *
  1187. * \param session An initiated and connected session.
  1188. * \param ctx A user-supplied DCC session context, which will be passed to
  1189. * the DCC callback function. May be NULL.
  1190. * \param nick A nick to send file via DCC to.
  1191. * \param filename A file name to sent. Must be an existing file.
  1192. * \param callback A DCC callback function, which will be called when
  1193. * file sent operation is failed, progressed or completed.
  1194. * \param dccid On success, DCC session ID will be stored in this var.
  1195. *
  1196. * \return Return code 0 means success. Other value means error, the error
  1197. * code may be obtained through irc_errno(). Any error, generated by the
  1198. * IRC server, is available through irc_callbacks_t::event_numeric.
  1199. *
  1200. * This function generates a DCC SEND request to send the file. When it is
  1201. * accepted, the file is sent to the remote party, and the DCC session is
  1202. * closed. The send operation progress and result can be checked in
  1203. * callback. See the details in irc_dcc_callback_t declaration.
  1204. *
  1205. * Possible error responces for this command from the RFC1459:
  1206. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  1207. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  1208. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  1209. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  1210. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  1211. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  1212. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  1213. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  1214. *
  1215. * \sa irc_dcc_callback_t
  1216. * \ingroup dccstuff
  1217. */
  1218. int irc_dcc_sendfile (irc_session_t *session,
  1219. void *ctx,
  1220. const char *nick,
  1221. const char *filename,
  1222. irc_dcc_callback_t callback,
  1223. irc_dcc_t *dccid);
  1224. /*!
  1225. * \fn int irc_dcc_destroy (irc_session_t * session, irc_dcc_t dccid)
  1226. * \brief Destroys a DCC session.
  1227. *
  1228. * \param session An initiated and connected session.
  1229. * \param dccid A DCC session ID.
  1230. *
  1231. * \return Return code 0 means success. Other value means error, the error
  1232. * code may be obtained through irc_errno().
  1233. *
  1234. * This function closes the DCC connection (if available), and destroys
  1235. * the DCC session, freeing the used resources. It can be called in any
  1236. * moment, even from callbacks or from different threads.
  1237. *
  1238. * Note that when DCC session is finished (either with success or failure),
  1239. * you should not destroy it - it will be destroyed automatically.
  1240. *
  1241. * \ingroup dccstuff
  1242. */
  1243. int irc_dcc_destroy (irc_session_t *session,
  1244. irc_dcc_t dccid);
  1245. /*!
  1246. * \fn void irc_get_version (unsigned int * high, unsigned int * low)
  1247. * \brief Obtains a libircclient version.
  1248. *
  1249. * \param high A pointer to receive the high version part.
  1250. * \param low A pointer to receive the low version part.
  1251. *
  1252. * This function returns the libircclient version. You can use the version either
  1253. * to check whether required options are available, or to output the version.
  1254. * The preferred printf-like format string to output the version is:
  1255. *
  1256. * printf ("Version: %d.%02d", high, low);
  1257. *
  1258. * \ingroup common
  1259. */
  1260. void irc_get_version (unsigned int *high,
  1261. unsigned int *low);
  1262. /*!
  1263. * \fn void irc_set_ctx (irc_session_t * session, void * ctx)
  1264. * \brief Sets the IRC session context.
  1265. *
  1266. * \param session An initiated session.
  1267. * \param ctx A context.
  1268. *
  1269. * This function sets the user-defined context for this IRC session. This
  1270. * context is not used by libircclient. Its purpose is to store session-specific
  1271. * user data, which may be obtained later by calling irc_get_ctx().
  1272. * Note that libircclient just 'carries out' this pointer. If you allocate some
  1273. * memory, and store its address in ctx (most common usage), it is your
  1274. * responsibility to free it before calling irc_destroy_session().
  1275. *
  1276. * \sa irc_get_ctx
  1277. * \ingroup contexts
  1278. */
  1279. void irc_set_ctx (irc_session_t *session,
  1280. void *ctx);
  1281. /*!
  1282. * \fn void irc_set_ctcp_version (irc_session_t * session, const char *version)
  1283. * \brief Sets the internal CTCP VERSION
  1284. *
  1285. * \param session an Initiated session.
  1286. * \param version the version to reply
  1287. *
  1288. * This function sets an internal user-defined version to reply on CTCP
  1289. * VERSION request. If none is given, a default one is provided. The parameter
  1290. * version is copied and can be freed by the user.
  1291. *
  1292. * \ingroup contexts
  1293. */
  1294. void irc_set_ctcp_version(irc_session_t *session,
  1295. const char *version);
  1296. /*!
  1297. * \fn void * irc_get_ctx (irc_session_t * session)
  1298. * \brief Returns the IRC session context.
  1299. *
  1300. * \param session An initiated session.
  1301. *
  1302. * This function returns the IRC session context, which was set by
  1303. * irc_set_ctx(). If no context was set, this function returns NULL.
  1304. *
  1305. * \sa irc_set_ctx
  1306. * \ingroup contexts
  1307. */
  1308. void* irc_get_ctx (irc_session_t *session);
  1309. /*!
  1310. * \fn int irc_errno (irc_session_t * session)
  1311. * \brief Returns the last error code.
  1312. *
  1313. * \param session An initiated session.
  1314. *
  1315. * This function returns the last error code associated with last operation
  1316. * of this IRC session. Possible error codes are defined in libirc_errors.h
  1317. *
  1318. * As usual, next errno rules apply:
  1319. * - irc_errno() should be called ONLY if the called function fails;
  1320. * - irc_errno() doesn't return 0 if function succeed; actually, the return
  1321. * value will be undefined.
  1322. * - you should call irc_errno() IMMEDIATELY after function fails, before
  1323. * calling any other libircclient function.
  1324. *
  1325. * \sa irc_strerror
  1326. * \ingroup errors
  1327. */
  1328. int irc_errno (irc_session_t *session);
  1329. /*!
  1330. * \fn const char * irc_strerror (int ircerrno)
  1331. * \brief Returns the text error message associated with this error code.
  1332. *
  1333. * \param ircerrno A numeric error code returned by irc_errno()
  1334. *
  1335. * This function returns the text representation of the given error code.
  1336. *
  1337. * \sa irc_errno()
  1338. * \ingroup errors
  1339. */
  1340. const char* irc_strerror (int ircerrno);
  1341. /*!
  1342. * \fn void irc_option_set (irc_session_t * session, unsigned int option)
  1343. * \brief Sets the libircclient option.
  1344. *
  1345. * \param session An initiated session.
  1346. * \param option An option from libirc_options.h
  1347. *
  1348. * This function sets the libircclient option, changing libircclient behavior. See the
  1349. * option list for the meaning for every option.
  1350. *
  1351. * \sa irc_option_reset
  1352. * \ingroup options
  1353. */
  1354. void irc_option_set (irc_session_t *session,
  1355. unsigned int option);
  1356. /*!
  1357. * \fn void irc_option_reset (irc_session_t * session, unsigned int option)
  1358. * \brief Resets the libircclient option.
  1359. *
  1360. * \param session An initiated session.
  1361. * \param option An option from libirc_options.h
  1362. *
  1363. * This function removes the previously set libircclient option, changing libircclient
  1364. * behavior. See the option list for the meaning for every option.
  1365. *
  1366. * \sa irc_option_set
  1367. * \ingroup options
  1368. */
  1369. void irc_option_reset (irc_session_t *session,
  1370. unsigned int option);
  1371. /*!
  1372. * \fn char * irc_color_strip_from_mirc (const char * message)
  1373. * \brief Removes all the color codes and format options.
  1374. *
  1375. * \param message A message from IRC
  1376. *
  1377. * \return Returns a new plain text message with stripped mIRC color codes.
  1378. * Note that the memory for the new message is allocated using malloc(), so
  1379. * you should free it using free() when it is not used anymore. If memory
  1380. * allocation failed, returns 0.
  1381. *
  1382. * \sa irc_color_convert_from_mirc irc_color_convert_to_mirc
  1383. * \ingroup colors
  1384. */
  1385. char* irc_color_strip_from_mirc (const char *message);
  1386. /*!
  1387. * \fn char * irc_color_convert_from_mirc (const char * message)
  1388. * \brief Converts all the color codes and format options to libircclient colors.
  1389. *
  1390. * \param message A message from IRC
  1391. *
  1392. * \return Returns a new message with converted mIRC color codes and format
  1393. * options. See the irc_color_convert_to_mirc() help to see how the colors
  1394. * are converted.\n
  1395. * Note that the memory for the new message is allocated using malloc(), so
  1396. * you should free it using free() when it is not used anymore. If memory
  1397. * allocation failed, returns 0.
  1398. *
  1399. * \sa irc_color_strip_from_mirc irc_color_convert_to_mirc
  1400. * \ingroup colors
  1401. */
  1402. char* irc_color_convert_from_mirc (const char *message);
  1403. /*!
  1404. * \fn char * irc_color_convert_to_mirc (const char * message)
  1405. * \brief Converts all the color codes from libircclient format to mIRC.
  1406. *
  1407. * \param message A message with color codes
  1408. *
  1409. * \return Returns a new message with converted color codes and format
  1410. * options, or 0 if memory could not be allocated. Note that the memory for
  1411. * the new message is allocated using malloc(), so you should free it using
  1412. * free() when it is not used anymore.
  1413. *
  1414. * The color system of libircclient is designed to be easy to use, and
  1415. * portable between different IRC clients. Every color or format option is
  1416. * described using plain text commands written between square brackets. The
  1417. * possible codes are:
  1418. * - [B] ... [/B] - bold format mode. Everything between [B] and [/B] is written in \b bold.
  1419. * - [I] ... [/I] - italic/reverse format mode. Everything between [I] and [/I] is written in \c italic, or reversed (however, because some clients are incapable of rendering italic text, most clients display this as normal text with the background and foreground colors swapped).
  1420. * - [U] ... [/U] - underline format mode. Everything between [U] and [/U] is written underlined.
  1421. * - [COLOR=RED] ... [/COLOR] - write the text using specified foreground color. The color is set by using the \c COLOR keyword, and equal sign followed by text color code (see below).
  1422. * - [COLOR=RED/BLUE] ... [/COLOR] - write the text using specified foreground and background color. The color is set by using the \c COLOR keyword, an equal sign followed by text foreground color code, a dash and a text background color code.
  1423. *
  1424. * The supported text colors are:
  1425. * - WHITE
  1426. * - BLACK
  1427. * - DARKBLUE
  1428. * - DARKGREEN
  1429. * - RED
  1430. * - BROWN
  1431. * - PURPLE
  1432. * - OLIVE
  1433. * - YELLOW
  1434. * - GREEN
  1435. * - TEAL
  1436. * - CYAN
  1437. * - BLUE
  1438. * - MAGENTA
  1439. * - DARKGRAY
  1440. * - LIGHTGRAY
  1441. *
  1442. * Examples of color sequences:
  1443. * \code
  1444. * Hello, [B]Tim[/B].
  1445. * [U]Arsenal[/U] got a [COLOR=RED]red card[/COLOR]
  1446. * The tree[U]s[/U] are [COLOR=GREEN/BLACK]green[/COLOR]
  1447. * \endcode
  1448. *
  1449. * \sa irc_color_strip_from_mirc irc_color_convert_from_mirc
  1450. * \ingroup colors
  1451. */
  1452. char* irc_color_convert_to_mirc (const char *message);
  1453. #ifdef __cplusplus
  1454. }
  1455. #endif
  1456. #endif /* INCLUDE_LIBIRC_H */