1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710
|
Functions
~~~~~~~~~
This section describes the functions defined in the library which are grouped by the purpose.
Library initialization and shutdown
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
irc_create_session
******************
**Prototype:**
.. c:function:: irc_session_t * irc_create_session( irc_callbacks_t * callbacks )
**Parameters:**
+---------------------------------------------------------------------------------------------------------------------------------------+
| *callbacks* | Event callbacks structure, which defines several callbacks, which will be called on appropriate events. Cannot be NULL. |
+---------------------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
Almost every library function requires this object to be passed to, and therefore this function should be called first.
Multiple sessions could be allocated to support multiple connections.
When it is not needed anymore, the session must be destroyed by calling the :c:func:`irc_destroy_session` function.
**Return value:**
An :c:type:`irc_session_t` object, or 0 if creation failed. Usually, failure is caused by out of memory error.
**Thread safety:**
This function can be called simultaneously from multiple threads. Same callback structure may be reused by multiple threads.
irc_destroy_session
*******************
**Prototype:**
.. c:function:: void irc_destroy_session (irc_session_t * session)
**Parameters:**
+---------------------------------------------------------------------------------------------------------------------------------------+
| *session* | The IRC session handle |
+---------------------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
**Thread safety:**
This function can be called simultaneously from multiple threads.
Connecting, disconnecting and running the main event loop
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
irc_connect6
************
**Prototype:**
.. 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)
irc_connect
***********
**Prototype:**
.. 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)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *server* | IP address or the host name of the server. If prefixed with #, the library will try to establish the SSL connection |
| | IPv4 address should be in numeric form such as 154.23.112.33; IPv6 address should be in IPv6 form |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *port* | Port number to connect to, usually 6667 |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *password* | IRC server password, if the server requires it. May be NULL, in this case password will not be send to the IRC |
| | server. Vast majority of IRC servers do not require passwords. This is NOT NickServ/ChanServ password |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | Nick which will be used to log into the IRC server. Cannot be NULL |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *username* | Username of the Unix account which is used to connect to the IRC server. This is for information only, will be shown in |
| | "user properties" dialogs and returned by /whois request. Can be NULL in which case "nobody" would be used |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *realname* | A real name of the person, who connects to the IRC. In reality nobody uses this field for that. Instead this field is |
| | used as user self-description, advertising, or other purposes. This information also will be shown in "user properties" |
| | dialogs and returned by /whois request. May be NULL, in this case "noname" will be used |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
The irc_connect6 works only if the library was built with the IPv6 support.
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.
The connection is established asynchronously, and the :c:member:`event_connect` is called once the connection is established.
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.
**Return value:**
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,
either :c:func:`irc_run` or :c:func:`irc_process_select_descriptors` will return an error.
**Thread safety:**
This function can be called simultaneously from multiple threads, but not using the same session object.
irc_disconnect
**************
**Prototype:**
.. c:function:: void irc_disconnect (irc_session_t * session)
**Parameters:**
+---------------------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+---------------------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
**Thread safety:**
This function can be called simultaneously from multiple threads, but not using the same session object.
irc_is_connected
****************
**Prototype:**
.. c:function:: int irc_is_connected (irc_session_t * session)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Return value:**
This function returns 1 if the connection to the IRC server is established or 0 if it is not.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_run
*******
**Prototype:**
.. c:function:: int irc_run (irc_session_t * session)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function enters into forever loop, processing the IRC events, and calling the relevant callbacks. This function will not return
until the server connection is terminated - either by server, or by calling :c:type:`irc_cmd_quit`. This function should only be used
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
generate it asynchronously). Even in last case, you still can call this function and start the asynchronous thread in :c:member:`event_connect` handler.
See the examples.
**Return value:**
This function returns a nonzero value if the connection to the IRC server could not be established, or was terminated.
**Thread safety:**
This function cannot be called from multiple threads. Use :c:func:`irc_add_select_descriptors` and :c:func:`irc_process_select_descriptors` instead.
irc_add_select_descriptors
**************************
**Prototype:**
.. c:function:: int irc_add_select_descriptors (irc_session_t * session, fd_set *in_set, fd_set *out_set, int * maxfd)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *in_set* | fd_set input descriptor set for select() |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *out_set* | fd_set output descriptor set for select() |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *maxfd* | Largest descriptor already in all the sets. Will be updated if libirc adds larger number to the FD_SET array |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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
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().
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
your sockets events from set. See the example.
What if you use epoll? :ref:`See the FAQ <faq_epoll>`
**Return value:**
This function returns a nonzero value if the :c:func:`irc_connect` was not called before calling this function.
**Thread safety:**
This function can be called simultaneously from multiple threads, but it rarely makes sense.
irc_process_select_descriptors
******************************
**Prototype:**
.. c:function:: int irc_process_select_descriptors (irc_session_t * session, fd_set *in_set, fd_set *out_set)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *in_set* | fd_set input descriptor set for select() |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *out_set* | fd_set output descriptor set for select() |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function should be used in pair with :c:func:`irc_add_select_descriptors` function, which documentation describes how they work together.
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
if you pop up a dialog in your application, such as a DCC CHAT or DCC SEND confirmation dialog.
**Return value:**
Return code 0 means success. Other value means error, the error code may be obtained through irc_errno().
**Thread safety:**
This function can be called simultaneously from multiple threads for different IRC session objects only.
Managing the IRC channels: joining, leaving, inviting
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
irc_cmd_join
************
**Prototype:**
.. c:function:: int irc_cmd_join (irc_session_t * session, const char * channel, const char * key)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *channel* | Channel name to join. Cannot be NULL. |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *key* | Secret key for the channel. Can be NULL if not needed |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
Use this function to join the new IRC channel. If the channel does not exist, it will be automatically created by the IRC server.
Note that to JOIN the password-protected channel, you must know the password, and specify it in the key argument.
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
receive the list of users who are on the channel (by using LIBIRC_RFC_RPL_NAMREPLY), which will include the user who just joined.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_BANNEDFROMCHAN
- LIBIRC_RFC_ERR_INVITEONLYCHAN
- LIBIRC_RFC_ERR_BADCHANNELKEY
- LIBIRC_RFC_ERR_CHANNELISFULL
- LIBIRC_RFC_ERR_BADCHANMASK
- LIBIRC_RFC_ERR_NOSUCHCHANNEL
- LIBIRC_RFC_ERR_TOOMANYCHANNELS
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_part
************
**Prototype:**
.. c:function:: int irc_cmd_part (irc_session_t * session, const char * channel)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *channel* | Channel name to leave. Cannot be NULL. |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NOSUCHCHANNEL
- LIBIRC_RFC_ERR_NOTONCHANNEL
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_invite
**************
**Prototype:**
.. c:function:: int irc_cmd_invite (irc_session_t * session, const char * nick, const char * channel)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | Nick name of the user to invite |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *channel* | Channel name to join. Cannot be NULL |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
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.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
On success one of the following replies returned:
- LIBIRC_RFC_RPL_INVITING
- LIBIRC_RFC_RPL_AWAY
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NEEDMOREPARAMS
- LIBIRC_RFC_ERR_NOSUCHNICK
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_ERR_USERONCHANNEL
- LIBIRC_RFC_ERR_ERR_CHANOPRIVSNEEDED
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_names
*************
**Prototype:**
.. c:function:: int irc_cmd_names (irc_session_t * session, const char * channel);
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *channel* | A channel name(s) to obtain user list. Multiple channel names must be separated by a comma |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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
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.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
The channel names are returned by :c:member:`event_numeric` event using the following reply codes:
- LIBIRC_RFC_RPL_NAMREPLY
- LIBIRC_RFC_RPL_ENDOFNAMES
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_list
************
**Prototype:**
.. c:function:: int irc_cmd_list (irc_session_t * session, const char * channel)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *channel* | A channel name(s) to list. Multiple channel names must be separated by a comma. If NULL, all channels are listed |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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,
multiple LIBIRC_RFC_RPL_LIST, and LIBIRC_RFC_RPL_LISTEND event sequence. Note that "private" channels are listed (without their topics) as channel
"Prv" unless the client generating the LIST query is actually on that channel. Likewise, secret channels are not listed at all unless the client
is active at the channel in question.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
The list of channels is returned by :c:member:`event_numeric` event using the following reply codes:
- LIBIRC_RFC_RPL_LISTSTART
- LIBIRC_RFC_RPL_LISTEND
- LIBIRC_RFC_RPL_LIST
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_topic
*************
**Prototype:**
.. c:function:: int irc_cmd_topic (irc_session_t * session, const char * channel, const char * topic)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *channel* | A channel name |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *topic* | A new channel topic. If NULL, the old topic would be returned and nothing would change. To set the empty topic use "" |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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
a channel operator to change the channel topic.
If the command succeeds, the IRC server will generate a LIBIRC_RFC_RPL_NOTOPIC or LIBIRC_RFC_RPL_TOPIC message, containing either the old
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
nick of person who changed the topic, and the date/time of the last change.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
The topic information is returned using one of following reply codes:
- LIBIRC_RFC_RPL_NOTOPIC
- LIBIRC_RFC_RPL_TOPIC
If the topic change was requested and it was successfully changed, the :c:member:`event_topic` is generated as well.
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NEEDMOREPARAMS
- LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
- LIBIRC_RFC_ERR_NOTONCHANNEL
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_channel_mode
********************
**Prototype:**
.. c:function:: int irc_cmd_channel_mode (irc_session_t * session, const char * channel, const char * mode)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *channel* | A channel name |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *mode* | A mode to change. If NULL, the channel mode is not changed but the old mode is returned |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
Channel mode is represended by the multiple letters combination. Every letter has its own meaning in channel modes. Most channel mode letters
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
plus sign before the letter, and reset by adding a minus sign before the letter.
Here is the list of 'standard' channel modes:
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| o nickname | gives (+o nickname) to, or takes (-o nickname) the channel operator privileges from a *nickname*. This mode affects |
| | the users in channel, not the channel itself. Examples: "+o tim", "-o watson" |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| p | sets (+p) or resets (-p) private channel flag. Private channels are shown in channel list as 'Prv', without the topic |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| s | sets (+s) or resets (-s) secret channel flag. Secret channels aren't shown in channel list at all |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| i | sets (+i) or resets (-i) invite-only channel flag. When the flag is set, only the people who are invited by the |
| | :c:func:`irc_cmd_invite` can join this channel |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| t | allows (+t) or denies (-t) changing the topic by the non-channel operator users. When the flag is set, only the channel |
| | operators can change the channel topic |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| 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 |
| | users who have joined the channel can send the messages to the channel |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| m | sets (+m) or resets (-m) the moderation of the channel. When the moderation mode is set, only channel operators and the |
| | users who have +v user mode can speak in the channel |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| v nickname | gives (+v nick) or takes (-v nick) from user the ability to speak on a moderated channel. Examples: "+v bob", "-v joy" |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| l number | sets (+l 20) or removes (-l) the restriction of maximum number of users allowed in channel. When the restriction is set |
| | and there is a number of users in the channel, no one can join the channel anymore |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| k key | sets (+k password) or removes (-k) the password from the channel. When the restriction is set, any user joining the |
| | channel required to provide a channel key |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| 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|
| | ban you must specify the ban mask to remove, not just "-b". |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
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
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
The old mode information is returned by using following numeric codes:
- LIBIRC_RFC_RPL_CHANNELMODEIS
- LIBIRC_RFC_RPL_BANLIST
- LIBIRC_RFC_RPL_ENDOFBANLIST
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NEEDMOREPARAMS
- LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
- LIBIRC_RFC_ERR_NOSUCHNICK
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_KEYSET
- LIBIRC_RFC_ERR_UNKNOWNMODE
- LIBIRC_RFC_ERR_NOSUCHCHANNEL
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_user_mode
*****************
**Prototype:**
.. c:function:: int irc_cmd_user_mode (irc_session_t * session, const char * mode)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *mode* | A mode to change. If NULL, the user mode is not changed but the old mode is returned |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function is used to change or view the user modes. Note that, unlike channel modes, some user modes cannot be changed at all.
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
by adding a plus sign before the letter, and reset by adding a minus sign before the letter.
Here is the list of 'standard' user modes:
+---+-----------------------------------------------------------------------------------------------------------------------------------+
| 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 |
+---+-----------------------------------------------------------------------------------------------------------------------------------+
| i | if set, marks a user as 'invisible' - that is, not seen by lookups if the user is not in a channel |
+---+-----------------------------------------------------------------------------------------------------------------------------------+
| w | if set, marks a user as 'receiving wallops' - special messages generated by IRC operators using WALLOPS command |
+---+-----------------------------------------------------------------------------------------------------------------------------------+
| s | if set, marks a user for receipt of server notices |
+---+-----------------------------------------------------------------------------------------------------------------------------------+
| r | NON-STANDARD MODE. If set, user has been authenticated with the NickServ IRC service |
+---+-----------------------------------------------------------------------------------------------------------------------------------+
| x | NON-STANDARD MODE. If set, user's real IP is masked by the IRC server |
+---+-----------------------------------------------------------------------------------------------------------------------------------+
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.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
The old mode information is returned by using the numeric code LIBIRC_RFC_RPL_UMODEIS:
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NEEDMOREPARAMS
- LIBIRC_RFC_ERR_NOSUCHNICK
- LIBIRC_RFC_ERR_UNKNOWNMODE
- LIBIRC_RFC_ERR_USERSDONTMATCH
- LIBIRC_RFC_ERR_UMODEUNKNOWNFLAG
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_kick
************
**Prototype:**
.. c:function:: int irc_cmd_kick (irc_session_t * session, const char * nick, const char * channel, const char * reason);
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | The nick to kick |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *channel* | The channel to kick the nick from |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | If not NULL, the reason to kick the user |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
If the command succeed, the :c:member:`event_kick` will be generated.
If the command failed, one of the following :c:member:`event_numeric` responses will be generated:
- LIBIRC_RFC_ERR_NEEDMOREPARAMS
- LIBIRC_RFC_ERR_BADCHANMASK
- LIBIRC_RFC_ERR_NOSUCHCHANNEL
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_CHANOPRIVSNEEDED
**Thread safety:**
This function can be called simultaneously from multiple threads.
Sending the messages, notices, /me messages and working with CTCP
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
irc_cmd_msg
***********
**Prototype:**
.. c:function:: int irc_cmd_msg (irc_session_t * session, const char * nch, const char * text)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nch* | Target nick or target channel |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *text* | Message text |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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,
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:
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.
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.
**Return value:**
Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed. You need to wait
for the appropriate event or for the error code via :c:member:`event_numeric` event.
If the command succeed, no event is typically generated except the possibility of LIBIRC_RFC_RPL_AWAY.
However if the command failed, one of the following numeric events may be generated:
- LIBIRC_RFC_ERR_NORECIPIENT
- LIBIRC_RFC_ERR_NOTEXTTOSEND
- LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_NOTOPLEVEL
- LIBIRC_RFC_ERR_WILDTOPLEVEL
- LIBIRC_RFC_ERR_TOOMANYTARGETS
- LIBIRC_RFC_ERR_NOSUCHNICK
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_me
**********
**Prototype:**
.. c:function:: int irc_cmd_me (irc_session_t * session, const char * nch, const char * text)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nch* | Target nick or target channel |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *text* | Message text |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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,
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:
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.
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.
**Return value:**
Return code 0 means the command was sent to the IRC server successfully. This does not mean the operation succeed. You need to wait
for the appropriate event or for the error code via :c:member:`event_numeric` event.
If the command succeed, no event is typically generated except the possibility of LIBIRC_RFC_RPL_AWAY.
However if the command failed, one of the following numeric events may be generated:
- LIBIRC_RFC_ERR_NORECIPIENT
- LIBIRC_RFC_ERR_NOTEXTTOSEND
- LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_NOTOPLEVEL
- LIBIRC_RFC_ERR_WILDTOPLEVEL
- LIBIRC_RFC_ERR_TOOMANYTARGETS
- LIBIRC_RFC_ERR_NOSUCHNICK
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_notice
**************
**Prototype:**
.. c:function:: int irc_cmd_notice (irc_session_t * session, const char * nch, const char * text)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nch* | Target nick or target channel |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *text* | Message text |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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,
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:
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.
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.
The only difference between a message and a notice is that the RFC explicitly says the automatic bots must not reply to NOTICE automatically.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
If the command succeed, no event is typically generated except the possibility of LIBIRC_RFC_RPL_AWAY.
However if the command failed, one of the following numeric events may be generated:
- LIBIRC_RFC_ERR_NORECIPIENT
- LIBIRC_RFC_ERR_NOTEXTTOSEND
- LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_NOTOPLEVEL
- LIBIRC_RFC_ERR_WILDTOPLEVEL
- LIBIRC_RFC_ERR_TOOMANYTARGETS
- LIBIRC_RFC_ERR_NOSUCHNICK
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_ctcp_request
********************
**Prototype:**
.. c:function:: int irc_cmd_ctcp_request (irc_session_t * session, const char * nick, const char * request)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | Target nick |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *request* | CTCP request tex |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function is used to send a CTCP request. There are four CTCP requests supported by most IRC clients:
* VERSION - get the client software name and version
* FINGER - get the client username, host and real name.
* PING - get the client delay.
* TIME - get the client local time.
Some clients may support other requests. The RFC does not list the requests and does not mandate any CTCP support.
If you send the CTCP request, make sure you define the handler for the :c:member:`event_ctcp_rep` to process the reply;
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NORECIPIENT
- LIBIRC_RFC_ERR_NOTEXTTOSEND
- LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_NOTOPLEVEL
- LIBIRC_RFC_ERR_WILDTOPLEVEL
- LIBIRC_RFC_ERR_TOOMANYTARGETS
- LIBIRC_RFC_ERR_NOSUCHNICK
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_ctcp_reply
******************
**Prototype:**
.. c:function:: int irc_cmd_ctcp_reply (irc_session_t * session, const char * nick, const char * reply)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | Target nick |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *reply* | CTCP reply |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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
unless you specify your own handler during the IRC session initialization.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NORECIPIENT
- LIBIRC_RFC_ERR_NOTEXTTOSEND
- LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_NOTOPLEVEL
- LIBIRC_RFC_ERR_WILDTOPLEVEL
- LIBIRC_RFC_ERR_TOOMANYTARGETS
- LIBIRC_RFC_ERR_NOSUCHNICK
**Thread safety:**
This function can be called simultaneously from multiple threads.
Miscellaneous: library version, raw data, changing nick, quitting
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
irc_cmd_nick
************
**Prototype:**
.. c:function:: int irc_cmd_nick (irc_session_t * session, const char * newnick)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | New nick |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function is used to change your current nick to another nick. Note that such a change is not always possible; for example
you cannot change nick to the existing nick, or (on some servers) to the registered nick.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
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:
- LIBIRC_RFC_ERR_NONICKNAMEGIVEN
- LIBIRC_RFC_ERR_ERRONEUSNICKNAME
- LIBIRC_RFC_ERR_NICKNAMEINUSE
- LIBIRC_RFC_ERR_NICKCOLLISION
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_whois
*************
**Prototype:**
.. c:function:: int irc_cmd_whois (irc_session_t * session, const char * nick)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | Nick or comma-separated list of nicks to query the information about |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function queries various information about the nick. The amount of information depends on the IRC server but typically includes username,
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.
**Return value:**
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
for the appropriate :c:member:`event_numeric` event.
If the request succeed, the information is returned through the following numeric codes which return the information:
- LIBIRC_RFC_RPL_WHOISUSER
- LIBIRC_RFC_RPL_WHOISCHANNELS
- LIBIRC_RFC_RPL_WHOISSERVER
- LIBIRC_RFC_RPL_AWAY
- LIBIRC_RFC_RPL_WHOISOPERATOR
- LIBIRC_RFC_RPL_WHOISIDLE
- LIBIRC_RFC_RPL_ENDOFWHOIS - this event terminates the WHOIS information
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NOSUCHSERVER
- LIBIRC_RFC_ERR_NOSUCHNICK
- LIBIRC_RFC_ERR_NONICKNAMEGIVEN
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_cmd_quit
************
**Prototype:**
.. c:function:: int irc_cmd_quit (irc_session_t * session, const char * reason)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *reason* | If not NULL, the reason to quit |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
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
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.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_send_raw
************
**Prototype:**
.. c:function:: int irc_send_raw (irc_session_t * session, const char * format, ...);
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *format* | printf-type formatting string followed by the format arguments |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_target_get_nick
*******************
**Prototype:**
.. c:function:: void irc_target_get_nick (const char * origin, char *nick, size_t size)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *origin* | Nick in the common IRC server format such as tim!root\@mycomain.com |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | Buffer to retrieve the parsed nick name |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *size* | Size of the *nick* buffer. If the parsed nick is larger than the buffer size it will be truncated |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
For most events IRC server returns 'origin' (i.e. the person, who generated this event) in so-called "common" form, like nick!host@domain.
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.
A buffer of size 128 should be enough for most nicks.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_target_get_host
*******************
**Prototype:**
.. c:function:: void irc_target_get_host (const char * target, char *host, size_t size)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *origin* | Nick in the common IRC server format such as tim!root\@mycomain.com |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *host* | Buffer to retrieve the parsed hostname |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *size* | Size of the *host* buffer. If the parsed nick is larger than the buffer size it will be truncated |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
For most events IRC server returns 'origin' (i.e. the person, who generated this event) in so-called "common" form, like nick!host\@domain.
This function parses this origin, and retrieves the host, storing it into the user-provided buffer.
**Thread safety:**
This function can be called simultaneously from multiple threads.
DCC initiating and accepting chat sessions, sending and receiving files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
irc_dcc_chat
************
**Prototype:**
.. c:function:: int irc_dcc_chat(irc_session_t * session, void * ctx, const char * nick, irc_dcc_callback_t callback, irc_dcc_t * dccid)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *ctx* | User-defined context which will be passed to the callback. May be NULL |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | Target nick |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *callback* | DCC callback which will be used for DCC and chat events |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *dccid* | If this function succeeds, the DCC session identifier is stored in this field |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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,
and bypasses the IRC server. DCC CHAT request must be accepted by other side before you can send anything.
When the chat is accepted, declined, terminated, or some data is received, the *callback* function is called. To be specific,
the callback will be called when:
* The chat request is accepted;
* The chat request is denied;
* The new chat message is received;
* The chat is terminated by the remote party;
See the details in :c:type:`irc_dcc_callback_t` declaration.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NORECIPIENT
- LIBIRC_RFC_ERR_NOTEXTTOSEND
- LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_NOTOPLEVEL
- LIBIRC_RFC_ERR_WILDTOPLEVEL
- LIBIRC_RFC_ERR_TOOMANYTARGETS
- LIBIRC_RFC_ERR_NOSUCHNICK
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_dcc_msg
***********
**Prototype:**
.. c:function:: int irc_dcc_msg (irc_session_t * session, irc_dcc_t dccid, const char * text)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *dccid* | DCC session identifier for the DCC CHAT session which is active |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *text* | NULL-terminated message to send |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
**Return value:**
Return code 0 means success. Other value means error, the error code may be obtained through irc_errno().
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_dcc_accept
**************
**Prototype:**
.. c:function:: int irc_dcc_accept (irc_session_t * session, irc_dcc_t dccid, void * ctx, irc_dcc_callback_t callback)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *dccid* | DCC session identifier returned by the callback |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *ctx* | User-defined context which will be passed to the callback. May be NULL |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *callback* | DCC callback which will be used for DCC and chat events |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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,
including the termination of the DCC session. See the :c:type:`DCC callback information <irc_dcc_callback_t>`.
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()
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
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.
**Return value:**
Return code 0 means success. Other value means error, the error code may be obtained through :c:func:`irc_errno`.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_dcc_decline
***************
**Prototype:**
.. c:function:: int irc_dcc_decline (irc_session_t * session, irc_dcc_t dccid)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *dccid* | DCC session identifier returned by the callback |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function declines a remote DCC chat or file transfer request.
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()
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
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.
Do not use this function to forecefully close the previously accepted or initiated DCC session. Use :c:func:`irc_dcc_destroy` instead.
**Return value:**
Return code 0 means success. Other value means error, the error code may be obtained through :c:func:`irc_errno`.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_dcc_sendfile
****************
**Prototype:**
.. 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)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *ctx* | User-defined context which will be passed to the callback. May be NULL |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *nick* | Target nick |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *filename* | Full path to the file which will be sent. Must be an existing file |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *callback* | DCC callback which will be used for DCC and chat events |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *dccid* | If this function succeeds, the DCC session identifier is stored in this field |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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
closed. The send operation progress and result can be checked in the callback. See the :c:type:`DCC callback information <irc_dcc_callback_t>`.
**Return value:**
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
for the appropriate event or for the error code via :c:member:`event_numeric` event.
Possible error responces for this command from the RFC1459:
- LIBIRC_RFC_ERR_NORECIPIENT
- LIBIRC_RFC_ERR_NOTEXTTOSEND
- LIBIRC_RFC_ERR_CANNOTSENDTOCHAN
- LIBIRC_RFC_ERR_NOTONCHANNEL
- LIBIRC_RFC_ERR_NOTOPLEVEL
- LIBIRC_RFC_ERR_WILDTOPLEVEL
- LIBIRC_RFC_ERR_TOOMANYTARGETS
- LIBIRC_RFC_ERR_NOSUCHNICK
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_dcc_destroy
***************
**Prototype:**
.. c:function:: int irc_dcc_destroy (irc_session_t * session, irc_dcc_t dccid)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *dccid* | DCC session identifier of a session to destroy |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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.
Note that when DCC session is finished (either with success or failure), you should not destroy it - it will be destroyed automatically.
**Return value:**
Return code 0 means success. Other value means error, the error code may be obtained through :c:func:`irc_errno`.
**Thread safety:**
This function can be called simultaneously from multiple threads.
Handling the colored messages
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
irc_color_strip_from_mirc
*************************
**Prototype:**
.. c:function:: char * irc_color_strip_from_mirc (const char * message)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *message* | Original message with colors |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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,
to make sure the bot is not confused if the string uses colors.
This function does not modify the message which doesn't use colors.
**Return value:**
Returns a new message with stripped color codes. 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. If memory allocation failed, returns 0.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_color_convert_from_mirc
***************************
**Prototype:**
.. c:function:: char * irc_color_convert_from_mirc (const char * message)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *message* | Original message with colors |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function converts all the color codes and format options to libircclient internal colors.
**Return value:**
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.
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.
If memory allocation failed, returns 0.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_color_convert_to_mirc
*************************
**Prototype:**
.. c:function:: char * irc_color_convert_to_mirc (const char * message)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *message* | Original message with colors |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function converts all the color codes and format options from internal libircclient colors to ANSI used by mIRC and other IRC clients.
**Return value:**
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
new message is allocated using malloc(), so you should free it using free() when it is not used anymore.
**Thread safety:**
This function can be called simultaneously from multiple threads.
The color system of libircclient is designed to be easy to use, and portable between different IRC clients. Every color or format option
is described using plain text commands written between square brackets.
The possible codes are:
- [B] ... [/B] - bold format mode. Everything between [B] and [/B] is written in **bold**.
- [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).
- [U] ... [/U] - underline format mode. Everything between [U] and [/U] is written underlined.
- [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).
- [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.
The following colors are supported:
- WHITE
- BLACK
- DARKBLUE
- DARKGREEN
- RED
- BROWN
- PURPLE
- OLIVE
- YELLOW
- GREEN
- TEAL
- CYAN
- BLUE
- MAGENTA
- DARKGRAY
- LIGHTGRAY
Examples of color sequences:
::
Hello, [B]Tim[/B].
[U]Arsenal[/U] got a [COLOR=RED]red card[/COLOR]
The tree[U]s[/U] are [COLOR=GREEN/BLACK]green[/COLOR]
Changing the library options
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
irc_get_version
***************
**Prototype:**
.. c:function:: void irc_get_version (unsigned int * high, unsigned int * low)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *high* | Stores the high version number |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *low* | Stores the low version number |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function returns the libircclient version. You can use the version either to check whether required options are available, or to output the version.
The preferred printf-like format string to output the version is:
``printf ("Version: %d.%02d", high, low);``
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_set_ctx
***********
**Prototype:**
.. c:function:: void irc_set_ctx (irc_session_t * session, void * ctx)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *ctx* | User-defined context |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
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
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,
and store its address in ctx (most common usage), it is your responsibility to free it before calling :c:func:`irc_destroy_session`.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_get_ctx
***********
**Prototype:**
.. c:function:: void * irc_get_ctx (irc_session_t * session)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function returns the IRC session context, which was set by irc_set_ctx_.
**Return value:**
If no context was set, this function returns NULL.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_option_set
**************
**Prototype:**
.. c:function:: void irc_option_set (irc_session_t * session, unsigned int option)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *option* | One of the :ref:`Libirc options <api_options>` to set |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function sets the libircclient option, changing libircclient behavior. See the :ref:`options <api_options>` list for the meaning for every option.
**Thread safety:**
This function can be called simultaneously from multiple threads.
irc_option_reset
****************
**Prototype:**
.. c:function:: void irc_option_reset (irc_session_t * session, unsigned int option)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *option* | One of the :ref:`Libirc options <api_options>` to set |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function resets the libircclient option, changing libircclient behavior. See the :ref:`options <api_options>` list for the meaning for every option.
**Thread safety:**
This function can be called simultaneously from multiple threads.
Handling the errors
^^^^^^^^^^^^^^^^^^^
irc_errno
*********
**Prototype:**
.. c:function:: int irc_errno (irc_session_t * session)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *session* | IRC session handle |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function returns the last error code associated with last operation of this IRC session. Possible error codes are defined in libirc_errors.h
As usual, typical errno rules apply:
- irc_errno() should be called ONLY if the called function fails;
- irc_errno() doesn't return 0 if function succeed; actually, the return value will be undefined.
- you should call irc_errno() IMMEDIATELY after function fails, before calling any other libircclient function.
**Return value:**
The error code.
**Thread safety:**
This function can be called simultaneously from multiple threads. Local error code is per IRC context, not per thread.
irc_strerror
************
**Prototype:**
.. c:function:: const char * irc_strerror (int ircerrno)
**Parameters:**
+-------------+-------------------------------------------------------------------------------------------------------------------------+
| *ircerrno* | IRC error code returned by :c:func:`irc_errno` |
+-------------+-------------------------------------------------------------------------------------------------------------------------+
**Description:**
This function returns the text representation of the given error code.
**Return value:**
Returns an internal English string with a short description of the error code.
**Thread safety:**
This function can be called simultaneously from multiple threads.
|