src/protocols/oscar/conn.c

changeset 8880
15b365a0a7fe
parent 8866
8a910a9b8865
child 8888
2e0a3c5d3629
equal deleted inserted replaced
8879:0dbcd2937463 8880:15b365a0a7fe
1 /* 1 /*
2 * conn.c 2 * Low-level connection handling.
3 * 3 *
4 * Does all this gloriously nifty connection handling stuff... 4 * Does all this gloriously nifty connection handling stuff...
5 * 5 *
6 */ 6 */
7 7
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
189 189
190 return; 190 return;
191 } 191 }
192 192
193 /** 193 /**
194 * Clears out connection list, killing remaining connections. 194 * Clears out the connection list, killing remaining connections.
195 * 195 *
196 * @param sess Session to be cleared 196 * @param sess Session to be cleared.
197 */ 197 */
198 static void aim_connrst(aim_session_t *sess) 198 static void aim_connrst(aim_session_t *sess)
199 { 199 {
200 200
201 if (sess->connlist) { 201 if (sess->connlist) {
213 213
214 return; 214 return;
215 } 215 }
216 216
217 /** 217 /**
218 * Reset a connection to default values. 218 * Initializes and/or resets a connection structure to the default values.
219 * Initializes and/or resets a connection structure. 219 *
220 * 220 * @param deadconn Connection to be reset.
221 * @param deadconn Connection to be reset
222 */ 221 */
223 static void aim_conn_init(aim_conn_t *deadconn) 222 static void aim_conn_init(aim_conn_t *deadconn)
224 { 223 {
225 224
226 if (!deadconn) 225 if (!deadconn)
238 237
239 return; 238 return;
240 } 239 }
241 240
242 /** 241 /**
243 * aim_conn_getnext - Gets a new connection structure.
244 *
245 * Allocate a new empty connection structure. 242 * Allocate a new empty connection structure.
246 * 243 *
247 * @param sess Session 244 * @param sess Session
248 * @return Returns new connection structure 245 * @return Returns the new connection structure.
249 */ 246 */
250 static aim_conn_t *aim_conn_getnext(aim_session_t *sess) 247 static aim_conn_t *aim_conn_getnext(aim_session_t *sess)
251 { 248 {
252 aim_conn_t *newconn; 249 aim_conn_t *newconn;
253 250
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
698 672
699 return 0; 673 return 0;
700 } 674 }
701 675
702 /** 676 /**
703 * aim_select - Wait for a socket with data or timeout
704 *
705 * Waits for a socket with data or for timeout, whichever comes first. 677 * Waits for a socket with data or for timeout, whichever comes first.
706 * See select(2). 678 * See select(2).
707 * 679 *
708 * Return codes in *status: 680 * Return codes in *status:
709 * -1 error in select() (%NULL returned) 681 * -1 error in select() (%NULL returned)
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)) {
928 899
929 return; 900 return;
930 } 901 }
931 902
932 /** 903 /**
933 * aim_session_kill - Deallocate a session 904 * Logoff and deallocate a session.
934 * 905 *
935 * @param sess Session to kill 906 * @param sess Session to kill
936 */ 907 */
937 faim_export void aim_session_kill(aim_session_t *sess) 908 faim_export void aim_session_kill(aim_session_t *sess)
938 { 909 {
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

mercurial