| 17 |
17 |
| 18 #ifdef _WIN32 |
18 #ifdef _WIN32 |
| 19 #include "win32dep.h" |
19 #include "win32dep.h" |
| 20 #endif |
20 #endif |
| 21 |
21 |
| 22 /* |
22 /** |
| 23 * In OSCAR, every connection has a set of SNAC groups associated |
23 * In OSCAR, every connection has a set of SNAC groups associated |
| 24 * with it. These are the groups that you can send over this connection |
24 * with it. These are the groups that you can send over this connection |
| 25 * without being guaranteed a "Not supported" SNAC error. |
25 * without being guaranteed a "Not supported" SNAC error. |
| 26 * |
26 * |
| 27 * The grand theory of things says that these associations transcend |
27 * The grand theory of things says that these associations transcend |
| 268 |
265 |
| 269 return newconn; |
266 return newconn; |
| 270 } |
267 } |
| 271 |
268 |
| 272 /** |
269 /** |
| 273 * aim_conn_kill - Close and free a connection. |
|
| 274 * |
|
| 275 * Close, clear, and free a connection structure. Should never be |
270 * Close, clear, and free a connection structure. Should never be |
| 276 * called from within libfaim. |
271 * called from within libfaim. |
| 277 * |
272 * |
| 278 * @param sess Session for the connection |
273 * @param sess Session for the connection. |
| 279 * @param deadconn Connection to be freed |
274 * @param deadconn Connection to be freed. |
| 280 */ |
275 */ |
| 281 faim_export void aim_conn_kill(aim_session_t *sess, aim_conn_t **deadconn) |
276 faim_export void aim_conn_kill(aim_session_t *sess, aim_conn_t **deadconn) |
| 282 { |
277 { |
| 283 aim_conn_t *cur, **prev; |
278 aim_conn_t *cur, **prev; |
| 284 |
279 |
| 300 |
295 |
| 301 return; |
296 return; |
| 302 } |
297 } |
| 303 |
298 |
| 304 /** |
299 /** |
| 305 * aim_conn_close - Close a connection |
|
| 306 * |
|
| 307 * Close (but not free) a connection. |
300 * Close (but not free) a connection. |
| 308 * |
301 * |
| 309 * This leaves everything untouched except for clearing the |
302 * This leaves everything untouched except for clearing the |
| 310 * handler list and setting the fd to -1 (used to recognize |
303 * handler list and setting the fd to -1 (used to recognize |
| 311 * dead connections). It will also remove cookies if necessary. |
304 * dead connections). It will also remove cookies if necessary. |
| 312 * |
305 * |
| 313 * @param deadconn Connection to close |
306 * Why only if fd >= 3? Seems rather implementation specific... |
| |
307 * fd's do not have to be distributed in a particular order, do they? |
| |
308 * |
| |
309 * @param deadconn The connection to close. |
| 314 */ |
310 */ |
| 315 faim_export void aim_conn_close(aim_conn_t *deadconn) |
311 faim_export void aim_conn_close(aim_conn_t *deadconn) |
| 316 { |
312 { |
| 317 aim_rxcallback_t userfunc; |
313 aim_rxcallback_t userfunc; |
| 318 |
314 |
| 329 |
325 |
| 330 return; |
326 return; |
| 331 } |
327 } |
| 332 |
328 |
| 333 /** |
329 /** |
| 334 * aim_getconn_type - Find a connection of a specific type |
330 * Locates a connection of the specified type in the |
| 335 * |
|
| 336 * Searches for a connection of the specified type in the |
|
| 337 * specified session. |
331 * specified session. |
| 338 * |
332 * |
| 339 * XXX except for RENDEZVOUS, all uses of this should be removed and |
333 * XXX - Except for rendezvous, all uses of this should be removed and |
| 340 * use aim_conn_findbygroup() instead. |
334 * aim_conn_findbygroup() should be used instead. |
| 341 * |
335 * |
| 342 * @param sess Session to search |
336 * @param sess The session to search. |
| 343 * @param type Type of connection to look for |
337 * @param type The type of connection to look for. |
| 344 * @return Returns the first connection found of target type |
338 * @return Returns the first connection found of the given target type, |
| |
339 * or NULL if none could be found. |
| 345 */ |
340 */ |
| 346 faim_export aim_conn_t *aim_getconn_type(aim_session_t *sess, int type) |
341 faim_export aim_conn_t *aim_getconn_type(aim_session_t *sess, int type) |
| 347 { |
342 { |
| 348 aim_conn_t *cur; |
343 aim_conn_t *cur; |
| 349 |
344 |
| 380 |
375 |
| 381 return cur; |
376 return cur; |
| 382 } |
377 } |
| 383 |
378 |
| 384 /** |
379 /** |
| 385 * aim_proxyconnect - An extrememly quick and dirty SOCKS5 interface. |
380 * Handle normal connections or SOCKS5 via an extrememly quick and |
| |
381 * dirty SOCKS5 interface. |
| 386 * |
382 * |
| 387 * Attempts to connect to the specified host via the configured |
383 * Attempts to connect to the specified host via the configured |
| 388 * proxy settings, if present. If no proxy is configured for |
384 * proxy settings, if present. If no proxy is configured for |
| 389 * this session, the connection is done directly. |
385 * this session, the connection is done directly. |
| 390 * |
386 * |
| 391 * XXX this is really awful. |
387 * XXX - this is really awful. |
| 392 * |
388 * XXX - Split the SOCKS5 and the normal connection stuff into two |
| 393 * @param sess Session to connect |
389 * separate functions. |
| 394 * @param host Host to connect to |
390 * |
| 395 * @param port Port to connect to |
391 * @param sess Session to connect. |
| 396 * @param statusret Return value of the connection |
392 * @param host Host to connect to. |
| |
393 * @param port Port to connect to. |
| |
394 * @param statusret Return value of the connection. |
| 397 */ |
395 */ |
| 398 static int aim_proxyconnect(aim_session_t *sess, const char *host, fu16_t port, fu32_t *statusret) |
396 static int aim_proxyconnect(aim_session_t *sess, const char *host, fu16_t port, fu32_t *statusret) |
| 399 { |
397 { |
| 400 int fd = -1; |
398 int fd = -1; |
| 401 |
399 |
| 548 } |
546 } |
| 549 return fd; |
547 return fd; |
| 550 } |
548 } |
| 551 |
549 |
| 552 /** |
550 /** |
| 553 * aim_cloneconn - clone an aim_conn_t |
551 * Clone an aim_conn_t. |
| 554 * |
552 * |
| 555 * A new connection is allocated, and the values are filled in |
553 * A new connection is allocated, and the values are filled in |
| 556 * appropriately. Note that this function sets the new connnection's |
554 * appropriately. Note that this function sets the new connnection's |
| 557 * ->priv pointer to be equal to that of its parent: only the pointer |
555 * ->priv pointer to be equal to that of its parent: only the pointer |
| 558 * is copied, not the data it points to. |
556 * is copied, not the data it points to. |
| 559 * |
557 * |
| 560 * @param sess session containing parent |
558 * @param sess The session containing this connection. |
| 561 * @param src connection to clone |
559 * @param src The connection to clone. |
| 562 * @return Returns a pointer to the new aim_conn_t, or %NULL on error |
560 * @return Returns a pointer to the new aim_conn_t, or %NULL on error. |
| 563 */ |
561 */ |
| 564 faim_internal aim_conn_t *aim_cloneconn(aim_session_t *sess, aim_conn_t *src) |
562 faim_internal aim_conn_t *aim_cloneconn(aim_session_t *sess, aim_conn_t *src) |
| 565 { |
563 { |
| 566 aim_conn_t *conn; |
564 aim_conn_t *conn; |
| 567 |
565 |
| 591 |
589 |
| 592 return conn; |
590 return conn; |
| 593 } |
591 } |
| 594 |
592 |
| 595 /** |
593 /** |
| 596 * aim_newconn - Open a new connection |
|
| 597 * |
|
| 598 * Opens a new connection to the specified dest host of specified |
594 * Opens a new connection to the specified dest host of specified |
| 599 * type, using the proxy settings if available. If @host is %NULL, |
595 * type, using the proxy settings if available. If @host is %NULL, |
| 600 * the connection is allocated and returned, but no connection |
596 * the connection is allocated and returned, but no connection |
| 601 * is made. |
597 * is made. |
| 602 * |
598 * |
| 657 |
653 |
| 658 return connstruct; |
654 return connstruct; |
| 659 } |
655 } |
| 660 |
656 |
| 661 /** |
657 /** |
| 662 * aim_conngetmaxfd - Return the highest valued file discriptor in session |
|
| 663 * |
|
| 664 * @param sess Session to search |
|
| 665 * @return Returns the highest values file descriptor of |
|
| 666 * all open connections in @sess |
|
| 667 */ |
|
| 668 faim_export int aim_conngetmaxfd(aim_session_t *sess) |
|
| 669 { |
|
| 670 int j; |
|
| 671 aim_conn_t *cur; |
|
| 672 |
|
| 673 for (cur = sess->connlist, j = 0; cur; cur = cur->next) { |
|
| 674 if (cur->fd > j) |
|
| 675 j = cur->fd; |
|
| 676 } |
|
| 677 |
|
| 678 return j; |
|
| 679 } |
|
| 680 |
|
| 681 /** |
|
| 682 * aim_conn_in_sess - Predicate to test the presense of a connection in a sess |
|
| 683 * |
|
| 684 * Searches @sess for the passed connection. |
658 * Searches @sess for the passed connection. |
| 685 * |
659 * |
| 686 * @param sess Session to look in |
660 * @param sess Session in which to look. |
| 687 * @param conn Connection to look for |
661 * @param conn Connection to look for. |
| 688 * @return Returns 1 if the passed connection is present, zero otherwise |
662 * @return Returns 1 if the passed connection is present, zero otherwise. |
| 689 */ |
663 */ |
| 690 faim_export int aim_conn_in_sess(aim_session_t *sess, aim_conn_t *conn) |
664 faim_export int aim_conn_in_sess(aim_session_t *sess, aim_conn_t *conn) |
| 691 { |
665 { |
| 692 aim_conn_t *cur; |
666 aim_conn_t *cur; |
| 693 |
667 |
| 781 |
753 |
| 782 return NULL; /* no waiting or error, return */ |
754 return NULL; /* no waiting or error, return */ |
| 783 } |
755 } |
| 784 |
756 |
| 785 /** |
757 /** |
| 786 * aim_conn_setlatency - Set a forced latency value for connection |
758 * Set a forced latency value for connection. Basically causes |
| 787 * |
759 * @newval seconds to be spent between transmits on a connection. |
| 788 * Causes @newval seconds to be spent between transmits on a connection. |
|
| 789 * |
760 * |
| 790 * This is my lame attempt at overcoming not understanding the rate |
761 * This is my lame attempt at overcoming not understanding the rate |
| 791 * limiting. |
762 * limiting. |
| 792 * |
763 * |
| 793 * XXX: This should really be replaced with something that scales and |
764 * XXX: This should really be replaced with something that scales and |
| 794 * backs off like the real rate limiting does. |
765 * backs off like the real rate limiting does. |
| 795 * |
766 * |
| 796 * @param conn Conn to set latency for |
767 * @param conn Conn to set latency for. |
| 797 * @param newval Number of seconds to force between transmits |
768 * @param newval Number of seconds to force between transmits. |
| 798 * @return Returns -1 if the connection does not exist, zero otherwise |
769 * @return Returns -1 if the connection does not exist, zero otherwise. |
| 799 */ |
770 */ |
| 800 faim_export int aim_conn_setlatency(aim_conn_t *conn, int newval) |
771 faim_export int aim_conn_setlatency(aim_conn_t *conn, int newval) |
| 801 { |
772 { |
| 802 |
773 |
| 803 if (!conn) |
774 if (!conn) |
| 808 |
779 |
| 809 return 0; |
780 return 0; |
| 810 } |
781 } |
| 811 |
782 |
| 812 /** |
783 /** |
| 813 * aim_setupproxy - Configure a proxy for this session |
784 * Configure a proxy for this session. |
| 814 * |
785 * |
| 815 * Call this with your SOCKS5 proxy server parameters before |
786 * Call this with your SOCKS5 proxy server parameters before |
| 816 * the first call to aim_newconn(). If called with all %NULL |
787 * the first call to aim_newconn(). If called with all %NULL |
| 817 * args, it will clear out a previously set proxy. |
788 * args, it will clear out a previously set proxy. |
| 818 * |
789 * |
| 819 * Set username and password to %NULL if not applicable. |
790 * Set username and password to %NULL if not applicable. |
| 820 * |
791 * |
| 821 * @param sess Session to set proxy for |
792 * @param sess Session to set proxy for. |
| 822 * @param server SOCKS server |
793 * @param server SOCKS server. |
| 823 * @param username SOCKS username |
794 * @param username SOCKS username. |
| 824 * @param password SOCKS password |
795 * @param password SOCKS password. |
| 825 */ |
796 */ |
| 826 faim_export void aim_setupproxy(aim_session_t *sess, const char *server, const char *username, const char *password) |
797 faim_export void aim_setupproxy(aim_session_t *sess, const char *server, const char *username, const char *password) |
| 827 { |
798 { |
| 828 /* clear out the proxy info */ |
799 /* clear out the proxy info */ |
| 829 if (!server || !strlen(server)) { |
800 if (!server || !strlen(server)) { |
| 944 |
915 |
| 945 return; |
916 return; |
| 946 } |
917 } |
| 947 |
918 |
| 948 /** |
919 /** |
| 949 * aim_setdebuggingcb - Set the function to call when outputting debugging info |
920 * Set the function to call when outputting debugging info. |
| 950 * |
921 * |
| 951 * The function specified is called whenever faimdprintf() is used within |
922 * The function specified is called whenever faimdprintf() is used within |
| 952 * libfaim, and the session's debugging level is greater tha nor equal to |
923 * libfaim, and the session's debugging level is greater tha nor equal to |
| 953 * the value faimdprintf was called with. |
924 * the value faimdprintf was called with. |
| 954 * |
925 * |
| 955 * @param sess Session to change |
926 * @param sess Session to change. |
| 956 * @param cb Function to call |
927 * @param cb Function to call. |
| 957 * @return Returns -1 if the session does not exist, zero otherwise |
928 * @return Returns -1 if the session does not exist, zero otherwise. |
| 958 */ |
929 */ |
| 959 faim_export int aim_setdebuggingcb(aim_session_t *sess, faim_debugging_callback_t cb) |
930 faim_export int aim_setdebuggingcb(aim_session_t *sess, faim_debugging_callback_t cb) |
| 960 { |
931 { |
| 961 |
932 |
| 962 if (!sess) |
933 if (!sess) |
| 966 |
937 |
| 967 return 0; |
938 return 0; |
| 968 } |
939 } |
| 969 |
940 |
| 970 /** |
941 /** |
| 971 * aim_conn_isconnecting - Determine if a connection is connecting |
942 * Determine if a connection is connecting. |
| 972 * |
943 * |
| 973 * @param conn Connection to examine |
944 * @param conn Connection to examine. |
| 974 * @return Returns nonzero if the connection is in the process of |
945 * @return Returns nonzero if the connection is in the process of |
| 975 * connecting (or if it just completed and |
946 * connecting (or if it just completed and |
| 976 * aim_conn_completeconnect() has yet to be called on it). |
947 * aim_conn_completeconnect() has yet to be called on it). |
| 977 */ |
948 */ |
| 978 faim_export int aim_conn_isconnecting(aim_conn_t *conn) |
949 faim_export int aim_conn_isconnecting(aim_conn_t *conn) |
| 1017 return NULL; |
988 return NULL; |
| 1018 |
989 |
| 1019 return (aim_session_t *)conn->sessv; |
990 return (aim_session_t *)conn->sessv; |
| 1020 } |
991 } |
| 1021 |
992 |
| 1022 /* |
993 /** |
| 1023 * aim_logoff() |
994 * Close -ALL- open connections. |
| 1024 * |
995 * |
| 1025 * Closes -ALL- open connections. |
996 * @param sess The session. |
| 1026 * |
997 * @return Zero. |
| 1027 */ |
998 */ |
| 1028 faim_export int aim_logoff(aim_session_t *sess) |
999 faim_export int aim_logoff(aim_session_t *sess) |
| 1029 { |
1000 { |
| 1030 |
|
| 1031 aim_connrst(sess); /* in case we want to connect again */ |
1001 aim_connrst(sess); /* in case we want to connect again */ |
| 1032 |
1002 |
| 1033 return 0; |
1003 return 0; |
| 1034 } |
1004 } |
| 1035 |
1005 |
| 1036 /* |
1006 /** |
| 1037 * aim_flap_nop() |
1007 * No-op. This sends an empty channel 5 SNAC. WinAIM 4.x and higher |
| 1038 * |
1008 * sends these _every minute_ to keep the connection alive. |
| 1039 * No-op. WinAIM 4.x sends these _every minute_ to keep |
|
| 1040 * the connection alive. |
|
| 1041 */ |
1009 */ |
| 1042 faim_export int aim_flap_nop(aim_session_t *sess, aim_conn_t *conn) |
1010 faim_export int aim_flap_nop(aim_session_t *sess, aim_conn_t *conn) |
| 1043 { |
1011 { |
| 1044 aim_frame_t *fr; |
1012 aim_frame_t *fr; |
| 1045 |
1013 |