LibIRCClient 1.10 Used by Probotic
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

1711 lines
85KB

  1. Functions
  2. ~~~~~~~~~
  3. This section describes the functions defined in the library which are grouped by the purpose.
  4. Library initialization and shutdown
  5. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  6. irc_create_session
  7. ******************
  8. **Prototype:**
  9. .. c:function:: irc_session_t * irc_create_session( irc_callbacks_t * callbacks )
  10. **Parameters:**
  11. +---------------------------------------------------------------------------------------------------------------------------------------+
  12. | *callbacks* | Event callbacks structure, which defines several callbacks, which will be called on appropriate events. Cannot be NULL. |
  13. +---------------------------------------------------------------------------------------------------------------------------------------+
  14. **Description:**
  15. Creates and initiates a new IRC session. Every session represents a single user connection to a single IRC server, and possibly to one or more users via DCC.
  16. Almost every library function requires this object to be passed to, and therefore this function should be called first.
  17. Multiple sessions could be allocated to support multiple connections.
  18. When it is not needed anymore, the session must be destroyed by calling the :c:func:`irc_destroy_session` function.
  19. **Return value:**
  20. An :c:type:`irc_session_t` object, or 0 if creation failed. Usually, failure is caused by out of memory error.
  21. **Thread safety:**
  22. This function can be called simultaneously from multiple threads. Same callback structure may be reused by multiple threads.
  23. irc_destroy_session
  24. *******************
  25. **Prototype:**
  26. .. c:function:: void irc_destroy_session (irc_session_t * session)
  27. **Parameters:**
  28. +---------------------------------------------------------------------------------------------------------------------------------------+
  29. | *session* | The IRC session handle |
  30. +---------------------------------------------------------------------------------------------------------------------------------------+
  31. **Description:**
  32. This function destroys an IRC session, closes the connection to the IRC server, and frees all the used resources. After calling this function you should not use this session object anymore.
  33. **Thread safety:**
  34. This function can be called simultaneously from multiple threads.
  35. Connecting, disconnecting and running the main event loop
  36. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  37. irc_connect6
  38. ************
  39. **Prototype:**
  40. .. c:function:: int irc_connect6 (irc_session_t * session, const char * server, unsigned short port, const char * password, const char * nick, const char * username, const char * realname)
  41. irc_connect
  42. ***********
  43. **Prototype:**
  44. .. c:function:: int irc_connect (irc_session_t * session, const char * server, unsigned short port, const char * password, const char * nick, const char * username, const char * realname)
  45. **Parameters:**
  46. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  47. | *session* | IRC session handle |
  48. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  49. | *server* | IP address or the host name of the server. If prefixed with #, the library will try to establish the SSL connection |
  50. | | IPv4 address should be in numeric form such as 154.23.112.33; IPv6 address should be in IPv6 form |
  51. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  52. | *port* | Port number to connect to, usually 6667 |
  53. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  54. | *password* | IRC server password, if the server requires it. May be NULL, in this case password will not be send to the IRC |
  55. | | server. Vast majority of IRC servers do not require passwords. This is NOT NickServ/ChanServ password |
  56. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  57. | *nick* | Nick which will be used to log into the IRC server. Cannot be NULL |
  58. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  59. | *username* | Username of the Unix account which is used to connect to the IRC server. This is for information only, will be shown in |
  60. | | "user properties" dialogs and returned by /whois request. Can be NULL in which case "nobody" would be used |
  61. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  62. | *realname* | A real name of the person, who connects to the IRC. In reality nobody uses this field for that. Instead this field is |
  63. | | used as user self-description, advertising, or other purposes. This information also will be shown in "user properties" |
  64. | | dialogs and returned by /whois request. May be NULL, in this case "noname" will be used |
  65. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  66. **Description:**
  67. This function initiates the connection to the IPv4 (irc_connect) or IPv6 (irc_connect6) IRC server. The server could be specified either by an IP address or by the DNS name.
  68. The irc_connect6 works only if the library was built with the IPv6 support.
  69. If the library was built with the OpenSSL support, and the IP address or the host name is prefixed by a hash, such as ``"#irc.example.com"``, the library attempts to establish the SSL connection.
  70. The connection is established asynchronously, and the :c:member:`event_connect` is called once the connection is established.
  71. A single IRC session object can only be connected to a single IRC server and only with a single nick, meaning it is not possible to have multiple nicks sharing a single connection.
  72. **Return value:**
  73. Returns 0 if the connection is initiated successfully. This doesn't mean the connection is established - the :c:member:`event_connect` is called when it happens. If the connection cannot be established,
  74. either :c:func:`irc_run` or :c:func:`irc_process_select_descriptors` will return an error.
  75. **Thread safety:**
  76. This function can be called simultaneously from multiple threads, but not using the same session object.
  77. irc_disconnect
  78. **************
  79. **Prototype:**
  80. .. c:function:: void irc_disconnect (irc_session_t * session)
  81. **Parameters:**
  82. +---------------------------------------------------------------------------------------------------------------------------------------+
  83. | *session* | IRC session handle |
  84. +---------------------------------------------------------------------------------------------------------------------------------------+
  85. **Description:**
  86. This function closes the IRC connection. After that connection is closed, if the libirc was looped in the :c:func:`irc_run` loop, it automatically leaves the loop and :c:func:`irc_run` returns.
  87. **Thread safety:**
  88. This function can be called simultaneously from multiple threads, but not using the same session object.
  89. irc_is_connected
  90. ****************
  91. **Prototype:**
  92. .. c:function:: int irc_is_connected (irc_session_t * session)
  93. **Parameters:**
  94. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  95. | *session* | IRC session handle |
  96. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  97. **Return value:**
  98. This function returns 1 if the connection to the IRC server is established or 0 if it is not.
  99. **Thread safety:**
  100. This function can be called simultaneously from multiple threads.
  101. irc_run
  102. *******
  103. **Prototype:**
  104. .. c:function:: int irc_run (irc_session_t * session)
  105. **Parameters:**
  106. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  107. | *session* | IRC session handle |
  108. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  109. **Description:**
  110. This function enters into forever loop, processing the IRC events, and calling the relevant callbacks. This function will not return
  111. until the server connection is terminated - either by server, or by calling :c:type:`irc_cmd_quit`. This function should only be used
  112. if you use a single IRC session and don't need asynchronous request processing (i.e. your bot just reacts on the events, and doesn't
  113. generate it asynchronously). Even in last case, you still can call this function and start the asynchronous thread in :c:member:`event_connect` handler.
  114. See the examples.
  115. **Return value:**
  116. This function returns a nonzero value if the connection to the IRC server could not be established, or was terminated.
  117. **Thread safety:**
  118. This function cannot be called from multiple threads. Use :c:func:`irc_add_select_descriptors` and :c:func:`irc_process_select_descriptors` instead.
  119. irc_add_select_descriptors
  120. **************************
  121. **Prototype:**
  122. .. c:function:: int irc_add_select_descriptors (irc_session_t * session, fd_set *in_set, fd_set *out_set, int * maxfd)
  123. **Parameters:**
  124. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  125. | *session* | IRC session handle |
  126. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  127. | *in_set* | fd_set input descriptor set for select() |
  128. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  129. | *out_set* | fd_set output descriptor set for select() |
  130. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  131. | *maxfd* | Largest descriptor already in all the sets. Will be updated if libirc adds larger number to the FD_SET array |
  132. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  133. **Description:**
  134. This function should be used after you called :c:func:`irc_connect`. It is useful when you have your own select-based event processing loop. To use it
  135. you should put your own descriptors into the sets, call this function to add the library descriptor(s) into the set, and then call select().
  136. When it returns, you should call :c:func:`irc_process_select_descriptors` which will handle the events and calls your callbacks(!). Then you can process
  137. your sockets events from set. See the example.
  138. What if you use epoll? :ref:`See the FAQ <faq_epoll>`
  139. **Return value:**
  140. This function returns a nonzero value if the :c:func:`irc_connect` was not called before calling this function.
  141. **Thread safety:**
  142. This function can be called simultaneously from multiple threads, but it rarely makes sense.
  143. irc_process_select_descriptors
  144. ******************************
  145. **Prototype:**
  146. .. c:function:: int irc_process_select_descriptors (irc_session_t * session, fd_set *in_set, fd_set *out_set)
  147. **Parameters:**
  148. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  149. | *session* | IRC session handle |
  150. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  151. | *in_set* | fd_set input descriptor set for select() |
  152. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  153. | *out_set* | fd_set output descriptor set for select() |
  154. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  155. **Description:**
  156. This function should be used in pair with :c:func:`irc_add_select_descriptors` function, which documentation describes how they work together.
  157. Note that while processing the events this function calls your callbacks and it will not return until all your callbacks return. Keep that in mind
  158. if you pop up a dialog in your application, such as a DCC CHAT or DCC SEND confirmation dialog.
  159. **Return value:**
  160. Return code 0 means success. Other value means error, the error code may be obtained through irc_errno().
  161. **Thread safety:**
  162. This function can be called simultaneously from multiple threads for different IRC session objects only.
  163. Managing the IRC channels: joining, leaving, inviting
  164. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  165. irc_cmd_join
  166. ************
  167. **Prototype:**
  168. .. c:function:: int irc_cmd_join (irc_session_t * session, const char * channel, const char * key)
  169. **Parameters:**
  170. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  171. | *session* | IRC session handle |
  172. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  173. | *channel* | Channel name to join. Cannot be NULL. |
  174. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  175. | *key* | Secret key for the channel. Can be NULL if not needed |
  176. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  177. **Description:**
  178. Use this function to join the new IRC channel. If the channel does not exist, it will be automatically created by the IRC server.
  179. Note that to JOIN the password-protected channel, you must know the password, and specify it in the key argument.
  180. If join is successful, the :c:member:`event_join` will be called (with your nick as the origin), then typically the :c:member:`event_topic` is be called and then you
  181. receive the list of users who are on the channel (by using LIBIRC_RFC_RPL_NAMREPLY), which will include the user who just joined.
  182. **Return value:**
  183. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  184. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  185. Possible error responces for this command from the RFC1459:
  186. - LIBIRC_RFC_ERR_BANNEDFROMCHAN
  187. - LIBIRC_RFC_ERR_INVITEONLYCHAN
  188. - LIBIRC_RFC_ERR_BADCHANNELKEY
  189. - LIBIRC_RFC_ERR_CHANNELISFULL
  190. - LIBIRC_RFC_ERR_BADCHANMASK
  191. - LIBIRC_RFC_ERR_NOSUCHCHANNEL
  192. - LIBIRC_RFC_ERR_TOOMANYCHANNELS
  193. **Thread safety:**
  194. This function can be called simultaneously from multiple threads.
  195. irc_cmd_part
  196. ************
  197. **Prototype:**
  198. .. c:function:: int irc_cmd_part (irc_session_t * session, const char * channel)
  199. **Parameters:**
  200. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  201. | *session* | IRC session handle |
  202. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  203. | *channel* | Channel name to leave. Cannot be NULL. |
  204. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  205. **Description:**
  206. Use this function to leave the IRC channel you've already joined to. An attempt to leave the channel you aren't in results a LIBIRC_RFC_ERR_NOTONCHANNEL server error.
  207. **Return value:**
  208. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  209. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  210. Possible error responces for this command from the RFC1459:
  211. - LIBIRC_RFC_ERR_NOSUCHCHANNEL
  212. - LIBIRC_RFC_ERR_NOTONCHANNEL
  213. **Thread safety:**
  214. This function can be called simultaneously from multiple threads.
  215. irc_cmd_invite
  216. **************
  217. **Prototype:**
  218. .. c:function:: int irc_cmd_invite (irc_session_t * session, const char * nick, const char * channel)
  219. **Parameters:**
  220. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  221. | *session* | IRC session handle |
  222. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  223. | *nick* | Nick name of the user to invite |
  224. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  225. | *channel* | Channel name to join. Cannot be NULL |
  226. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  227. **Description:**
  228. This function is used to invite someone to invite-only channel. "Invite-only" is a channel mode, which restricts anyone, except invided, to join this channel.
  229. After invitation, the user could join this channel. The user, who is invited, will receive the :c:member:`event_invite` event. Note that you must be a channel operator to invite the users.
  230. **Return value:**
  231. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  232. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  233. On success one of the following replies returned:
  234. - LIBIRC_RFC_RPL_INVITING
  235. - LIBIRC_RFC_RPL_AWAY
  236. Possible error responces for this command from the RFC1459:
  237. - LIBIRC_RFC_ERR_NEEDMOREPARAMS
  238. - LIBIRC_RFC_ERR_NOSUCHNICK
  239. - LIBIRC_RFC_ERR_NOTONCHANNEL
  240. - LIBIRC_RFC_ERR_ERR_USERONCHANNEL
  241. - LIBIRC_RFC_ERR_ERR_CHANOPRIVSNEEDED
  242. **Thread safety:**
  243. This function can be called simultaneously from multiple threads.
  244. irc_cmd_names
  245. *************
  246. **Prototype:**
  247. .. c:function:: int irc_cmd_names (irc_session_t * session, const char * channel);
  248. **Parameters:**
  249. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  250. | *session* | IRC session handle |
  251. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  252. | *channel* | A channel name(s) to obtain user list. Multiple channel names must be separated by a comma |
  253. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  254. **Description:**
  255. This function is used to to ask the IRC server for the list of the users who are joined the specified channel. You can list all nicknames
  256. that are visible to you on any channel that you can see. The list of users will be returned using LIBIRC_RFC_RPL_NAMREPLY and LIBIRC_RFC_RPL_ENDOFNAMES numeric codes.
  257. **Return value:**
  258. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  259. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  260. The channel names are returned by :c:member:`event_numeric` event using the following reply codes:
  261. - LIBIRC_RFC_RPL_NAMREPLY
  262. - LIBIRC_RFC_RPL_ENDOFNAMES
  263. **Thread safety:**
  264. This function can be called simultaneously from multiple threads.
  265. irc_cmd_list
  266. ************
  267. **Prototype:**
  268. .. c:function:: int irc_cmd_list (irc_session_t * session, const char * channel)
  269. **Parameters:**
  270. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  271. | *session* | IRC session handle |
  272. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  273. | *channel* | A channel name(s) to list. Multiple channel names must be separated by a comma. If NULL, all channels are listed |
  274. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  275. **Description:**
  276. This function is used to ask the IRC server for the active (existing) channels list. The list will be returned using the LIBIRC_RFC_RPL_LISTSTART,
  277. multiple LIBIRC_RFC_RPL_LIST, and LIBIRC_RFC_RPL_LISTEND event sequence. Note that "private" channels are listed (without their topics) as channel
  278. "Prv" unless the client generating the LIST query is actually on that channel. Likewise, secret channels are not listed at all unless the client
  279. is active at the channel in question.
  280. **Return value:**
  281. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  282. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  283. The list of channels is returned by :c:member:`event_numeric` event using the following reply codes:
  284. - LIBIRC_RFC_RPL_LISTSTART
  285. - LIBIRC_RFC_RPL_LISTEND
  286. - LIBIRC_RFC_RPL_LIST
  287. **Thread safety:**
  288. This function can be called simultaneously from multiple threads.
  289. irc_cmd_topic
  290. *************
  291. **Prototype:**
  292. .. c:function:: int irc_cmd_topic (irc_session_t * session, const char * channel, const char * topic)
  293. **Parameters:**
  294. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  295. | *session* | IRC session handle |
  296. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  297. | *channel* | A channel name |
  298. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  299. | *topic* | A new channel topic. If NULL, the old topic would be returned and nothing would change. To set the empty topic use "" |
  300. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  301. **Description:**
  302. This function is used to change or view the topic (title) of a channel. Note that depending on *+t* channel mode, you may be required to be
  303. a channel operator to change the channel topic.
  304. If the command succeeds, the IRC server will generate a LIBIRC_RFC_RPL_NOTOPIC or LIBIRC_RFC_RPL_TOPIC message, containing either the old
  305. or changed topic. Also the IRC server can (but does not have to) generate the non-RFC LIBIRC_RFC_RPL_TOPIC_EXTRA message, containing the
  306. nick of person who changed the topic, and the date/time of the last change.
  307. **Return value:**
  308. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  309. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  310. The topic information is returned using one of following reply codes:
  311. - LIBIRC_RFC_RPL_NOTOPIC
  312. - LIBIRC_RFC_RPL_TOPIC
  313. If the topic change was requested and it was successfully changed, the :c:member:`event_topic` is generated as well.
  314. Possible error responces for this command from the RFC1459:
  315. - LIBIRC_RFC_ERR_NEEDMOREPARAMS
  316. - LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
  317. - LIBIRC_RFC_ERR_NOTONCHANNEL
  318. **Thread safety:**
  319. This function can be called simultaneously from multiple threads.
  320. irc_cmd_channel_mode
  321. ********************
  322. **Prototype:**
  323. .. c:function:: int irc_cmd_channel_mode (irc_session_t * session, const char * channel, const char * mode)
  324. **Parameters:**
  325. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  326. | *session* | IRC session handle |
  327. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  328. | *channel* | A channel name |
  329. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  330. | *mode* | A mode to change. If NULL, the channel mode is not changed but the old mode is returned |
  331. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  332. **Description:**
  333. This function is used to is used to change or view the channel modes. Note that only the channel operators can change the channel mode.
  334. Channel mode is represended by the multiple letters combination. Every letter has its own meaning in channel modes. Most channel mode letters
  335. are boolean (i.e. could only be set or reset), but a few channel mode letters accept a parameter. All channel options are set by adding a
  336. plus sign before the letter, and reset by adding a minus sign before the letter.
  337. Here is the list of 'standard' channel modes:
  338. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  339. | o nickname | gives (+o nickname) to, or takes (-o nickname) the channel operator privileges from a *nickname*. This mode affects |
  340. | | the users in channel, not the channel itself. Examples: "+o tim", "-o watson" |
  341. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  342. | p | sets (+p) or resets (-p) private channel flag. Private channels are shown in channel list as 'Prv', without the topic |
  343. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  344. | s | sets (+s) or resets (-s) secret channel flag. Secret channels aren't shown in channel list at all |
  345. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  346. | i | sets (+i) or resets (-i) invite-only channel flag. When the flag is set, only the people who are invited by the |
  347. | | :c:func:`irc_cmd_invite` can join this channel |
  348. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  349. | t | allows (+t) or denies (-t) changing the topic by the non-channel operator users. When the flag is set, only the channel |
  350. | | operators can change the channel topic |
  351. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  352. | n | sets (+n) or resets (-n) the protection from the users who did not join the channel. When the +n mode is set, only the |
  353. | | users who have joined the channel can send the messages to the channel |
  354. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  355. | m | sets (+m) or resets (-m) the moderation of the channel. When the moderation mode is set, only channel operators and the |
  356. | | users who have +v user mode can speak in the channel |
  357. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  358. | v nickname | gives (+v nick) or takes (-v nick) from user the ability to speak on a moderated channel. Examples: "+v bob", "-v joy" |
  359. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  360. | l number | sets (+l 20) or removes (-l) the restriction of maximum number of users allowed in channel. When the restriction is set |
  361. | | and there is a number of users in the channel, no one can join the channel anymore |
  362. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  363. | k key | sets (+k password) or removes (-k) the password from the channel. When the restriction is set, any user joining the |
  364. | | channel required to provide a channel key |
  365. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  366. | b mask | sets (+b *!*@*.mil) or removes (-b *!*@*.mil) the ban mask on a user to keep him out of channel. Note that to remove the|
  367. | | ban you must specify the ban mask to remove, not just "-b". |
  368. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  369. Note that the actual list of channel modes depends on the IRC server, and can be bigger. If you know the popular channel modes which aren't listed here - please contact me
  370. **Return value:**
  371. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  372. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  373. The old mode information is returned by using following numeric codes:
  374. - LIBIRC_RFC_RPL_CHANNELMODEIS
  375. - LIBIRC_RFC_RPL_BANLIST
  376. - LIBIRC_RFC_RPL_ENDOFBANLIST
  377. Possible error responces for this command from the RFC1459:
  378. - LIBIRC_RFC_ERR_NEEDMOREPARAMS
  379. - LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
  380. - LIBIRC_RFC_ERR_NOSUCHNICK
  381. - LIBIRC_RFC_ERR_NOTONCHANNEL
  382. - LIBIRC_RFC_ERR_KEYSET
  383. - LIBIRC_RFC_ERR_UNKNOWNMODE
  384. - LIBIRC_RFC_ERR_NOSUCHCHANNEL
  385. **Thread safety:**
  386. This function can be called simultaneously from multiple threads.
  387. irc_cmd_user_mode
  388. *****************
  389. **Prototype:**
  390. .. c:function:: int irc_cmd_user_mode (irc_session_t * session, const char * mode)
  391. **Parameters:**
  392. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  393. | *session* | IRC session handle |
  394. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  395. | *mode* | A mode to change. If NULL, the user mode is not changed but the old mode is returned |
  396. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  397. **Description:**
  398. This function is used to change or view the user modes. Note that, unlike channel modes, some user modes cannot be changed at all.
  399. User mode is represended by the letters combination. All the user mode letters are boolean (i.e. could only be set or reset), they are set
  400. by adding a plus sign before the letter, and reset by adding a minus sign before the letter.
  401. Here is the list of 'standard' user modes:
  402. +---+-----------------------------------------------------------------------------------------------------------------------------------+
  403. | o | represents an IRC operator status. Could not be set directly (but can be reset though), to set it use the IRC \a OPER command |
  404. +---+-----------------------------------------------------------------------------------------------------------------------------------+
  405. | i | if set, marks a user as 'invisible' - that is, not seen by lookups if the user is not in a channel |
  406. +---+-----------------------------------------------------------------------------------------------------------------------------------+
  407. | w | if set, marks a user as 'receiving wallops' - special messages generated by IRC operators using WALLOPS command |
  408. +---+-----------------------------------------------------------------------------------------------------------------------------------+
  409. | s | if set, marks a user for receipt of server notices |
  410. +---+-----------------------------------------------------------------------------------------------------------------------------------+
  411. | r | NON-STANDARD MODE. If set, user has been authenticated with the NickServ IRC service |
  412. +---+-----------------------------------------------------------------------------------------------------------------------------------+
  413. | x | NON-STANDARD MODE. If set, user's real IP is masked by the IRC server |
  414. +---+-----------------------------------------------------------------------------------------------------------------------------------+
  415. Note that the actual list of user modes depends on the IRC server, and can be bigger. If you know the popular user modes, which aren't mentioned here - please contact me.
  416. **Return value:**
  417. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  418. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  419. The old mode information is returned by using the numeric code LIBIRC_RFC_RPL_UMODEIS:
  420. Possible error responces for this command from the RFC1459:
  421. - LIBIRC_RFC_ERR_NEEDMOREPARAMS
  422. - LIBIRC_RFC_ERR_NOSUCHNICK
  423. - LIBIRC_RFC_ERR_UNKNOWNMODE
  424. - LIBIRC_RFC_ERR_USERSDONTMATCH
  425. - LIBIRC_RFC_ERR_UMODEUNKNOWNFLAG
  426. **Thread safety:**
  427. This function can be called simultaneously from multiple threads.
  428. irc_cmd_kick
  429. ************
  430. **Prototype:**
  431. .. c:function:: int irc_cmd_kick (irc_session_t * session, const char * nick, const char * channel, const char * reason);
  432. **Parameters:**
  433. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  434. | *session* | IRC session handle |
  435. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  436. | *nick* | The nick to kick |
  437. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  438. | *channel* | The channel to kick the nick from |
  439. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  440. | *nick* | If not NULL, the reason to kick the user |
  441. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  442. **Description:**
  443. This function is used to kick a person out of channel. Note that you must be a channel operator to kick anyone from a channel.
  444. **Return value:**
  445. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  446. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  447. If the command succeed, the :c:member:`event_kick` will be generated.
  448. If the command failed, one of the following :c:member:`event_numeric` responses will be generated:
  449. - LIBIRC_RFC_ERR_NEEDMOREPARAMS
  450. - LIBIRC_RFC_ERR_BADCHANMASK
  451. - LIBIRC_RFC_ERR_NOSUCHCHANNEL
  452. - LIBIRC_RFC_ERR_NOTONCHANNEL
  453. - LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
  454. **Thread safety:**
  455. This function can be called simultaneously from multiple threads.
  456. Sending the messages, notices, /me messages and working with CTCP
  457. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  458. irc_cmd_msg
  459. ***********
  460. **Prototype:**
  461. .. c:function:: int irc_cmd_msg (irc_session_t * session, const char * nch, const char * text)
  462. **Parameters:**
  463. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  464. | *session* | IRC session handle |
  465. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  466. | *nch* | Target nick or target channel |
  467. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  468. | *text* | Message text |
  469. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  470. **Description:**
  471. This function is used to send the message to the channel or privately to another nick. "Privately" here means the message is not posted to the public,
  472. but the message still goes through the IRC server and could be seen by the IRC netwrk operators. The message target is determined by the *nch* argument:
  473. if it is a nick, this will be a private message, but if it is a channel name it will be posted into the channel.
  474. The protocol does not require you to join the channel to post the message into it, but most channels set the channel mode preventing you from posting into a channel unless you join it.
  475. **Return value:**
  476. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed. You need to wait
  477. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  478. If the command succeed, no event is typically generated except the possibility of LIBIRC_RFC_RPL_AWAY.
  479. However if the command failed, one of the following numeric events may be generated:
  480. - LIBIRC_RFC_ERR_NORECIPIENT
  481. - LIBIRC_RFC_ERR_NOTEXTTOSEND
  482. - LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  483. - LIBIRC_RFC_ERR_NOTONCHANNEL
  484. - LIBIRC_RFC_ERR_NOTOPLEVEL
  485. - LIBIRC_RFC_ERR_WILDTOPLEVEL
  486. - LIBIRC_RFC_ERR_TOOMANYTARGETS
  487. - LIBIRC_RFC_ERR_NOSUCHNICK
  488. **Thread safety:**
  489. This function can be called simultaneously from multiple threads.
  490. irc_cmd_me
  491. **********
  492. **Prototype:**
  493. .. c:function:: int irc_cmd_me (irc_session_t * session, const char * nch, const char * text)
  494. **Parameters:**
  495. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  496. | *session* | IRC session handle |
  497. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  498. | *nch* | Target nick or target channel |
  499. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  500. | *text* | Message text |
  501. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  502. **Description:**
  503. This function is used to send the /me message (CTCP ACTION) to the channel or privately to another nick. "Privately" here means the message is not posted to the public,
  504. but the message still goes through the IRC server and could be seen by the IRC netwrk operators. The message target is determined by the *nch* argument:
  505. if it is a nick, this will be a private message, but if it is a channel name it will be posted into the channel.
  506. The protocol does not require you to join the channel to post the message into it, but most channels set the channel mode preventing you from posting into a channel unless you join it.
  507. **Return value:**
  508. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed. You need to wait
  509. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  510. If the command succeed, no event is typically generated except the possibility of LIBIRC_RFC_RPL_AWAY.
  511. However if the command failed, one of the following numeric events may be generated:
  512. - LIBIRC_RFC_ERR_NORECIPIENT
  513. - LIBIRC_RFC_ERR_NOTEXTTOSEND
  514. - LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  515. - LIBIRC_RFC_ERR_NOTONCHANNEL
  516. - LIBIRC_RFC_ERR_NOTOPLEVEL
  517. - LIBIRC_RFC_ERR_WILDTOPLEVEL
  518. - LIBIRC_RFC_ERR_TOOMANYTARGETS
  519. - LIBIRC_RFC_ERR_NOSUCHNICK
  520. **Thread safety:**
  521. This function can be called simultaneously from multiple threads.
  522. irc_cmd_notice
  523. **************
  524. **Prototype:**
  525. .. c:function:: int irc_cmd_notice (irc_session_t * session, const char * nch, const char * text)
  526. **Parameters:**
  527. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  528. | *session* | IRC session handle |
  529. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  530. | *nch* | Target nick or target channel |
  531. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  532. | *text* | Message text |
  533. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  534. **Description:**
  535. This function is used to send the notice to the channel or privately to another nick. "Privately" here means the message is not posted to the public,
  536. but the message still goes through the IRC server and could be seen by the IRC netwrk operators. The message target is determined by the *nch* argument:
  537. if it is a nick, this will be a private message, but if it is a channel name it will be posted into the channel.
  538. The protocol does not require you to join the channel to post the notice into it, but most channels set the channel mode preventing you from posting into a channel unless you join it.
  539. The only difference between a message and a notice is that the RFC explicitly says the automatic bots must not reply to NOTICE automatically.
  540. **Return value:**
  541. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  542. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  543. If the command succeed, no event is typically generated except the possibility of LIBIRC_RFC_RPL_AWAY.
  544. However if the command failed, one of the following numeric events may be generated:
  545. - LIBIRC_RFC_ERR_NORECIPIENT
  546. - LIBIRC_RFC_ERR_NOTEXTTOSEND
  547. - LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  548. - LIBIRC_RFC_ERR_NOTONCHANNEL
  549. - LIBIRC_RFC_ERR_NOTOPLEVEL
  550. - LIBIRC_RFC_ERR_WILDTOPLEVEL
  551. - LIBIRC_RFC_ERR_TOOMANYTARGETS
  552. - LIBIRC_RFC_ERR_NOSUCHNICK
  553. **Thread safety:**
  554. This function can be called simultaneously from multiple threads.
  555. irc_cmd_ctcp_request
  556. ********************
  557. **Prototype:**
  558. .. c:function:: int irc_cmd_ctcp_request (irc_session_t * session, const char * nick, const char * request)
  559. **Parameters:**
  560. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  561. | *session* | IRC session handle |
  562. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  563. | *nick* | Target nick |
  564. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  565. | *request* | CTCP request tex |
  566. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  567. **Description:**
  568. This function is used to send a CTCP request. There are four CTCP requests supported by most IRC clients:
  569. * VERSION - get the client software name and version
  570. * FINGER - get the client username, host and real name.
  571. * PING - get the client delay.
  572. * TIME - get the client local time.
  573. Some clients may support other requests. The RFC does not list the requests and does not mandate any CTCP support.
  574. If you send the CTCP request, make sure you define the handler for the :c:member:`event_ctcp_rep` to process the reply;
  575. **Return value:**
  576. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  577. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  578. Possible error responces for this command from the RFC1459:
  579. - LIBIRC_RFC_ERR_NORECIPIENT
  580. - LIBIRC_RFC_ERR_NOTEXTTOSEND
  581. - LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  582. - LIBIRC_RFC_ERR_NOTONCHANNEL
  583. - LIBIRC_RFC_ERR_NOTOPLEVEL
  584. - LIBIRC_RFC_ERR_WILDTOPLEVEL
  585. - LIBIRC_RFC_ERR_TOOMANYTARGETS
  586. - LIBIRC_RFC_ERR_NOSUCHNICK
  587. **Thread safety:**
  588. This function can be called simultaneously from multiple threads.
  589. irc_cmd_ctcp_reply
  590. ******************
  591. **Prototype:**
  592. .. c:function:: int irc_cmd_ctcp_reply (irc_session_t * session, const char * nick, const char * reply)
  593. **Parameters:**
  594. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  595. | *session* | IRC session handle |
  596. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  597. | *nick* | Target nick |
  598. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  599. | *reply* | CTCP reply |
  600. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  601. **Description:**
  602. This function is used to send a reply to the CTCP request received from :c:member:`event_ctcp_req` event. Note that you will not receive this event
  603. unless you specify your own handler during the IRC session initialization.
  604. **Return value:**
  605. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  606. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  607. Possible error responces for this command from the RFC1459:
  608. - LIBIRC_RFC_ERR_NORECIPIENT
  609. - LIBIRC_RFC_ERR_NOTEXTTOSEND
  610. - LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  611. - LIBIRC_RFC_ERR_NOTONCHANNEL
  612. - LIBIRC_RFC_ERR_NOTOPLEVEL
  613. - LIBIRC_RFC_ERR_WILDTOPLEVEL
  614. - LIBIRC_RFC_ERR_TOOMANYTARGETS
  615. - LIBIRC_RFC_ERR_NOSUCHNICK
  616. **Thread safety:**
  617. This function can be called simultaneously from multiple threads.
  618. Miscellaneous: library version, raw data, changing nick, quitting
  619. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  620. irc_cmd_nick
  621. ************
  622. **Prototype:**
  623. .. c:function:: int irc_cmd_nick (irc_session_t * session, const char * newnick)
  624. **Parameters:**
  625. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  626. | *session* | IRC session handle |
  627. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  628. | *nick* | New nick |
  629. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  630. **Description:**
  631. This function is used to change your current nick to another nick. Note that such a change is not always possible; for example
  632. you cannot change nick to the existing nick, or (on some servers) to the registered nick.
  633. **Return value:**
  634. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  635. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  636. If the operation succeed, the server will send the :c:member:`event_nick` event. If not, it will send a numeric error. Possible error responces for this command from the RFC1459:
  637. - LIBIRC_RFC_ERR_NONICKNAMEGIVEN
  638. - LIBIRC_RFC_ERR_ERRONEUSNICKNAME
  639. - LIBIRC_RFC_ERR_NICKNAMEINUSE
  640. - LIBIRC_RFC_ERR_NICKCOLLISION
  641. **Thread safety:**
  642. This function can be called simultaneously from multiple threads.
  643. irc_cmd_whois
  644. *************
  645. **Prototype:**
  646. .. c:function:: int irc_cmd_whois (irc_session_t * session, const char * nick)
  647. **Parameters:**
  648. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  649. | *session* | IRC session handle |
  650. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  651. | *nick* | Nick or comma-separated list of nicks to query the information about |
  652. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  653. **Description:**
  654. This function queries various information about the nick. The amount of information depends on the IRC server but typically includes username,
  655. real name (as defined by the client at login), the IRC server used, the channels user is in, idle time, away mode and so on.
  656. **Return value:**
  657. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  658. for the appropriate :c:member:`event_numeric` event.
  659. If the request succeed, the information is returned through the following numeric codes which return the information:
  660. - LIBIRC_RFC_RPL_WHOISUSER
  661. - LIBIRC_RFC_RPL_WHOISCHANNELS
  662. - LIBIRC_RFC_RPL_WHOISSERVER
  663. - LIBIRC_RFC_RPL_AWAY
  664. - LIBIRC_RFC_RPL_WHOISOPERATOR
  665. - LIBIRC_RFC_RPL_WHOISIDLE
  666. - LIBIRC_RFC_RPL_ENDOFWHOIS - this event terminates the WHOIS information
  667. Possible error responces for this command from the RFC1459:
  668. - LIBIRC_RFC_ERR_NOSUCHSERVER
  669. - LIBIRC_RFC_ERR_NOSUCHNICK
  670. - LIBIRC_RFC_ERR_NONICKNAMEGIVEN
  671. **Thread safety:**
  672. This function can be called simultaneously from multiple threads.
  673. irc_cmd_quit
  674. ************
  675. **Prototype:**
  676. .. c:function:: int irc_cmd_quit (irc_session_t * session, const char * reason)
  677. **Parameters:**
  678. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  679. | *session* | IRC session handle |
  680. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  681. | *reason* | If not NULL, the reason to quit |
  682. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  683. **Description:**
  684. This function sends the QUIT command to the IRC server. This command forces the IRC server to close the IRC connection, and terminate the session.
  685. The difference between this command and calling the irc_disconnect is that this command allows to specify the reason to quit which will be shown
  686. to all the users in the channels you joined. Also it would make it clear that you left the IRC channels by purpose, and not merely got disconnected.
  687. **Return value:**
  688. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  689. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  690. **Thread safety:**
  691. This function can be called simultaneously from multiple threads.
  692. irc_send_raw
  693. ************
  694. **Prototype:**
  695. .. c:function:: int irc_send_raw (irc_session_t * session, const char * format, ...);
  696. **Parameters:**
  697. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  698. | *session* | IRC session handle |
  699. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  700. | *format* | printf-type formatting string followed by the format arguments |
  701. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  702. **Description:**
  703. This function sends the raw data as-is to the IRC server. Use it to generate a server command, which is not (yet) provided by libircclient directly.
  704. **Return value:**
  705. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  706. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  707. **Thread safety:**
  708. This function can be called simultaneously from multiple threads.
  709. irc_target_get_nick
  710. *******************
  711. **Prototype:**
  712. .. c:function:: void irc_target_get_nick (const char * origin, char *nick, size_t size)
  713. **Parameters:**
  714. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  715. | *origin* | Nick in the common IRC server format such as tim!root\@mycomain.com |
  716. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  717. | *nick* | Buffer to retrieve the parsed nick name |
  718. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  719. | *size* | Size of the *nick* buffer. If the parsed nick is larger than the buffer size it will be truncated |
  720. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  721. **Description:**
  722. For most events IRC server returns 'origin' (i.e. the person, who generated this event) in so-called "common" form, like nick!host@domain.
  723. However, all the irc_cmd_* functions require just a nick. This function parses this origin, and retrieves the nick, storing it into the user-provided buffer.
  724. A buffer of size 128 should be enough for most nicks.
  725. **Thread safety:**
  726. This function can be called simultaneously from multiple threads.
  727. irc_target_get_host
  728. *******************
  729. **Prototype:**
  730. .. c:function:: void irc_target_get_host (const char * target, char *host, size_t size)
  731. **Parameters:**
  732. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  733. | *origin* | Nick in the common IRC server format such as tim!root\@mycomain.com |
  734. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  735. | *host* | Buffer to retrieve the parsed hostname |
  736. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  737. | *size* | Size of the *host* buffer. If the parsed nick is larger than the buffer size it will be truncated |
  738. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  739. **Description:**
  740. For most events IRC server returns 'origin' (i.e. the person, who generated this event) in so-called "common" form, like nick!host\@domain.
  741. This function parses this origin, and retrieves the host, storing it into the user-provided buffer.
  742. **Thread safety:**
  743. This function can be called simultaneously from multiple threads.
  744. DCC initiating and accepting chat sessions, sending and receiving files
  745. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  746. irc_dcc_chat
  747. ************
  748. **Prototype:**
  749. .. c:function:: int irc_dcc_chat(irc_session_t * session, void * ctx, const char * nick, irc_dcc_callback_t callback, irc_dcc_t * dccid)
  750. **Parameters:**
  751. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  752. | *session* | IRC session handle |
  753. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  754. | *ctx* | User-defined context which will be passed to the callback. May be NULL |
  755. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  756. | *nick* | Target nick |
  757. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  758. | *callback* | DCC callback which will be used for DCC and chat events |
  759. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  760. | *dccid* | If this function succeeds, the DCC session identifier is stored in this field |
  761. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  762. **Description:**
  763. This function requests a DCC CHAT between you and other IRC user. DCC CHAT is like private chat, but it goes directly between two users,
  764. and bypasses the IRC server. DCC CHAT request must be accepted by other side before you can send anything.
  765. When the chat is accepted, declined, terminated, or some data is received, the *callback* function is called. To be specific,
  766. the callback will be called when:
  767. * The chat request is accepted;
  768. * The chat request is denied;
  769. * The new chat message is received;
  770. * The chat is terminated by the remote party;
  771. See the details in :c:type:`irc_dcc_callback_t` declaration.
  772. **Return value:**
  773. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  774. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  775. Possible error responces for this command from the RFC1459:
  776. - LIBIRC_RFC_ERR_NORECIPIENT
  777. - LIBIRC_RFC_ERR_NOTEXTTOSEND
  778. - LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  779. - LIBIRC_RFC_ERR_NOTONCHANNEL
  780. - LIBIRC_RFC_ERR_NOTOPLEVEL
  781. - LIBIRC_RFC_ERR_WILDTOPLEVEL
  782. - LIBIRC_RFC_ERR_TOOMANYTARGETS
  783. - LIBIRC_RFC_ERR_NOSUCHNICK
  784. **Thread safety:**
  785. This function can be called simultaneously from multiple threads.
  786. irc_dcc_msg
  787. ***********
  788. **Prototype:**
  789. .. c:function:: int irc_dcc_msg (irc_session_t * session, irc_dcc_t dccid, const char * text)
  790. **Parameters:**
  791. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  792. | *session* | IRC session handle |
  793. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  794. | *dccid* | DCC session identifier for the DCC CHAT session which is active |
  795. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  796. | *text* | NULL-terminated message to send |
  797. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  798. **Description:**
  799. This function is used to send the DCC CHAT message to an active DCC CHAT. To be active, DCC CHAT request must be initiated by one side and accepted by another side.
  800. **Return value:**
  801. Return code 0 means success. Other value means error, the error code may be obtained through irc_errno().
  802. **Thread safety:**
  803. This function can be called simultaneously from multiple threads.
  804. irc_dcc_accept
  805. **************
  806. **Prototype:**
  807. .. c:function:: int irc_dcc_accept (irc_session_t * session, irc_dcc_t dccid, void * ctx, irc_dcc_callback_t callback)
  808. **Parameters:**
  809. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  810. | *session* | IRC session handle |
  811. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  812. | *dccid* | DCC session identifier returned by the callback |
  813. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  814. | *ctx* | User-defined context which will be passed to the callback. May be NULL |
  815. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  816. | *callback* | DCC callback which will be used for DCC and chat events |
  817. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  818. **Description:**
  819. This function accepts a remote DCC chat or file transfer request. After the request is accepted the *callback* will be called for the further DCC events,
  820. including the termination of the DCC session. See the :c:type:`DCC callback information <irc_dcc_callback_t>`.
  821. This function should be called only after either :c:member:`event_dcc_chat_req` or :c:member:`event_dcc_send_req` events are received. You don't have to call irc_dcc_accept()
  822. or irc_dcc_decline() immediately in the event processing function - you may just store the *dccid* and return, and call those functions later. However to
  823. prevent memory leaks you must call either irc_dcc_decline() or irc_dcc_accept() for any incoming DCC request within 60 seconds after receiving it.
  824. **Return value:**
  825. Return code 0 means success. Other value means error, the error code may be obtained through :c:func:`irc_errno`.
  826. **Thread safety:**
  827. This function can be called simultaneously from multiple threads.
  828. irc_dcc_decline
  829. ***************
  830. **Prototype:**
  831. .. c:function:: int irc_dcc_decline (irc_session_t * session, irc_dcc_t dccid)
  832. **Parameters:**
  833. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  834. | *session* | IRC session handle |
  835. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  836. | *dccid* | DCC session identifier returned by the callback |
  837. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  838. **Description:**
  839. This function declines a remote DCC chat or file transfer request.
  840. This function should be called only after either :c:member:`event_dcc_chat_req` or :c:member:`event_dcc_send_req` events are received. You don't have to call irc_dcc_accept()
  841. or irc_dcc_decline() immediately in the event processing function - you may just store the *dccid* and return, and call those functions later. However to
  842. prevent memory leaks you must call either irc_dcc_decline() or irc_dcc_accept() for any incoming DCC request within 60 seconds after receiving it.
  843. Do not use this function to forecefully close the previously accepted or initiated DCC session. Use :c:func:`irc_dcc_destroy` instead.
  844. **Return value:**
  845. Return code 0 means success. Other value means error, the error code may be obtained through :c:func:`irc_errno`.
  846. **Thread safety:**
  847. This function can be called simultaneously from multiple threads.
  848. irc_dcc_sendfile
  849. ****************
  850. **Prototype:**
  851. .. c:function:: 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)
  852. **Parameters:**
  853. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  854. | *session* | IRC session handle |
  855. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  856. | *ctx* | User-defined context which will be passed to the callback. May be NULL |
  857. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  858. | *nick* | Target nick |
  859. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  860. | *filename* | Full path to the file which will be sent. Must be an existing file |
  861. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  862. | *callback* | DCC callback which will be used for DCC and chat events |
  863. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  864. | *dccid* | If this function succeeds, the DCC session identifier is stored in this field |
  865. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  866. **Description:**
  867. This function generates a DCC SEND request to send the file. When it is accepted, the file is sent to the remote party, and the DCC session is
  868. closed. The send operation progress and result can be checked in the callback. See the :c:type:`DCC callback information <irc_dcc_callback_t>`.
  869. **Return value:**
  870. Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed, and you need to wait
  871. for the appropriate event or for the error code via :c:member:`event_numeric` event.
  872. Possible error responces for this command from the RFC1459:
  873. - LIBIRC_RFC_ERR_NORECIPIENT
  874. - LIBIRC_RFC_ERR_NOTEXTTOSEND
  875. - LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
  876. - LIBIRC_RFC_ERR_NOTONCHANNEL
  877. - LIBIRC_RFC_ERR_NOTOPLEVEL
  878. - LIBIRC_RFC_ERR_WILDTOPLEVEL
  879. - LIBIRC_RFC_ERR_TOOMANYTARGETS
  880. - LIBIRC_RFC_ERR_NOSUCHNICK
  881. **Thread safety:**
  882. This function can be called simultaneously from multiple threads.
  883. irc_dcc_destroy
  884. ***************
  885. **Prototype:**
  886. .. c:function:: int irc_dcc_destroy (irc_session_t * session, irc_dcc_t dccid)
  887. **Parameters:**
  888. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  889. | *session* | IRC session handle |
  890. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  891. | *dccid* | DCC session identifier of a session to destroy |
  892. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  893. **Description:**
  894. This function closes the DCC connection (if available), and destroys the DCC session, freeing the used resources. It can be called anytime, even from callbacks or from different threads.
  895. Note that when DCC session is finished (either with success or failure), you should not destroy it - it will be destroyed automatically.
  896. **Return value:**
  897. Return code 0 means success. Other value means error, the error code may be obtained through :c:func:`irc_errno`.
  898. **Thread safety:**
  899. This function can be called simultaneously from multiple threads.
  900. Handling the colored messages
  901. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  902. irc_color_strip_from_mirc
  903. *************************
  904. **Prototype:**
  905. .. c:function:: char * irc_color_strip_from_mirc (const char * message)
  906. **Parameters:**
  907. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  908. | *message* | Original message with colors |
  909. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  910. **Description:**
  911. This function strips all the ANSI color codes from the message, and returns a new message with no color information. Useful for the bots which react to strings,
  912. to make sure the bot is not confused if the string uses colors.
  913. This function does not modify the message which doesn't use colors.
  914. **Return value:**
  915. Returns a new message with stripped color codes. Note that the memory for the new message is allocated using malloc(), so you should free
  916. it using free() when it is not used anymore. If memory allocation failed, returns 0.
  917. **Thread safety:**
  918. This function can be called simultaneously from multiple threads.
  919. irc_color_convert_from_mirc
  920. ***************************
  921. **Prototype:**
  922. .. c:function:: char * irc_color_convert_from_mirc (const char * message)
  923. **Parameters:**
  924. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  925. | *message* | Original message with colors |
  926. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  927. **Description:**
  928. This function converts all the color codes and format options to libircclient internal colors.
  929. **Return value:**
  930. Returns a pointer to the new message with converted ANSI color codes and format options. See the irc_color_convert_to_mirc_ help for details.
  931. Note that the memory for the new message is allocated using malloc(), so you should free it using free() when it is not used anymore.
  932. If memory allocation failed, returns 0.
  933. **Thread safety:**
  934. This function can be called simultaneously from multiple threads.
  935. irc_color_convert_to_mirc
  936. *************************
  937. **Prototype:**
  938. .. c:function:: char * irc_color_convert_to_mirc (const char * message)
  939. **Parameters:**
  940. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  941. | *message* | Original message with colors |
  942. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  943. **Description:**
  944. This function converts all the color codes and format options from internal libircclient colors to ANSI used by mIRC and other IRC clients.
  945. **Return value:**
  946. Returns a new message with converted color codes and format options, or 0 if memory could not be allocated. Note that the memory for the
  947. new message is allocated using malloc(), so you should free it using free() when it is not used anymore.
  948. **Thread safety:**
  949. This function can be called simultaneously from multiple threads.
  950. The color system of libircclient is designed to be easy to use, and portable between different IRC clients. Every color or format option
  951. is described using plain text commands written between square brackets.
  952. The possible codes are:
  953. - [B] ... [/B] - bold format mode. Everything between [B] and [/B] is written in **bold**.
  954. - [I] ... [/I] - italic/reverse format mode. Everything between [I] and [/I] is written in *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).
  955. - [U] ... [/U] - underline format mode. Everything between [U] and [/U] is written underlined.
  956. - [COLOR=RED] ... [/COLOR] - write the text using specified foreground color. The color is set by using the COLOR keyword, and equal sign followed by text color code (see below).
  957. - [COLOR=RED/BLUE] ... [/COLOR] - write the text using specified foreground and background color. The color is set by using the COLOR keyword, an equal sign followed by text foreground color code, a dash and a text background color code.
  958. The following colors are supported:
  959. - WHITE
  960. - BLACK
  961. - DARKBLUE
  962. - DARKGREEN
  963. - RED
  964. - BROWN
  965. - PURPLE
  966. - OLIVE
  967. - YELLOW
  968. - GREEN
  969. - TEAL
  970. - CYAN
  971. - BLUE
  972. - MAGENTA
  973. - DARKGRAY
  974. - LIGHTGRAY
  975. Examples of color sequences:
  976. ::
  977. Hello, [B]Tim[/B].
  978. [U]Arsenal[/U] got a [COLOR=RED]red card[/COLOR]
  979. The tree[U]s[/U] are [COLOR=GREEN/BLACK]green[/COLOR]
  980. Changing the library options
  981. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  982. irc_get_version
  983. ***************
  984. **Prototype:**
  985. .. c:function:: void irc_get_version (unsigned int * high, unsigned int * low)
  986. **Parameters:**
  987. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  988. | *high* | Stores the high version number |
  989. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  990. | *low* | Stores the low version number |
  991. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  992. **Description:**
  993. This function returns the libircclient version. You can use the version either to check whether required options are available, or to output the version.
  994. The preferred printf-like format string to output the version is:
  995. ``printf ("Version: %d.%02d", high, low);``
  996. **Thread safety:**
  997. This function can be called simultaneously from multiple threads.
  998. irc_set_ctx
  999. ***********
  1000. **Prototype:**
  1001. .. c:function:: void irc_set_ctx (irc_session_t * session, void * ctx)
  1002. **Parameters:**
  1003. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1004. | *session* | IRC session handle |
  1005. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1006. | *ctx* | User-defined context |
  1007. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1008. **Description:**
  1009. This function sets the user-defined context for this IRC session. This context is not used by libircclient. Its purpose is to store session-specific
  1010. user data, which may be obtained later by calling irc_get_ctx_. Note that libircclient just carries out this pointer. If you allocate some memory,
  1011. and store its address in ctx (most common usage), it is your responsibility to free it before calling :c:func:`irc_destroy_session`.
  1012. **Thread safety:**
  1013. This function can be called simultaneously from multiple threads.
  1014. irc_get_ctx
  1015. ***********
  1016. **Prototype:**
  1017. .. c:function:: void * irc_get_ctx (irc_session_t * session)
  1018. **Parameters:**
  1019. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1020. | *session* | IRC session handle |
  1021. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1022. **Description:**
  1023. This function returns the IRC session context, which was set by irc_set_ctx_.
  1024. **Return value:**
  1025. If no context was set, this function returns NULL.
  1026. **Thread safety:**
  1027. This function can be called simultaneously from multiple threads.
  1028. irc_option_set
  1029. **************
  1030. **Prototype:**
  1031. .. c:function:: void irc_option_set (irc_session_t * session, unsigned int option)
  1032. **Parameters:**
  1033. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1034. | *session* | IRC session handle |
  1035. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1036. | *option* | One of the :ref:`Libirc options <api_options>` to set |
  1037. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1038. **Description:**
  1039. This function sets the libircclient option, changing libircclient behavior. See the :ref:`options <api_options>` list for the meaning for every option.
  1040. **Thread safety:**
  1041. This function can be called simultaneously from multiple threads.
  1042. irc_option_reset
  1043. ****************
  1044. **Prototype:**
  1045. .. c:function:: void irc_option_reset (irc_session_t * session, unsigned int option)
  1046. **Parameters:**
  1047. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1048. | *session* | IRC session handle |
  1049. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1050. | *option* | One of the :ref:`Libirc options <api_options>` to set |
  1051. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1052. **Description:**
  1053. This function resets the libircclient option, changing libircclient behavior. See the :ref:`options <api_options>` list for the meaning for every option.
  1054. **Thread safety:**
  1055. This function can be called simultaneously from multiple threads.
  1056. Handling the errors
  1057. ^^^^^^^^^^^^^^^^^^^
  1058. irc_errno
  1059. *********
  1060. **Prototype:**
  1061. .. c:function:: int irc_errno (irc_session_t * session)
  1062. **Parameters:**
  1063. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1064. | *session* | IRC session handle |
  1065. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1066. **Description:**
  1067. This function returns the last error code associated with last operation of this IRC session. Possible error codes are defined in libirc_errors.h
  1068. As usual, typical errno rules apply:
  1069. - irc_errno() should be called ONLY if the called function fails;
  1070. - irc_errno() doesn't return 0 if function succeed; actually, the return value will be undefined.
  1071. - you should call irc_errno() IMMEDIATELY after function fails, before calling any other libircclient function.
  1072. **Return value:**
  1073. The error code.
  1074. **Thread safety:**
  1075. This function can be called simultaneously from multiple threads. Local error code is per IRC context, not per thread.
  1076. irc_strerror
  1077. ************
  1078. **Prototype:**
  1079. .. c:function:: const char * irc_strerror (int ircerrno)
  1080. **Parameters:**
  1081. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1082. | *ircerrno* | IRC error code returned by :c:func:`irc_errno` |
  1083. +-------------+-------------------------------------------------------------------------------------------------------------------------+
  1084. **Description:**
  1085. This function returns the text representation of the given error code.
  1086. **Return value:**
  1087. Returns an internal English string with a short description of the error code.
  1088. **Thread safety:**
  1089. This function can be called simultaneously from multiple threads.