Example #1
0
static int init_child_context (
    TCB                    *tcb, 
    struct_smtsmtp_message *message, 
    QID                     reply_to,
    event_t                 event_number)
{
    ASSERT (tcb);

  START_BODY
    tcb-> thread_type = event_number;
    tcb-> message = message;
    tcb-> reply_to = reply_to;

    tcb-> message_boundary = generate_unique_boundary ();
    RAISE_EXC_IF (!tcb-> message_boundary, memory_error_event);
    tcb-> plain_text_body_header = xstrcpy (
        NULL, 
        "\r\n--", 
        tcb-> message_boundary, 
        "\r\n"
        "Content-Type: text/plain; charset=US-ASCII\r\n"
        "Content-Transfer-Encoding: 7BIT\r\n"
        "Content-description: Body of message\r\n\r\n",
        NULL
      );
    RAISE_EXC_IF (!tcb-> plain_text_body_header, memory_error_event);
  END_BODY
      
    return 0;
}
Example #2
0
MODULE build_socket_read_closed_error (THREAD *thread)
{
#if 0
    struct_smtsock_read_closed
        *sock_read_read_closed = NULL;
    int
        rc;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

  START_BODY
    get_smtsock_read_closed  (thread-> event-> body, &sock_read_read_closed);

    strcpy (operation, "Read");

    rc = snprintf (
        strout,
        STROUT_SIZE,
        "%s on socket[%li] failed: socket closed by peer",
        operation,
        tcb-> sock_handle);
    RAISE_EXC_IF (rc <= 0, snprintf_error_event);

    set_error (tcb, ERROR_CODE, strout, NULL);
  END_BODY

    if (sock_read_read_closed)
        free_smtsock_read_closed (&sock_read_read_closed);
#endif
}
Example #3
0
MODULE create_child_thread (THREAD *thread)
{
    THREAD
        *child = NULL;
    TCB
        *child_tcb = NULL;
    struct_smtsmtp_message
        *event = NULL;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

  START_BODY
    get_smtsmtp_message (thread-> event-> body, &event);

    child = thread_create (AGENT_NAME, "");
    RAISE_EXC_IF (child == NULL, undefined_event);
    
    child_tcb = child-> tcb;
    clear_context (child_tcb);
    
    init_child_context (child_tcb, event, 
                        thread-> event-> sender,
                        thread-> event-> event_number);
    CHECK_EXC;
    event = NULL;

  END_BODY

    if (event)
        free_smtsmtp_message (&event);
}
Example #4
0
MODULE write_text_body (THREAD *thread)
{
    char
        *body_buffer;
    int
        body_size;

    tcb = thread-> tcb;                 /*  Point to thread's context        */
    smtp_msg = tcb-> message;           /*  only for readability             */


    if (smtp_msg-> msg_body && *smtp_msg-> msg_body)
      {
  START_BODY
        body_size = strlen (smtp_msg-> msg_body)
                  + extra_characters_required (smtp_msg-> msg_body);

        body_buffer = (char *) mem_alloc (body_size + 1);
        RAISE_EXC_IF (!body_buffer, memory_error_event);

        strclr (body_buffer);
        append_msg_body (body_buffer, smtp_msg-> msg_body);

        send_smtsock_writeh(
            &sockq,
            0,                              /* Timeout in sec, zero = none */
            tcb-> sock_handle,              /* Socket to write to */
            (qbyte)strlen(body_buffer),     /* Amount of data to write */
            (byte*)body_buffer,             /* Block of data to write */
            FALSE,                          /* Whether to always reply */
            (void *) SOCK_TAG_WRITE);       /* User-defined request tag */
        TRACE_SMTP (body_buffer);
        mem_free (body_buffer);
  END_BODY
      }
Example #5
0
File: smtsmtp.c Project: imatix/gsl
MODULE build_socket_timeout_error (THREAD *thread)
{
#if 0
    STRUCT_SMTSOCK_TIMEOUT
    *sock_read_timeout = NULL;
    int
    rc;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    START_BODY
    GET_SMTSOCK_TIMEOUT  (thread-> event-> body, &sock_read_timeout);

    /*  JS: Note that the only socket request that can timeout in this       */
    /*      is connect.                                                      */
    switch (sock_read_timeout-> tag)
    {
    case SOCK_TAG_CONNECT:
        strcpy (operation, "Connect");
        break;
    /*          case SOCK_TAG_READ:         strcpy (operation, "Read");    break; */
    case SOCK_TAG_WRITE:
        strcpy (operation, "Write");
        break;
    case SOCK_TAG_INPUT:
        strcpy (operation, "Connect");
        break;
    case SOCK_TAG_OUTPUT:
        strcpy (operation, "Output");
        break;
    }

    rc = snprintf (
             strout,
             STROUT_SIZE,
             "%s failed on socket [%li]: timeout expired",
             operation,
             tcb-> sock_handle);
    RAISE_EXC_IF (rc <= 0, snprintf_error_event);

    set_error (tcb, ERROR_CODE, strout, NULL);
    END_BODY

    if (sock_read_timeout)
        FREE_SMTSOCK_TIMEOUT (&sock_read_timeout);
#endif
}
Example #6
0
File: smtsmtp.c Project: imatix/gsl
MODULE build_socket_error (THREAD *thread)
{
    struct_smtsock_error
    *sock_error = NULL;
    int
    rc;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    START_BODY
    get_smtsock_error (thread-> event-> body, &sock_error);

    switch ((long) sock_error-> tag)
    {
    case SOCK_TAG_CONNECT:
        strcpy (operation, "Connect");
        break;
    case SOCK_TAG_READ:
        strcpy (operation, "Read");
        break;
    case SOCK_TAG_WRITE:
        strcpy (operation, "Write");
        break;
    case SOCK_TAG_INPUT:
        strcpy (operation, "Connect");
        break;
    case SOCK_TAG_OUTPUT:
        strcpy (operation, "Output");
        break;
    }

    rc = snprintf (
             strout,
             STROUT_SIZE,
             "%s on socket[%li] failed: %s",
             operation,
             (long) tcb-> sock_handle,
             sock_error-> message);
    RAISE_EXC_IF (rc <= 0, snprintf_error_event);

    set_error (tcb, ERROR_CODE, strout, NULL);
    END_BODY

    if (sock_error)
        free_smtsock_error (&sock_error);
}
Example #7
0
File: smtsmtp.c Project: imatix/gsl
MODULE build_socket_closed_error (THREAD *thread)
{
#if 0
    STRUCT_SMTSOCK_CLOSED
    *sock_read_closed = NULL;
    int
    rc;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

    START_BODY

    GET_SMTSOCK_CLOSED  (thread-> event-> body, &sock_read_closed);

    switch (sock_read_closed-> tag)
    {
    case SOCK_TAG_CONNECT:
        strcpy (operation, "Connect");
        break;
    /*      case SOCK_TAG_READ:         strcpy (operation, "Read");    break; */
    case SOCK_TAG_WRITE:
        strcpy (operation, "Write");
        break;
    case SOCK_TAG_INPUT:
        strcpy (operation, "Connect");
        break;
    case SOCK_TAG_OUTPUT:
        strcpy (operation, "Output");
        break;
    }

    rc = snprintf (
             strout,
             STROUT_SIZE,
             "%s on socket[%li] failed: socket closed by peer",
             operation,
             tcb-> sock_handle);
    RAISE_EXC_IF (rc <= 0, snprintf_error_event);

    set_error (tcb, ERROR_CODE, strout, NULL);

    END_BODY

    FREE_SMTSOCK_CLOSED (&sock_read_closed);
#endif
}
Example #8
0
MODULE check_server_response (THREAD *thread)
{
    struct_smtsock_read_reply 
        *sock_read_ok = NULL;
    int 
        error_code;
    byte 
        saved = 0;
    char 
        *sock_read_ok_data = NULL;

    tcb = thread-> tcb;                 /*  Point to thread's context        */

  START_BODY
    get_smtsock_read_reply (thread-> event-> body, &sock_read_ok);

    if (sock_read_ok-> size <= 0)
        set_error (tcb, ERROR_CODE, "Out of memory", NULL);
    RAISE_EXC_IF (sock_read_ok-> size <= 0, memory_error_event);

    sock_read_ok_data = (char *) sock_read_ok-> data;

    saved = sock_read_ok_data[sock_read_ok-> size];
    sock_read_ok_data[sock_read_ok-> size] = 0;
    strcrop (sock_read_ok_data);

    if ((error_code = atoi (sock_read_ok_data)) > SMTP_SERVER_ERROR)
      {
         set_error (tcb, ERROR_CODE, 
                    "REFUSED by SMTP server: ", sock_read_ok_data, NULL);
         raise_exception (server_response_error_event);
      }
    CHECK_EXC;

    the_next_event = server_response_ok_event;
    sock_read_ok_data[sock_read_ok-> size] = saved;
  END_BODY

    if (sock_read_ok)
        free_smtsock_read_reply (&sock_read_ok);
}