/* * conn.c * * Does all this gloriously nifty connection handling stuff... * */ #include #include "sock.h" static int aim_logoff(aim_session_t *sess); /* * In OSCAR, every connection has a set of SNAC groups associated * with it. These are the groups that you can send over this connection * without being guarenteed a "Not supported" SNAC error. * * The grand theory of things says that these associations transcend * what libfaim calls "connection types" (conn->type). You can probably * see the elegance here, but since I want to revel in it for a bit, you * get to hear it all spelled out. * * So let us say that you have your core BOS connection running. One * of your modules has just given you a SNAC of the group 0x0004 to send * you. Maybe an IM destined for some twit in Greenland. So you start * at the top of your connection list, looking for a connection that * claims to support group 0x0004. You find one. Why, that neat BOS * connection of yours can do that. So you send it on its way. * * Now, say, that fellow from Greenland has friends and they all want to * meet up with you in a lame chat room. This has landed you a SNAC * in the family 0x000e and you have to admit you're a bit lost. You've * searched your connection list for someone who wants to make your life * easy and deliver this SNAC for you, but there isn't one there. * * Here comes the good bit. Without even letting anyone know, particularly * the module that decided to send this SNAC, and definitly not that twit * in Greenland, you send out a service request. In this request, you have * marked the need for a connection supporting group 0x000e. A few seconds * later, you receive a service redirect with an IP address and a cookie in * it. Great, you say. Now I have something to do. Off you go, making * that connection. One of the first things you get from this new server * is a message saying that indeed it does support the group you were looking * for. So you continue and send rate confirmation and all that. * * Then you remember you had that SNAC to send, and now you have a means to * do it, and you do, and everyone is happy. Except the Greenlander, who is * still stuck in the bitter cold. * * Oh, and this is useful for building the Migration SNACs, too. In the * future, this may help convince me to implement rate limit mitigation * for real. We'll see. * * Just to make me look better, I'll say that I've known about this great * scheme for quite some time now. But I still haven't convinced myself * to make libfaim work that way. It would take a fair amount of effort, * and probably some client API changes as well. (Whenever I don't want * to do something, I just say it would change the client API. Then I * instantly have a couple of supporters of not doing it.) * * Generally, addgroup is only called by the internal handling of the * server ready SNAC. So if you want to do something before that, you'll * have to be more creative. That is done rather early, though, so I don't * think you have to worry about it. Unless you're me. I care deeply * about such inane things. * */ void aim_conn_addgroup(aim_conn_t *conn, guint16 group) { aim_conn_inside_t *ins = (aim_conn_inside_t *)conn->inside; struct snacgroup *sg; if (!(sg = g_malloc(sizeof(struct snacgroup)))) return; sg->group = group; sg->next = ins->groups; ins->groups = sg; return; } aim_conn_t *aim_conn_findbygroup(aim_session_t *sess, guint16 group) { aim_conn_t *cur; for (cur = sess->connlist; cur; cur = cur->next) { aim_conn_inside_t *ins = (aim_conn_inside_t *)cur->inside; struct snacgroup *sg; for (sg = ins->groups; sg; sg = sg->next) { if (sg->group == group) return cur; } } return NULL; } static void connkill_snacgroups(struct snacgroup **head) { struct snacgroup *sg; for (sg = *head; sg; ) { struct snacgroup *tmp; tmp = sg->next; g_free(sg); sg = tmp; } *head = NULL; return; } static void connkill_rates(struct rateclass **head) { struct rateclass *rc; for (rc = *head; rc; ) { struct rateclass *tmp; struct snacpair *sp; tmp = rc->next; for (sp = rc->members; sp; ) { struct snacpair *tmpsp; tmpsp = sp->next; g_free(sp); sp = tmpsp; } g_free(rc); rc = tmp; } *head = NULL; return; } static void connkill_real(aim_session_t *sess, aim_conn_t **deadconn) { aim_rxqueue_cleanbyconn(sess, *deadconn); aim_tx_cleanqueue(sess, *deadconn); if ((*deadconn)->fd != -1) aim_conn_close(*deadconn); /* * XXX ->priv should never be touched by the library. I know * it used to be, but I'm getting rid of all that. Use * ->internal instead. */ if ((*deadconn)->priv) g_free((*deadconn)->priv); /* * This
/*
 * libyahoo2: yahoo_debug.h
 *
 * Copyright (C) 2002-2004, Philip S Tellis <philip.tellis AT gmx.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

extern int yahoo_log_message(char *fmt, ...);

#define NOTICE(x) if (yahoo_get_log_level() >= YAHOO_LOG_NOTICE) { yahoo_log_message x; yahoo_log_message("\n"); }

#define LOG(x) if (yahoo_get_log_level() >= YAHOO_LOG_INFO) { yahoo_log_message("%s:%d: ", __FILE__, __LINE__); \
		                                              yahoo_log_message x; \
		                                              yahoo_log_message("\n"); }

#define WARNING(x) if (yahoo_get_log_level() >= YAHOO_LOG_WARNING) { yahoo_log_message("%s:%d: warning: ", __FILE__, \
		                                                                       __LINE__); \
		                                                     yahoo_log_message x; \
		                                                     yahoo_log_message("\n"); }

#define DEBUG_MSG(x) if (yahoo_get_log_level() >= YAHOO_LOG_DEBUG) { yahoo_log_message("%s:%d: debug: ", __FILE__, \
		                                                                       __LINE__); \
		                                                     yahoo_log_message x; \
		                                                     yahoo_log_message("\n"); }
st); /* missing 0x0f - 0x12 */ aim__registermodule(sess, ssi_modfirst); /* missing 0x14 */ aim__registermodule(sess, icq_modfirst); /* missing 0x16 */ aim__registermodule(sess, auth_modfirst); return; } /** * aim_session_kill - Deallocate a session * @sess: Session to kill * */ void aim_session_kill(aim_session_t *sess) { aim_cleansnacs(sess, -1); aim_logoff(sess); aim__shutdownmodules(sess); return; } /* * XXX this is nearly as ugly as proxyconnect(). */ int aim_conn_completeconnect(aim_session_t *sess, aim_conn_t *conn) { fd_set fds, wfds; struct timeval tv; int res, error = ETIMEDOUT; aim_rxcallback_t userfunc; if (!conn || (conn->fd == -1)) return -1; if (!(conn->status & AIM_CONN_STATUS_INPROGRESS)) return -1; FD_ZERO(&fds); FD_SET(conn->fd, &fds); FD_ZERO(&wfds); FD_SET(conn->fd, &wfds); tv.tv_sec = 0; tv.tv_usec = 0; if ((res = select(conn->fd+1, &fds, &wfds, NULL, &tv)) == -1) { error = errno; aim_conn_close(conn); errno = error; return -1; } else if (res == 0) { return 0; /* hasn't really completed yet... */ } if (FD_ISSET(conn->fd, &fds) || FD_ISSET(conn->fd, &wfds)) { unsigned int len = sizeof(error); if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) error = errno; } if (error) { aim_conn_close(conn); errno = error; return -1; } sock_make_blocking(conn->fd); conn->status &= ~AIM_CONN_STATUS_INPROGRESS; if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE))) userfunc(sess, NULL, conn); /* Flush out the queues if there was something waiting for this conn */ aim_tx_flushqueue(sess); return 0; } aim_session_t *aim_conn_getsess(aim_conn_t *conn) { if (!conn) return NULL; return (aim_session_t *)conn->sessv; } /* * aim_logoff() * * Closes -ALL- open connections. * */ static int aim_logoff(aim_session_t *sess) { aim_connrst(sess); /* in case we want to connect again */ return 0; } /* * aim_flap_nop() * * No-op. WinAIM 4.x sends these _every minute_ to keep * the connection alive. */ int aim_flap_nop(aim_session_t *sess, aim_conn_t *conn) { aim_frame_t *fr; if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x05, 0))) return -ENOMEM; aim_tx_enqueue(sess, fr); return 0; }