void mwSession_start(struct mwSession *s) { struct mwMsgHandshake *msg; int ret; g_return_if_fail(s != NULL); g_return_if_fail(mwSession_isStopped(s)); if(mwSession_isStarted(s) || mwSession_isStarting(s)) { g_debug("attempted to start session that is already started/starting"); return; } state(s, mwSession_STARTING, 0); msg = (struct mwMsgHandshake *) mwMessage_new(mwMessage_HANDSHAKE); msg->major = GUINT(property_get(s, mwSession_CLIENT_VER_MAJOR)); msg->minor = GUINT(property_get(s, mwSession_CLIENT_VER_MINOR)); msg->login_type = GUINT(property_get(s, mwSession_CLIENT_TYPE_ID)); msg->loclcalc_addr = GUINT(property_get(s, mwSession_CLIENT_IP)); if(msg->major >= 0x001e && msg->minor >= 0x001d) { msg->unknown_a = 0x0100; msg->local_host = property_get(s, mwSession_CLIENT_HOST); } ret = mwSession_send(s, MW_MESSAGE(msg)); mwMessage_free(MW_MESSAGE(msg)); if(ret) { mwSession_stop(s, CONNECTION_BROKEN); } else { state(s, mwSession_HANDSHAKE, 0); } }
void mwSession_stop(struct mwSession *s, guint32 reason) { GList *list, *l = NULL; struct mwMsgChannelDestroy *msg; g_return_if_fail(s != NULL); if(mwSession_isStopped(s) || mwSession_isStopping(s)) { g_debug("attempted to stop session that is already stopped/stopping"); return; } state(s, mwSession_STOPPING, GUINT_TO_POINTER(reason)); for(list = l = mwSession_getServices(s); l; l = l->next) mwService_stop(MW_SERVICE(l->data)); g_list_free(list); msg = (struct mwMsgChannelDestroy *) mwMessage_new(mwMessage_CHANNEL_DESTROY); msg->head.channel = MW_MASTER_CHANNEL_ID; msg->reason = reason; /* don't care if this fails, we're closing the connection anyway */ mwSession_send(s, MW_MESSAGE(msg)); mwMessage_free(MW_MESSAGE(msg)); session_buf_free(s); /* close the connection */ io_close(s); state(s, mwSession_STOPPED, GUINT_TO_POINTER(reason)); }
void mwSession_free(struct mwSession *s) { struct mwSessionHandler *h; g_return_if_fail(s != NULL); if(! mwSession_isStopped(s)) { g_debug("session is not stopped (state: %s), proceeding with free", state_str(s->state)); } h = s->handler; if(h && h->clear) h->clear(s); s->handler = NULL; session_buf_free(s); mwChannelSet_free(s->channels); g_hash_table_destroy(s->services); g_hash_table_destroy(s->ciphers); g_hash_table_destroy(s->attributes); mwLoginInfo_clear(&s->login); mwUserStatus_clear(&s->status); mwPrivacyInfo_clear(&s->privacy); g_free(s); }
int CSametimeProto::LogOut() { debugLog(_T("LogOut() start")); continue_connect = false; EnterCriticalSection(&session_cs); if (session && server_connection && m_iStatus != ID_STATUS_OFFLINE && !mwSession_isStopped(session) && !mwSession_isStopping(session)) { debugLog(_T("LogOut() mwSession_stop")); mwSession_stop(session, 0); } LeaveCriticalSection(&session_cs); return 0; }