SMTP_SESSION *smtp_session_alloc(VSTREAM *stream, const char *dest, const char *host, const char *addr, unsigned port, time_t start, int flags) { SMTP_SESSION *session; session = (SMTP_SESSION *) mymalloc(sizeof(*session)); session->stream = stream; session->dest = mystrdup(dest); session->host = mystrdup(host); session->addr = mystrdup(addr); session->namaddr = concatenate(host, "[", addr, "]", (char *) 0); session->helo = 0; session->port = port; session->features = 0; session->size_limit = 0; session->error_mask = 0; session->buffer = vstring_alloc(100); session->scratch = vstring_alloc(100); session->scratch2 = vstring_alloc(100); smtp_chat_init(session); session->mime_state = 0; if (session->port) { vstring_sprintf(session->buffer, "%s:%d", session->namaddr, ntohs(session->port)); session->namaddrport = mystrdup(STR(session->buffer)); } else session->namaddrport = mystrdup(session->namaddr); session->send_proto_helo = 0; if (flags & SMTP_MISC_FLAG_CONN_STORE) CACHE_THIS_SESSION_UNTIL(start + var_smtp_reuse_time); else DONT_CACHE_THIS_SESSION; session->reuse_count = 0; USE_NEWBORN_SESSION; /* He's not dead Jim! */ #ifdef USE_SASL_AUTH smtp_sasl_connect(session); #endif /* * Need to pass the session as a parameter when the new-style per-nexthop * policies can specify not only security level thresholds, but also how * security levels are defined. */ #ifdef USE_TLS session_tls_init(session, dest, host, flags); #endif session->state = 0; debug_peer_check(host, addr); return (session); }
lagopus_result_t session_create(session_type_t t, lagopus_session_t *session) { lagopus_result_t ret; lagopus_session_t s; if (!(t & (SESSION_PASSIVE | SESSION_ACTIVE | SESSION_ACCEPTED | SESSION_UNIX_STREAM | SESSION_UNIX_DGRAM))) { lagopus_msg_warning("illegal session type: 0x%x\n", t); return LAGOPUS_RESULT_INVALID_ARGS; } if (session == NULL) { return LAGOPUS_RESULT_INVALID_ARGS; } lagopus_msg_debug(5, "s_server_session %x.\n", t); s = malloc(sizeof(struct session)); if (s == NULL) { return LAGOPUS_RESULT_NO_MEMORY; } s->sock = -1; s->accept = NULL; s->connect = NULL; s->read = NULL; s->write = NULL; s->close = close_default; s->destroy = NULL; s->connect_check = NULL; s->ctx = NULL; s->session_type = t; s->events = 0; memset(&s->rbuf.buf, 0, sizeof(s->rbuf.buf)); s->rbuf.rp = s->rbuf.ep = s->rbuf.buf; lagopus_msg_debug(5, "s_server_session %x, SESSION_TCP %x.\n", t, SESSION_TCP); if (t & SESSION_TCP) { s->family = PF_INET; s->type = SOCK_STREAM; } else if (t & SESSION_TCP6) { s->family = PF_INET6; s->type = SOCK_STREAM; } else if (t & SESSION_UNIX_STREAM) { s->family = PF_UNIX; s->type = SOCK_STREAM; } else if (t & SESSION_UNIX_DGRAM) { s->family = PF_UNIX; s->type = SOCK_DGRAM; } else { ret = LAGOPUS_RESULT_INVALID_ARGS; goto err; } lagopus_msg_debug(5, "s_server_session %x, SESSION_TLS %x.\n", t, SESSION_TLS); lagopus_msg_debug(5, "lagopus_session_t s %p.\n", s); if (t & SESSION_TLS) { lagopus_msg_debug(5, "session_tls_init.\n"); ret = session_tls_init(s); if (ret != LAGOPUS_RESULT_OK) { goto err; } } else if (t & (SESSION_TCP | SESSION_TCP6 | SESSION_UNIX_STREAM | SESSION_UNIX_DGRAM)) { ret = session_tcp_init(s); if (ret != LAGOPUS_RESULT_OK) { goto err; } } else { ret = LAGOPUS_RESULT_INVALID_ARGS; goto err; } *session = s; return LAGOPUS_RESULT_OK; err: lagopus_msg_warning("illegal session type: 0x%x\n", t); free(s); *session = NULL; return ret; }