}
+/*
+ * Initialize a new context and place it in the list. The session number
+ * used to be the PID (which is why it's called cs_pid), but that was when we
+ * had one process per session. Now we just assign them sequentially, starting
+ * at 1 (don't change it to 0 because masterCC uses 0).
+ */
+CitContext *CloneContext(CitContext *CloneMe) {
+ CitContext *me;
+ static int next_pid = 0;
+
+ me = (CitContext *) malloc(sizeof(CitContext));
+ if (me == NULL) {
+ CtdlLogPrintf(CTDL_ALERT, "citserver: can't allocate memory!!\n");
+ return NULL;
+ }
+ memcpy(me, CloneMe, sizeof(CitContext));
+
+ memset(&me->RecvBuf, 0, sizeof(IOBuffer));
+ memset(&me->SendBuf, 0, sizeof(IOBuffer));
+ memset(&me->SBuf, 0, sizeof(IOBuffer));
+ me->MigrateBuf = NULL;
+ me->sMigrateBuf = NULL;
+ me->redirect_buffer = NULL;
+#ifdef HAVE_OPENSSL
+ me->ssl = NULL;
+#endif
+
+ me->download_fp = NULL;
+ me->upload_fp = NULL;
+ /// TODO: what about the room/user?
+ me->ma = NULL;
+ me->openid_data = NULL;
+ me->ldap_dn = NULL;
+ me->session_specific_data = NULL;
+
+ me->MigrateBuf = NewStrBuf();
+ me->RecvBuf.Buf = NewStrBuf();
+
+ begin_critical_section(S_SESSION_TABLE);
+ {
+ me->cs_pid = ++next_pid;
+ me->prev = NULL;
+ me->next = ContextList;
+ me->lastcmd = time(NULL); /* set lastcmd to now to prevent idle timer infanticide */
+ ContextList = me;
+ if (me->next != NULL) {
+ me->next->prev = me;
+ }
+ ++num_sessions;
+ }
+ end_critical_section(S_SESSION_TABLE);
+ return (me);
+}
+
+
/*
* Return an array containing a copy of the context list.
* This allows worker threads to perform "for each context" operations without
void dead_session_purge(int force);
void set_async_waiting(struct CitContext *ccptr);
+CitContext *CloneContext(CitContext *CloneMe);
+
/* forcibly close and flush fd's on shutdown */
void terminate_stuck_sessions(void);
IO->DNSChannel = NULL;
}
assert(IO->Terminate);
+ become_session(IO->CitContext);
IO->Terminate(IO);
}
{
eReadState Finished = eBufferNotEmpty;
+ become_session(IO->CitContext);
+
while ((Finished == eBufferNotEmpty) && (IO->NextState == eReadMessage)){
if (IO->RecvBuf.nBlobBytesWanted != 0) {
int rc;
AsyncIO *IO = watcher->data;
+ become_session(IO->CitContext);
rc = StrBuf_write_one_chunk_callback(watcher->fd, 0/*TODO*/, &IO->SendBuf);
if (rc == 0)
break;
case eSendReply:
case eSendMore:
+ become_session(IO->CitContext);
IO_send_callback(loop, &IO->send_event, revents);
break;
case eTerminateConnection:
AsyncIO *IO = watcher->data;
ev_timer_stop (event_base, &IO->rw_timeout);
+ become_session(IO->CitContext);
+
assert(IO->Timeout);
IO->Timeout(IO);
}
ev_timer_stop (event_base, &IO->conn_fail);
ev_io_stop(loop, &IO->conn_event);
+ become_session(IO->CitContext);
+
assert(IO->ConnFail);
IO->ConnFail(IO);
}
{
AsyncIO *IO = watcher->data;
CtdlLogPrintf(CTDL_DEBUG, "event: %s\n", __FUNCTION__);
+ become_session(IO->CitContext);
IO->DNSQuery->PostDNS(IO);
}
int ReadFirst)
{
IO->Data = pData;
+ become_session(IO->CitContext);
if (ReadFirst) {
IO->NextState = eReadMessage;
RemoveQItem(Msg->MyQItem);
}
+
+ RemoveContext(Msg->IO.CitContext);
DeleteSmtpOutMsg(Msg);
}
else SendMsg->msgtext = NewStrBufDup(MsgText);
if (smtp_resolve_recipients(SendMsg)) {
-
-
-
+ CitContext *SubC;
+ SubC = CloneContext (CC);
+ SubC->session_specific_data = (char*) SendMsg;
+ SendMsg->IO.CitContext = SubC;
if (SendMsg->pCurrRelay == NULL)
QueueEventContext(&SendMsg->IO,