LibIRCClient 1.10 Used by Probotic
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
Bu depo arşivlendi. Dosyaları görüntüleyebilir ve klonlayabilirsiniz ama işlem gönderemez ve konu/değişiklik isteği açamazsınız.

1500 satır
60KB

  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, unsigned int 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, fd_set *in_set, fd_set *out_set, int * maxfd);
  331. /*!
  332. * \fn int irc_process_select_descriptors (irc_session_t * session, fd_set *in_set, fd_set *out_set)
  333. * \brief Processes the IRC socket(s), which descriptor(s) are set.
  334. *
  335. * \param session An initiated and connected session.
  336. * \param in_set A FD_IN descriptor set for select()
  337. * \param out_set A FD_OUT descriptor set for select()
  338. *
  339. * \return Return code 0 means success. Other value means error, the error
  340. * code may be obtained through irc_errno().
  341. *
  342. * This function should be used in pair with irc_add_select_descriptors
  343. * function. See irc_add_select_descriptors description.
  344. *
  345. * \sa irc_add_select_descriptors
  346. * \ingroup running
  347. */
  348. int irc_process_select_descriptors (irc_session_t * session, fd_set *in_set, fd_set *out_set);
  349. /*!
  350. * \fn int irc_send_raw (irc_session_t * session, const char * format, ...)
  351. * \brief Sends raw data to the IRC server.
  352. *
  353. * \param session An initiated and connected session.
  354. * \param format A printf-formatted string, followed by function args.
  355. *
  356. * \return Return code 0 means success. Other value means error, the error
  357. * code may be obtained through irc_errno(). Any error, generated by the
  358. * IRC server, is available through irc_callbacks_t::event_numeric.
  359. *
  360. * This function sends the raw data as-is to the IRC server. Use it to
  361. * generate a server command, which is not (yet) provided by libircclient
  362. * directly.
  363. *
  364. * \ingroup ircmd_oth
  365. */
  366. int irc_send_raw (irc_session_t * session, const char * format, ...);
  367. /*!
  368. * \fn int irc_cmd_quit (irc_session_t * session, const char * reason)
  369. * \brief Sends QUIT command to the IRC server.
  370. *
  371. * \param session An initiated and connected session.
  372. * \param reason A reason to quit. May be NULL.
  373. *
  374. * \return Return code 0 means success. Other value means error, the error
  375. * code may be obtained through irc_errno(). Any error, generated by the
  376. * IRC server, is available through irc_callbacks_t::event_numeric.
  377. *
  378. * This function sends the QUIT command to the IRC server. This command
  379. * forces the IRC server to close the IRC connection, and terminate the
  380. * session.
  381. *
  382. * \ingroup ircmd_oth
  383. */
  384. int irc_cmd_quit (irc_session_t * session, const char * reason);
  385. /*!
  386. * \fn int irc_cmd_join (irc_session_t * session, const char * channel, const char * key)
  387. * \brief Joins the new IRC channel.
  388. *
  389. * \param session An initiated and connected session.
  390. * \param channel A channel name to join to. Must not be NULL.
  391. * \param key Channel password. May be NULL.
  392. *
  393. * \return Return code 0 means success. Other value means error, the error
  394. * code may be obtained through irc_errno(). Any error, generated by the
  395. * IRC server, is available through irc_callbacks_t::event_numeric.
  396. *
  397. * This function is used to JOIN the IRC channel. If the channel is not exist,
  398. * it will be automatically created by the IRC server. Note that to JOIN the
  399. * password-protected channel, you must know the password, and specify it in
  400. * the \a key argument.
  401. *
  402. * If join is successful, the irc_callbacks_t::event_join is called (with \a origin ==
  403. * your nickname), then you are sent the channel's topic
  404. * (using ::LIBIRC_RFC_RPL_TOPIC) and the list of users who are on the
  405. * channel (using ::LIBIRC_RFC_RPL_NAMREPLY), which includes the user
  406. * joining - namely you.
  407. *
  408. * Possible error responces for this command from the RFC1459:
  409. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  410. * - ::LIBIRC_RFC_ERR_BANNEDFROMCHAN
  411. * - ::LIBIRC_RFC_ERR_INVITEONLYCHAN
  412. * - ::LIBIRC_RFC_ERR_BADCHANNELKEY
  413. * - ::LIBIRC_RFC_ERR_CHANNELISFULL
  414. * - ::LIBIRC_RFC_ERR_BADCHANMASK
  415. * - ::LIBIRC_RFC_ERR_NOSUCHCHANNEL
  416. * - ::LIBIRC_RFC_ERR_TOOMANYCHANNELS
  417. *
  418. * And on success the following replies returned:
  419. * - ::LIBIRC_RFC_RPL_TOPIC
  420. * - ::LIBIRC_RFC_RPL_NAMREPLY
  421. *
  422. * \ingroup ircmd_ch
  423. */
  424. int irc_cmd_join (irc_session_t * session, const char * channel, const char * key);
  425. /*!
  426. * \fn int irc_cmd_part (irc_session_t * session, const char * channel)
  427. * \brief Leaves the IRC channel.
  428. *
  429. * \param session An initiated and connected session.
  430. * \param channel A channel name to leave. Must not be NULL.
  431. *
  432. * \return Return code 0 means success. Other value means error, the error
  433. * code may be obtained through irc_errno(). Any error, generated by the
  434. * IRC server, is available through irc_callbacks_t::event_numeric.
  435. *
  436. * This function is used to leave the IRC channel you've already joined to.
  437. * An attempt to leave the channel you aren't in results a ::LIBIRC_RFC_ERR_NOTONCHANNEL
  438. * server error.
  439. *
  440. * Possible error responces for this command from the RFC1459:
  441. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  442. * - ::LIBIRC_RFC_ERR_NOSUCHCHANNEL
  443. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  444. *
  445. * \ingroup ircmd_ch
  446. */
  447. int irc_cmd_part (irc_session_t * session, const char * channel);
  448. /*!
  449. * \fn int irc_cmd_invite (irc_session_t * session, const char * nick, const char * channel)
  450. * \brief Invites a user to invite-only channel.
  451. *
  452. * \param session An initiated and connected session.
  453. * \param nick A nick to invite. Must not be NULL.
  454. * \param channel A channel name to invite to. Must not be NULL.
  455. *
  456. * \return Return code 0 means success. Other value means error, the error
  457. * code may be obtained through irc_errno(). Any error, generated by the
  458. * IRC server, is available through irc_callbacks_t::event_numeric.
  459. *
  460. * This function is used to invite someone to invite-only channel.
  461. * "Invite-only" is a channel mode, which restricts anyone, except invided,
  462. * to join this channel. After invitation, the user could join this channel.
  463. * The user, who is invited, will receive the irc_callbacks_t::event_invite event.
  464. * Note that you must be a channel operator to INVITE the users.
  465. *
  466. * Possible error responces for this command from the RFC1459:
  467. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  468. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  469. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  470. * - ::LIBIRC_RFC_ERR_ERR_USERONCHANNEL
  471. * - ::LIBIRC_RFC_ERR_ERR_CHANOPRIVSNEEDED
  472. *
  473. * And on success one of the following replies returned:
  474. * - ::LIBIRC_RFC_RPL_INVITING
  475. * - ::LIBIRC_RFC_RPL_AWAY
  476. *
  477. * \sa irc_callbacks_t::event_invite irc_cmd_channel_mode
  478. * \ingroup ircmd_ch
  479. */
  480. int irc_cmd_invite (irc_session_t * session, const char * nick, const char * channel);
  481. /*!
  482. * \fn int irc_cmd_names (irc_session_t * session, const char * channel)
  483. * \brief Obtains a list of users who're in channel.
  484. *
  485. * \param session An initiated and connected session.
  486. * \param channel A channel name(s) to obtain user list. Must not be NULL.
  487. * It is possible to specify more than a single channel, but
  488. * several channel names should be separated by a comma.
  489. *
  490. * \return Return code 0 means success. Other value means error, the error
  491. * code may be obtained through irc_errno(). Any error, generated by the
  492. * IRC server, is available through irc_callbacks_t::event_numeric.
  493. *
  494. * This function is used to ask the IRC server for the list of the users
  495. * who're in specified channel. You can list all nicknames that are visible
  496. * to you on any channel that you can see. The list of users will be returned
  497. * using ::RPL_NAMREPLY and ::RPL_ENDOFNAMES numeric codes.
  498. *
  499. * The channel names are returned by irc_callbacks_t::event_numeric
  500. * using the following reply codes:
  501. * - ::LIBIRC_RFC_RPL_NAMREPLY
  502. * - ::LIBIRC_RFC_RPL_ENDOFNAMES
  503. *
  504. * \ingroup ircmd_ch
  505. */
  506. int irc_cmd_names (irc_session_t * session, const char * channel);
  507. /*!
  508. * \fn int irc_cmd_list (irc_session_t * session, const char * channel)
  509. * \brief Obtains a list of active server channels with their topics.
  510. *
  511. * \param session An initiated and connected session.
  512. * \param channel A channel name(s) to list. May be NULL, in which case all the
  513. * channels will be listed. It is possible to specify more than
  514. * a single channel, but several channel names should be
  515. * separated by a comma.
  516. *
  517. * \return Return code 0 means success. Other value means error, the error
  518. * code may be obtained through irc_errno(). Any error, generated by the
  519. * IRC server, is available through irc_callbacks_t::event_numeric.
  520. *
  521. * This function is used to ask the IRC server for the active (existing)
  522. * channels list. The list will be returned using ::LIBIRC_RFC_RPL_LISTSTART -
  523. * ::LIBIRC_RFC_RPL_LIST - ::LIBIRC_RFC_RPL_LISTEND sequence.
  524. * Note that "private" channels are listed (without their topics) as channel
  525. * "Prv" unless the client generating the LIST query is actually on that
  526. * channel. Likewise, secret channels are
  527. * not listed at all unless the client is a member of the channel in question.
  528. *
  529. * Possible error responces for this command from the RFC1459:
  530. * - ::LIBIRC_RFC_ERR_NOSUCHSERVER
  531. *
  532. * And the channel list is returned using the following reply codes:
  533. * - ::LIBIRC_RFC_RPL_LISTSTART
  534. * - ::LIBIRC_RFC_RPL_LISTEND
  535. * - ::LIBIRC_RFC_RPL_LIST
  536. *
  537. * \ingroup ircmd_ch
  538. */
  539. int irc_cmd_list (irc_session_t * session, const char * channel);
  540. /*!
  541. * \fn int irc_cmd_topic (irc_session_t * session, const char * channel, const char * topic)
  542. * \brief Views or changes the channel topic.
  543. *
  544. * \param session An initiated and connected session.
  545. * \param channel A channel name to invite to. Must not be NULL.
  546. * \param topic A new topic to change. If NULL, the old topic will be
  547. * returned, and topic won't changed.
  548. *
  549. * \return Return code 0 means success. Other value means error, the error
  550. * code may be obtained through irc_errno(). Any error, generated by the
  551. * IRC server, is available through irc_callbacks_t::event_numeric.
  552. *
  553. * The irc_cmd_topic() is used to change or view the topic of a channel.
  554. * The topic for \a channel is returned if \a topic is NULL. If the \a topic
  555. * is not NULL, the topic for the \a channel will be changed. Note that,
  556. * depending on \a +t channel mode, you may be required to be a channel
  557. * operator to change the channel topic.
  558. *
  559. * If the command succeed, the IRC server will generate a ::RPL_NOTOPIC or
  560. * ::RPL_TOPIC message, containing either old or changed topic. Also the IRC
  561. * server can (but not have to) generate the non-RFC ::RPL_TOPIC_EXTRA message,
  562. * containing the nick of person, who's changed the topic, and the time of
  563. * latest topic change.
  564. *
  565. * Possible error responces for this command from the RFC1459:
  566. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  567. * - ::LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
  568. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  569. *
  570. * And the topic information is returned using one of following reply codes:
  571. * - ::LIBIRC_RFC_RPL_NOTOPIC
  572. * - ::LIBIRC_RFC_RPL_TOPIC
  573. *
  574. * \sa irc_callbacks_t::event_topic irc_cmd_channel_mode
  575. * \ingroup ircmd_ch
  576. */
  577. int irc_cmd_topic (irc_session_t * session, const char * channel, const char * topic);
  578. /*!
  579. * \fn int irc_cmd_channel_mode (irc_session_t * session, const char * channel, const char * mode)
  580. * \brief Views or changes the channel mode.
  581. *
  582. * \param session An initiated and connected session.
  583. * \param channel A channel name to invite to. Must not be NULL.
  584. * \param mode A channel mode, described below. If NULL, the channel mode is
  585. * not changed, just the old mode is returned.
  586. *
  587. * \return Return code 0 means success. Other value means error, the error
  588. * code may be obtained through irc_errno(). Any error, generated by the
  589. * IRC server, is available through irc_callbacks_t::event_numeric.
  590. *
  591. * The irc_cmd_channel_mode() is used to change or view the channel modes.
  592. * The \a channel mode is returned if the \a mode is NULL. If the \a mode
  593. * is not NULL, the mode for the \a channel will be changed. Note that,
  594. * only channel operators can change the channel modes.
  595. *
  596. * Channel mode is represended by the letters combination. Every letter has
  597. * its own meaning in channel modes. Most channel mode letters are boolean
  598. * (i.e. could only be set or reset), but a few channel mode letters accept a
  599. * parameter. All channel options are set by adding a plus sign before the
  600. * letter, and reset by adding a minus sign before the letter.
  601. *
  602. * Here is the list of 'standard' channel modes:
  603. *
  604. * - \a o \a nickname - gives (+o nick) or takes (-o nick) the channel
  605. * operator privileges from a \a nickname. This mode affects the
  606. * users in channel, not the channel itself.
  607. * Examples: "+o tim", "-o watson".
  608. *
  609. * - \a p - sets (+p) or resets (-p) private channel flag.
  610. * Private channels are shown in channel list as 'Prv', without the topic.
  611. *
  612. * - \a s - sets (+p) or resets (-p) secret channel flag.
  613. * Secret channels aren't shown in channel list at all.
  614. *
  615. * - \a i - sets (+i) or resets (-i) invite-only channel flag. When the flag
  616. * is set, only the people who are invited by irc_cmd_invite(), can
  617. * join this channel.
  618. *
  619. * - \a t - sets (+t) or resets (-t) topic settable by channel operator only
  620. * flag. When the flag is set, only the channel operators can change the
  621. * channel topic.
  622. *
  623. * - \a n - sets (+n) or resets (-n) the protection from the clients outside
  624. * the channel. When the \a +n mode is set, only the clients, who are in
  625. * channel, can send the messages to the channel.
  626. *
  627. * - \a m - sets (+m) or resets (-m) the moderation of the channel. When the
  628. * moderation mode is set, only channel operators and the users who have
  629. * the \a +v user mode can speak in the channel.
  630. *
  631. * - \a v \a nickname - gives (+v nick) or takes (-v nick) from user the
  632. * ability to speak on a moderated channel.
  633. * Examples: "+v tim", "-v watson".
  634. *
  635. * - \a l \a number - sets (+l 20) or removes (-l) the restriction of maximum
  636. * users in channel. When the restriction is set, and there is a number
  637. * of users in the channel, no one can join the channel anymore.
  638. *
  639. * - \a k \a key - sets (+k secret) or removes (-k) the password from the
  640. * channel. When the restriction is set, any user joining the channel
  641. * required to provide a channel key.
  642. *
  643. * - \a b \a mask - sets (+b *!*@*.mil) or removes (-b *!*@*.mil) the ban mask
  644. * on a user to keep him out of channel. Note that to remove the ban you
  645. * must specify the ban mask to remove, not just "-b".
  646. *
  647. * Note that the actual list of channel modes depends on the IRC server, and
  648. * can be bigger. If you know the popular channel modes, which aren't
  649. * mentioned here - please contact me at tim@krasnogorsk.ru
  650. *
  651. * Possible error responces for this command from the RFC1459:
  652. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  653. * - ::LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
  654. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  655. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  656. * - ::LIBIRC_RFC_ERR_KEYSET
  657. * - ::LIBIRC_RFC_ERR_UNKNOWNMODE
  658. * - ::LIBIRC_RFC_ERR_NOSUCHCHANNEL
  659. *
  660. * And the mode information is given using following reply codes:
  661. * - ::LIBIRC_RFC_RPL_CHANNELMODEIS
  662. * - ::LIBIRC_RFC_RPL_BANLIST
  663. * - ::LIBIRC_RFC_RPL_ENDOFBANLIST
  664. *
  665. * \sa irc_cmd_topic irc_cmd_list
  666. * \ingroup ircmd_ch
  667. */
  668. int irc_cmd_channel_mode (irc_session_t * session, const char * channel, const char * mode);
  669. /*!
  670. * \fn int irc_cmd_user_mode (irc_session_t * session, const char * mode)
  671. * \brief Views or changes your own user mode.
  672. *
  673. * \param session An initiated and connected session.
  674. * \param mode A user mode, described below. If NULL, the user mode is
  675. * not changed, just the old mode is returned.
  676. *
  677. * \return Return code 0 means success. Other value means error, the error
  678. * code may be obtained through irc_errno(). Any error, generated by the
  679. * IRC server, is available through irc_callbacks_t::event_numeric.
  680. *
  681. * The irc_cmd_user_mode() is used to change or view the user modes.
  682. * Note that, unlike channel modes, not all user modes can be changed.
  683. * The user mode is returned if the \a mode is NULL. If the \a mode
  684. * is not NULL, the mode for you will be changed, and new mode will be
  685. * returned.
  686. *
  687. * Like channel mode, user mode is also represended by the letters combination.
  688. * All the user mode letters are boolean (i.e. could only be set or reset),
  689. * they are set by adding a plus sign before the letter, and reset by adding
  690. * a minus sign before the letter.
  691. *
  692. * Here is the list of 'standard' user modes:
  693. *
  694. * - \a o - represents an IRC operator status. Could not be set directly (but
  695. * can be reset though), to set it use the IRC \a OPER command.
  696. *
  697. * - \a i - if set, marks a user as 'invisible' - that is, not seen by lookups
  698. * if the user is not in a channel.
  699. *
  700. * - \a w - if set, marks a user as 'receiving wallops' - special messages
  701. * generated by IRC operators using WALLOPS command.
  702. *
  703. * - \a s - if set, marks a user for receipt of server notices.
  704. *
  705. * - \a r - NON-STANDARD MODE. If set, user has been authenticated with
  706. * NICKSERV IRC service.
  707. *
  708. * - \a x - NON-STANDARD MODE. If set, user's real IP is hidden by IRC
  709. * servers, to prevent scriptkiddies to do nasty things to the user's
  710. * computer.
  711. *
  712. * Note that the actual list of user modes depends on the IRC server, and
  713. * can be bigger. If you know the popular user modes, which aren't
  714. * mentioned here - please contact me at tim@krasnogorsk.ru
  715. *
  716. * Possible error responces for this command from the RFC1459:
  717. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  718. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  719. * - ::LIBIRC_RFC_ERR_UNKNOWNMODE
  720. * - ::LIBIRC_RFC_ERR_USERSDONTMATCH
  721. * - ::LIBIRC_RFC_ERR_UMODEUNKNOWNFLAG
  722. *
  723. * And the mode information is given using reply code ::LIBIRC_RFC_RPL_UMODEIS
  724. *
  725. * \ingroup ircmd_oth
  726. */
  727. int irc_cmd_user_mode (irc_session_t * session, const char * mode);
  728. /*!
  729. * \fn int irc_cmd_nick (irc_session_t * session, const char * newnick)
  730. * \brief Changes your nick.
  731. *
  732. * \param session An initiated and connected session.
  733. * \param newnick A new nick. Must not be NULL.
  734. *
  735. * \return Return code 0 means success. Other value means error, the error
  736. * code may be obtained through irc_errno(). Any error, generated by the
  737. * IRC server, is available through irc_callbacks_t::event_numeric.
  738. *
  739. * This function is used to change your current nick to another nick. Note
  740. * that such a change is not always possible; for example you cannot change
  741. * nick to the existing nick, or (on some servers) to the registered nick.
  742. *
  743. * Possible error responces for this command from the RFC1459:
  744. * - ::LIBIRC_RFC_ERR_NONICKNAMEGIVEN
  745. * - ::LIBIRC_RFC_ERR_ERRONEUSNICKNAME
  746. * - ::LIBIRC_RFC_ERR_NICKNAMEINUSE
  747. * - ::LIBIRC_RFC_ERR_NICKCOLLISION
  748. *
  749. * \ingroup ircmd_oth
  750. */
  751. int irc_cmd_nick (irc_session_t * session, const char * newnick);
  752. /*!
  753. * \fn int irc_cmd_whois (irc_session_t * session, const char * nick)
  754. * \brief Queries the information about the nick.
  755. *
  756. * \param session An initiated and connected session.
  757. * \param nick A nick to query the information abour. Must not be NULL.
  758. * A comma-separated list of several nicknames may be given.
  759. *
  760. * \return Return code 0 means success. Other value means error, the error
  761. * code may be obtained through irc_errno(). Any error, generated by the
  762. * IRC server, is available through irc_callbacks_t::event_numeric.
  763. *
  764. * This function queries various information about the nick: username, real
  765. * name, the IRC server used, the channels user is in, idle time, away mode and so on.
  766. *
  767. * Possible error responces for this command from the RFC1459:
  768. * - ::LIBIRC_RFC_ERR_NOSUCHSERVER
  769. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  770. * - ::LIBIRC_RFC_ERR_NONICKNAMEGIVEN
  771. *
  772. * And the information is returned using the following reply codes. The whois
  773. * query is completed when ::LIBIRC_RFC_RPL_ENDOFWHOIS message is received.
  774. * - ::LIBIRC_RFC_RPL_WHOISUSER
  775. * - ::LIBIRC_RFC_RPL_WHOISCHANNELS
  776. * - ::LIBIRC_RFC_RPL_WHOISSERVER
  777. * - ::LIBIRC_RFC_RPL_AWAY
  778. * - ::LIBIRC_RFC_RPL_WHOISOPERATOR
  779. * - ::LIBIRC_RFC_RPL_WHOISIDLE
  780. * - ::LIBIRC_RFC_RPL_ENDOFWHOIS
  781. *
  782. * \ingroup ircmd_oth
  783. */
  784. int irc_cmd_whois (irc_session_t * session, const char * nick);
  785. /*!
  786. * \fn irc_cmd_msg (irc_session_t * session, const char * nch, const char * text)
  787. * \brief Sends the message to the nick or to the channel.
  788. *
  789. * \param session An initiated and connected session.
  790. * \param nch A target nick or channel. Must not be NULL.
  791. * \param text Message text. Must not be NULL.
  792. *
  793. * \return Return code 0 means success. Other value means error, the error
  794. * code may be obtained through irc_errno(). Any error, generated by the
  795. * IRC server, is available through irc_callbacks_t::event_numeric.
  796. *
  797. * This function is used to send the channel or private messages. The target
  798. * is determined by \a nch argument: if it describes nick, this will be a
  799. * private message, if a channel name - public (channel) message. Note that
  800. * depending on channel modes, you may be required to join the channel to
  801. * send the channel messages.
  802. *
  803. * Possible error responces for this command from the RFC1459:
  804. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  805. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  806. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  807. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  808. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  809. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  810. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  811. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  812. *
  813. * On success there is NOTHING generated.
  814. *
  815. * \ingroup ircmd_msg
  816. */
  817. int irc_cmd_msg (irc_session_t * session, const char * nch, const char * text);
  818. /*!
  819. * \fn int irc_cmd_me (irc_session_t * session, const char * nch, const char * text)
  820. * \brief Sends the /me (CTCP ACTION) message to the nick or to the channel.
  821. *
  822. * \param session An initiated and connected session.
  823. * \param nch A target nick or channel. Must not be NULL.
  824. * \param text Action message text. Must not be NULL.
  825. *
  826. * \return Return code 0 means success. Other value means error, the error
  827. * code may be obtained through irc_errno(). Any error, generated by the
  828. * IRC server, is available through irc_callbacks_t::event_numeric.
  829. *
  830. * This function is used to send the /me message to channel or private.
  831. * As for irc_cmd_msg, the target is determined by \a nch argument.
  832. *
  833. * Possible error responces for this command from the RFC1459:
  834. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  835. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  836. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  837. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  838. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  839. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  840. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  841. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  842. *
  843. * On success there is NOTHING generated.
  844. * However, a ::LIBIRC_RFC_RPL_AWAY reply can be also generated.
  845. *
  846. * \sa irc_cmd_msg
  847. * \ingroup ircmd_msg
  848. */
  849. int irc_cmd_me (irc_session_t * session, const char * nch, const char * text);
  850. /*!
  851. * \fn int irc_cmd_notice (irc_session_t * session, const char * nch, const char * text)
  852. * \brief Sends the notice to the nick or to the channel.
  853. *
  854. * \param session An initiated and connected session.
  855. * \param nch A target nick or channel. Must not be NULL.
  856. * \param text Notice text. Must not be NULL.
  857. *
  858. * \return Return code 0 means success. Other value means error, the error
  859. * code may be obtained through irc_errno(). Any error, generated by the
  860. * IRC server, is available through irc_callbacks_t::event_numeric.
  861. *
  862. * This function is used to send the channel or private notices. The target
  863. * is determined by \a nch argument: if it describes nick, this will be a
  864. * private message, if a channel name - public (channel) message. Note that
  865. * depending on channel modes, you may be required to join the channel to
  866. * send the channel notices.
  867. *
  868. * The only difference between message and notice is that, according to RFC
  869. * 1459, you must not automatically reply to NOTICE messages.
  870. *
  871. * Possible error responces for this command from the RFC1459:
  872. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  873. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  874. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  875. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  876. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  877. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  878. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  879. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  880. *
  881. * On success there is NOTHING generated. On notices sent to target nick,
  882. * a ::LIBIRC_RFC_RPL_AWAY reply may be generated.
  883. *
  884. * \sa irc_cmd_msg
  885. * \ingroup ircmd_msg
  886. */
  887. int irc_cmd_notice (irc_session_t * session, const char * nch, const char * text);
  888. /*!
  889. * \fn int irc_cmd_kick (irc_session_t * session, const char * nick, const char * channel, const char * reason)
  890. * \brief Kick some lazy ass out of channel.
  891. *
  892. * \param session An initiated and connected session.
  893. * \param nick A nick to kick. Must not be NULL.
  894. * \param channel A channel to kick this nick out of. Must not be NULL.
  895. * \param reason A reason to kick. May be NULL.
  896. *
  897. * \return Return code 0 means success. Other value means error, the error
  898. * code may be obtained through irc_errno(). Any error, generated by the
  899. * IRC server, is available through irc_callbacks_t::event_numeric.
  900. *
  901. * This function is used to kick a person out of channel. Note that you must
  902. * be a channel operator to kick anyone.
  903. *
  904. * Possible error responces for this command from the RFC1459:
  905. * - ::LIBIRC_RFC_ERR_NEEDMOREPARAMS
  906. * - ::LIBIRC_RFC_ERR_BADCHANMASK
  907. * - ::LIBIRC_RFC_ERR_NOSUCHCHANNEL
  908. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  909. * - ::LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
  910. *
  911. * On success the irc_callbacks_t::event_kick event will be generated.
  912. *
  913. * \sa irc_callbacks_t::event_numeric
  914. * \ingroup ircmd_ch
  915. */
  916. int irc_cmd_kick (irc_session_t * session, const char * nick, const char * channel, const char * reason);
  917. /*!
  918. * \fn int irc_cmd_ctcp_request (irc_session_t * session, const char * nick, const char * request)
  919. * \brief Generates a CTCP request.
  920. *
  921. * \param session An initiated and connected session.
  922. * \param nick A target nick to send request to. Must not be NULL.
  923. * \param request A request string. Must not 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 send a CTCP request. There are four CTCP requests
  930. * supported by Mirc:
  931. * VERSION - get the client software name and version
  932. * FINGER - get the client username, host and real name.
  933. * PING - get the client delay.
  934. * TIME - get the client local time.
  935. *
  936. * A reply to the CTCP request will be sent by the irc_callbacks_t::event_ctcp_rep callback;
  937. * be sure to define it.
  938. *
  939. * Possible error responces for this command from the RFC1459:
  940. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  941. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  942. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  943. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  944. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  945. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  946. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  947. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  948. *
  949. * \sa irc_callbacks_t::event_ctcp_rep irc_callbacks_t::event_numeric
  950. * \ingroup ctcp
  951. */
  952. int irc_cmd_ctcp_request (irc_session_t * session, const char * nick, const char * request);
  953. /*!
  954. * \fn int irc_cmd_ctcp_reply (irc_session_t * session, const char * nick, const char * reply)
  955. * \brief Generates a reply to the CTCP request.
  956. *
  957. * \param session An initiated and connected session.
  958. * \param nick A target nick to send request to. Must not be NULL.
  959. * \param reply A reply string. Must not be NULL.
  960. *
  961. * \return Return code 0 means success. Other value means error, the error
  962. * code may be obtained through irc_errno(). Any error, generated by the
  963. * IRC server, is available through irc_callbacks_t::event_numeric.
  964. *
  965. * This function is used to send a reply to the CTCP request, generated by
  966. * irc_callbacks_t::event_ctcp_req. Note that you will not receive this event
  967. * unless you specify your own handler as \c event_ctcp_req callback during
  968. * the IRC session initialization.
  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. * \ingroup ctcp
  981. */
  982. int irc_cmd_ctcp_reply (irc_session_t * session, const char * nick, const char * reply);
  983. /*!
  984. * \fn void irc_target_get_nick (const char * target, char *nick, size_t size)
  985. * \brief Gets the nick part from the target
  986. *
  987. * \param target A nick in common IRC server form like tim!root\@mycomain.com; cannot be NULL
  988. * \param nick A buffer to hold the nickname.
  989. * \param size A buffer size. If nick is longer than buffer size, it will
  990. * be truncated.
  991. *
  992. * For most events IRC server returns 'origin' (i.e. the person, who
  993. * generated this event) in i.e. "common" form, like nick!host\@domain.
  994. * However, all the irc_cmd_* functions require just a nick/
  995. * This function parses this origin, and gets the nick, storing it into
  996. * user-provided buffer.
  997. * A buffer of size 90 should be enough for most nicks :)
  998. *
  999. * \ingroup nnparse
  1000. */
  1001. void irc_target_get_nick (const char * target, char *nick, size_t size);
  1002. /*!
  1003. * \fn void irc_target_get_host (const char * target, char *nick, size_t size)
  1004. * \brief Gets the host part from the target
  1005. *
  1006. * \param target A nick in common IRC server form like tim!root\@mydomain.com
  1007. * \param nick A buffer to hold the nickname.
  1008. * \param size A buffer size. If nick is longer than buffer size, it will
  1009. * be truncated.
  1010. *
  1011. * For most events IRC server returns 'origin' (i.e. the person, who
  1012. * generated this event) in i.e. "common" form, like nick!host\@domain.
  1013. * I don't know any command, which requires host, but it may be useful :)
  1014. * This function parses this origin, and gets the host, storing it into
  1015. * user-provided buffer.
  1016. *
  1017. * \ingroup nnparse
  1018. */
  1019. void irc_target_get_host (const char * target, char *nick, size_t size);
  1020. /*!
  1021. * \fn int irc_dcc_chat(irc_session_t * session, void * ctx, const char * nick, irc_dcc_callback_t callback, irc_dcc_t * dccid)
  1022. * \brief Initiates a DCC CHAT.
  1023. *
  1024. * \param session An initiated and connected session.
  1025. * \param ctx A user-supplied DCC session context, which will be passed to
  1026. * the DCC callback function. May be NULL.
  1027. * \param nick A nick to DCC CHAT with.
  1028. * \param callback A DCC callback function, which will be called when
  1029. * anything is said by other party. Must not be NULL.
  1030. * \param dccid On success, DCC session ID will be stored in this var.
  1031. *
  1032. * \return Return code 0 means success. Other value means error, the error
  1033. * code may be obtained through irc_errno(). Any error, generated by the
  1034. * IRC server, is available through irc_callbacks_t::event_numeric.
  1035. *
  1036. * This function requests a DCC CHAT between you and other user. For
  1037. * newbies, DCC chat is like private chat, but it goes directly between
  1038. * two users, and bypasses IRC server. DCC CHAT request must be accepted
  1039. * by other side before you can send anything.
  1040. *
  1041. * When the chat is accepted, terminated, or some data is received, the
  1042. * callback function is called. See the details in irc_dcc_callback_t
  1043. * declaration.
  1044. *
  1045. * Possible error responces for this command from the RFC1459:
  1046. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  1047. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  1048. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  1049. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  1050. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  1051. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  1052. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  1053. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  1054. *
  1055. * \sa irc_dcc_callback_t irc_dcc_msg
  1056. * \ingroup dccstuff
  1057. */
  1058. int irc_dcc_chat (irc_session_t * session, void * ctx, const char * nick, irc_dcc_callback_t callback, irc_dcc_t * dccid);
  1059. /*!
  1060. * \fn int irc_dcc_msg (irc_session_t * session, irc_dcc_t dccid, const char * text)
  1061. * \brief Sends the message to the specific DCC CHAT
  1062. *
  1063. * \param session An IRC session.
  1064. * \param dccid A DCC session ID, which chat request must have been accepted.
  1065. * \param text Message text. Must not be NULL.
  1066. *
  1067. * \return Return code 0 means success. Other value means error, the error
  1068. * code may be obtained through irc_errno().
  1069. *
  1070. * This function is used to send the DCC CHAT messages. DCC CHAT request
  1071. * must be initiated and accepted first (or just accepted, if initiated by
  1072. * other side).
  1073. *
  1074. * \sa irc_dcc_chat
  1075. * \ingroup dccstuff
  1076. */
  1077. int irc_dcc_msg (irc_session_t * session, irc_dcc_t dccid, const char * text);
  1078. /*!
  1079. * \fn int irc_dcc_accept (irc_session_t * session, irc_dcc_t dccid, void * ctx, irc_dcc_callback_t callback)
  1080. * \brief Accepts a remote DCC CHAT or DCC RECVFILE request.
  1081. *
  1082. * \param session An initiated and connected session.
  1083. * \param dccid A DCC session ID, returned by appropriate callback.
  1084. * \param ctx A user-supplied DCC session context, which will be passed
  1085. * to the DCC callback function. May be NULL.
  1086. * \param callback A DCC callback function, which will be called when
  1087. * anything is said by other party. Must not be NULL.
  1088. *
  1089. * \return Return code 0 means success. Other value means error, the error
  1090. * code may be obtained through irc_errno().
  1091. *
  1092. * This function accepts a remote DCC request - either DCC CHAT or DCC FILE.
  1093. * After the request is accepted, the supplied callback will be called,
  1094. * and you can start sending messages or receiving the file.
  1095. *
  1096. * This function should be called only after either event_dcc_chat_req or
  1097. * event_dcc_send_req events are generated, and should react to them. It is
  1098. * possible not to call irc_dcc_accept or irc_dcc_decline immediately in
  1099. * callback function - you may just return, and call it later. However, to
  1100. * prevent memory leaks, you must call either irc_dcc_decline or
  1101. * irc_dcc_accept for any incoming DCC request.
  1102. *
  1103. * \sa irc_dcc_decline event_dcc_chat_req event_dcc_send_req
  1104. * \ingroup dccstuff
  1105. */
  1106. int irc_dcc_accept (irc_session_t * session, irc_dcc_t dccid, void * ctx, irc_dcc_callback_t callback);
  1107. /*!
  1108. * \fn int irc_dcc_decline (irc_session_t * session, irc_dcc_t dccid)
  1109. * \brief Declines a remote DCC CHAT or DCC RECVFILE request.
  1110. *
  1111. * \param session An initiated and connected session.
  1112. * \param dccid A DCC session ID, returned by appropriate callback.
  1113. *
  1114. * \return Return code 0 means success. Other value means error, the error
  1115. * code may be obtained through irc_errno().
  1116. *
  1117. * This function declines a remote DCC request - either DCC CHAT or DCC FILE.
  1118. *
  1119. * This function should be called only after either event_dcc_chat_req or
  1120. * event_dcc_send_req events are generated, and should react to them. It is
  1121. * possible not to call irc_dcc_accept or irc_dcc_decline immediately in
  1122. * callback function - you may just return, and call it later. However, to
  1123. * prevent memory leaks, you must call either irc_dcc_decline or
  1124. * irc_dcc_accept for any incoming DCC request.
  1125. *
  1126. * Do not use this function to close the accepted or initiated DCC session.
  1127. * Use irc_dcc_destroy instead.
  1128. *
  1129. * \sa irc_dcc_accept irc_callbacks_t::event_dcc_chat_req irc_callbacks_t::event_dcc_send_req irc_dcc_destroy
  1130. * \ingroup dccstuff
  1131. */
  1132. int irc_dcc_decline (irc_session_t * session, irc_dcc_t dccid);
  1133. /*!
  1134. * \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)
  1135. * \brief Sends a file via DCC.
  1136. *
  1137. * \param session An initiated and connected session.
  1138. * \param ctx A user-supplied DCC session context, which will be passed to
  1139. * the DCC callback function. May be NULL.
  1140. * \param nick A nick to send file via DCC to.
  1141. * \param filename A file name to sent. Must be an existing file.
  1142. * \param callback A DCC callback function, which will be called when
  1143. * file sent operation is failed, progressed or completed.
  1144. * \param dccid On success, DCC session ID will be stored in this var.
  1145. *
  1146. * \return Return code 0 means success. Other value means error, the error
  1147. * code may be obtained through irc_errno(). Any error, generated by the
  1148. * IRC server, is available through irc_callbacks_t::event_numeric.
  1149. *
  1150. * This function generates a DCC SEND request to send the file. When it is
  1151. * accepted, the file is sent to the remote party, and the DCC session is
  1152. * closed. The send operation progress and result can be checked in
  1153. * callback. See the details in irc_dcc_callback_t declaration.
  1154. *
  1155. * Possible error responces for this command from the RFC1459:
  1156. * - ::LIBIRC_RFC_ERR_NORECIPIENT
  1157. * - ::LIBIRC_RFC_ERR_NOTEXTTOSEND
  1158. * - ::LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  1159. * - ::LIBIRC_RFC_ERR_NOTONCHANNEL
  1160. * - ::LIBIRC_RFC_ERR_NOTOPLEVEL
  1161. * - ::LIBIRC_RFC_ERR_WILDTOPLEVEL
  1162. * - ::LIBIRC_RFC_ERR_TOOMANYTARGETS
  1163. * - ::LIBIRC_RFC_ERR_NOSUCHNICK
  1164. *
  1165. * \sa irc_dcc_callback_t
  1166. * \ingroup dccstuff
  1167. */
  1168. 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);
  1169. /*!
  1170. * \fn int irc_dcc_destroy (irc_session_t * session, irc_dcc_t dccid)
  1171. * \brief Destroys a DCC session.
  1172. *
  1173. * \param session An initiated and connected session.
  1174. * \param dccid A DCC session ID.
  1175. *
  1176. * \return Return code 0 means success. Other value means error, the error
  1177. * code may be obtained through irc_errno().
  1178. *
  1179. * This function closes the DCC connection (if available), and destroys
  1180. * the DCC session, freeing the used resources. It can be called in any
  1181. * moment, even from callbacks or from different threads.
  1182. *
  1183. * Note that when DCC session is finished (either with success or failure),
  1184. * you should not destroy it - it will be destroyed automatically.
  1185. *
  1186. * \ingroup dccstuff
  1187. */
  1188. int irc_dcc_destroy (irc_session_t * session, irc_dcc_t dccid);
  1189. /*!
  1190. * \fn void irc_get_version (unsigned int * high, unsigned int * low)
  1191. * \brief Obtains a libircclient version.
  1192. *
  1193. * \param high A pointer to receive the high version part.
  1194. * \param low A pointer to receive the low version part.
  1195. *
  1196. * This function returns the libircclient version. You can use the version either
  1197. * to check whether required options are available, or to output the version.
  1198. * The preferred printf-like format string to output the version is:
  1199. *
  1200. * printf ("Version: %d.%02d", high, low);
  1201. *
  1202. * \ingroup common
  1203. */
  1204. void irc_get_version (unsigned int * high, unsigned int * low);
  1205. /*!
  1206. * \fn void irc_set_ctx (irc_session_t * session, void * ctx)
  1207. * \brief Sets the IRC session context.
  1208. *
  1209. * \param session An initiated session.
  1210. * \param ctx A context.
  1211. *
  1212. * This function sets the user-defined context for this IRC session. This
  1213. * context is not used by libircclient. Its purpose is to store session-specific
  1214. * user data, which may be obtained later by calling irc_get_ctx().
  1215. * Note that libircclient just 'carries out' this pointer. If you allocate some
  1216. * memory, and store its address in ctx (most common usage), it is your
  1217. * responsibility to free it before calling irc_destroy_session().
  1218. *
  1219. * \sa irc_get_ctx
  1220. * \ingroup contexts
  1221. */
  1222. void irc_set_ctx (irc_session_t * session, void * ctx);
  1223. /*!
  1224. * \fn void irc_set_ctcp_version (irc_session_t * session, const char *version)
  1225. * \brief Sets the internal CTCP VERSION
  1226. *
  1227. * \param session an Initiated session.
  1228. * \param version the version to reply
  1229. *
  1230. * This function sets an internal user-defined version to reply on CTCP
  1231. * VERSION request. If none is given, a default one is provided. The parameter
  1232. * version is copied and can be freed by the user.
  1233. *
  1234. * \ingroup contexts
  1235. */
  1236. void irc_set_ctcp_version(irc_session_t * session, const char * version);
  1237. /*!
  1238. * \fn void * irc_get_ctx (irc_session_t * session)
  1239. * \brief Returns the IRC session context.
  1240. *
  1241. * \param session An initiated session.
  1242. *
  1243. * This function returns the IRC session context, which was set by
  1244. * irc_set_ctx(). If no context was set, this function returns NULL.
  1245. *
  1246. * \sa irc_set_ctx
  1247. * \ingroup contexts
  1248. */
  1249. void * irc_get_ctx (irc_session_t * session);
  1250. /*!
  1251. * \fn int irc_errno (irc_session_t * session)
  1252. * \brief Returns the last error code.
  1253. *
  1254. * \param session An initiated session.
  1255. *
  1256. * This function returns the last error code associated with last operation
  1257. * of this IRC session. Possible error codes are defined in libirc_errors.h
  1258. *
  1259. * As usual, next errno rules apply:
  1260. * - irc_errno() should be called ONLY if the called function fails;
  1261. * - irc_errno() doesn't return 0 if function succeed; actually, the return
  1262. * value will be undefined.
  1263. * - you should call irc_errno() IMMEDIATELY after function fails, before
  1264. * calling any other libircclient function.
  1265. *
  1266. * \sa irc_strerror
  1267. * \ingroup errors
  1268. */
  1269. int irc_errno (irc_session_t * session);
  1270. /*!
  1271. * \fn const char * irc_strerror (int ircerrno)
  1272. * \brief Returns the text error message associated with this error code.
  1273. *
  1274. * \param ircerrno A numeric error code returned by irc_errno()
  1275. *
  1276. * This function returns the text representation of the given error code.
  1277. *
  1278. * \sa irc_errno()
  1279. * \ingroup errors
  1280. */
  1281. const char * irc_strerror (int ircerrno);
  1282. /*!
  1283. * \fn void irc_option_set (irc_session_t * session, unsigned int option)
  1284. * \brief Sets the libircclient option.
  1285. *
  1286. * \param session An initiated session.
  1287. * \param option An option from libirc_options.h
  1288. *
  1289. * This function sets the libircclient option, changing libircclient behavior. See the
  1290. * option list for the meaning for every option.
  1291. *
  1292. * \sa irc_option_reset
  1293. * \ingroup options
  1294. */
  1295. void irc_option_set (irc_session_t * session, unsigned int option);
  1296. /*!
  1297. * \fn void irc_option_reset (irc_session_t * session, unsigned int option)
  1298. * \brief Resets the libircclient option.
  1299. *
  1300. * \param session An initiated session.
  1301. * \param option An option from libirc_options.h
  1302. *
  1303. * This function removes the previously set libircclient option, changing libircclient
  1304. * behavior. See the option list for the meaning for every option.
  1305. *
  1306. * \sa irc_option_set
  1307. * \ingroup options
  1308. */
  1309. void irc_option_reset (irc_session_t * session, unsigned int option);
  1310. /*!
  1311. * \fn char * irc_color_strip_from_mirc (const char * message)
  1312. * \brief Removes all the color codes and format options.
  1313. *
  1314. * \param message A message from IRC
  1315. *
  1316. * \return Returns a new plain text message with stripped mIRC color codes.
  1317. * Note that the memory for the new message is allocated using malloc(), so
  1318. * you should free it using free() when it is not used anymore. If memory
  1319. * allocation failed, returns 0.
  1320. *
  1321. * \sa irc_color_convert_from_mirc irc_color_convert_to_mirc
  1322. * \ingroup colors
  1323. */
  1324. char * irc_color_strip_from_mirc (const char * message);
  1325. /*!
  1326. * \fn char * irc_color_convert_from_mirc (const char * message)
  1327. * \brief Converts all the color codes and format options to libircclient colors.
  1328. *
  1329. * \param message A message from IRC
  1330. *
  1331. * \return Returns a new message with converted mIRC color codes and format
  1332. * options. See the irc_color_convert_to_mirc() help to see how the colors
  1333. * are converted.\n
  1334. * Note that the memory for the new message is allocated using malloc(), so
  1335. * you should free it using free() when it is not used anymore. If memory
  1336. * allocation failed, returns 0.
  1337. *
  1338. * \sa irc_color_strip_from_mirc irc_color_convert_to_mirc
  1339. * \ingroup colors
  1340. */
  1341. char * irc_color_convert_from_mirc (const char * message);
  1342. /*!
  1343. * \fn char * irc_color_convert_to_mirc (const char * message)
  1344. * \brief Converts all the color codes from libircclient format to mIRC.
  1345. *
  1346. * \param message A message with color codes
  1347. *
  1348. * \return Returns a new message with converted color codes and format
  1349. * options, or 0 if memory could not be allocated. Note that the memory for
  1350. * the new message is allocated using malloc(), so you should free it using
  1351. * free() when it is not used anymore.
  1352. *
  1353. * The color system of libircclient is designed to be easy to use, and
  1354. * portable between different IRC clients. Every color or format option is
  1355. * described using plain text commands written between square brackets. The
  1356. * possible codes are:
  1357. * - [B] ... [/B] - bold format mode. Everything between [B] and [/B] is written in \b bold.
  1358. * - [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).
  1359. * - [U] ... [/U] - underline format mode. Everything between [U] and [/U] is written underlined.
  1360. * - [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).
  1361. * - [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.
  1362. *
  1363. * The supported text colors are:
  1364. * - WHITE
  1365. * - BLACK
  1366. * - DARKBLUE
  1367. * - DARKGREEN
  1368. * - RED
  1369. * - BROWN
  1370. * - PURPLE
  1371. * - OLIVE
  1372. * - YELLOW
  1373. * - GREEN
  1374. * - TEAL
  1375. * - CYAN
  1376. * - BLUE
  1377. * - MAGENTA
  1378. * - DARKGRAY
  1379. * - LIGHTGRAY
  1380. *
  1381. * Examples of color sequences:
  1382. * \code
  1383. * Hello, [B]Tim[/B].
  1384. * [U]Arsenal[/U] got a [COLOR=RED]red card[/COLOR]
  1385. * The tree[U]s[/U] are [COLOR=GREEN/BLACK]green[/COLOR]
  1386. * \endcode
  1387. *
  1388. * \sa irc_color_strip_from_mirc irc_color_convert_from_mirc
  1389. * \ingroup colors
  1390. */
  1391. char * irc_color_convert_to_mirc (const char * message);
  1392. #ifdef __cplusplus
  1393. }
  1394. #endif
  1395. #endif /* INCLUDE_LIBIRC_H */