예제 #1
0
void connection_delete(connection_t* con)
{
    mailbox_delete_all(con->index);
    shutdown(con->socket, SHUT_RDWR);
    connection_close(con);

    tims_dbgdetail("connection[%i] closed\n", con->index);
}
예제 #2
0
void mailbox_purge(connection_t *con)
{
    tims_print("con[%02d]: %s: purge\n", con->index,
               inet_ntoa(conList[con->index].addr.sin_addr));

    mailbox_delete_all(con->index);

//TODO: delete all mailboxes @ next level TCP Router

}
예제 #3
0
파일: mail.c 프로젝트: 91D2/pvpgn
static void mail_func_delete(t_connection * c, const char * str) {
   t_account * user;
   t_mailbox * mailbox;
   const char * p;
   char tmp[256]; /* that should be enough */
   int i;
   
   if (c==NULL) {
      eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
      return;
   }
   if (str==NULL) {
      eventlog(eventlog_level_error,__FUNCTION__,"got NULL command string");
      return;
   }
   for(i=0;str[i]==' ';i++);
   p=str+i;
   if (*p=='\0') {
      message_send_text(c,message_type_error,c,"Please specify which message to delete. Use the following syntax: /mail delete {<index>|all} .");
      return;
   }
   if ((user=conn_get_account(c))==NULL) {
      eventlog(eventlog_level_error,__FUNCTION__,"got NULL account");
      return;
   }
   if ((mailbox=mailbox_open(user, mbox_mode_write))==NULL) {
      eventlog(eventlog_level_error,__FUNCTION__,"got NULL mailbox");
      return;
   }
   if (strcmp(p,"all")==0) {
      int rez;
      
      if ((rez=mailbox_delete_all(mailbox))<0) {
	 message_send_text(c,message_type_error,c,"There was an error completing your request.");
	 mailbox_close(mailbox);
	 return;
      }
      sprintf(tmp,"Successfuly deleted %d messages.",rez);
      message_send_text(c,message_type_info,c,tmp);
   }
   else {
      int idx;
      
      for(i=0;p[i]>='0' && p[i]<='9' && p[i]!='\0';i++);
      if (p[i]!='\0' && p[i]!=' ') {
	 message_send_text(c,message_type_error,c,"Invalid index. Please use /mail delete {<index>|all} where <index> is a number.");
	 mailbox_close(mailbox);
	 return;
      }
      idx=atoi(p);
      if (idx<1 || idx>mailbox_count(mailbox)) {
	 message_send_text(c,message_type_error,c,"That index is out of range.");
	 mailbox_close(mailbox);
	 return;
      }
      if (mailbox_delete(mailbox,idx)<0) {
	 message_send_text(c,message_type_error,c,"There was an error completing your request.");
	 mailbox_close(mailbox);
	 return;
      }
      sprintf(tmp,"Succesfully deleted message #%02d.",idx);
      message_send_text(c,message_type_info,c,tmp);
   }
   mailbox_close(mailbox);
}
예제 #4
0
// the tcpConnection_task_proc handles the connection to one client
void tcpConnection_task_proc(void *arg)
{
    tims_msg_head*        tcpMsg;
    connection_t*         con = (connection_t*)arg;
    tims_msg_head         replyMsg;
    int                   forwardConIndex;
    int                   ret, idx;

    signal(SIGHUP,  signal_handler);
    signal(SIGINT,  signal_handler);
    signal(SIGTERM, signal_handler);
    signal(SIGPIPE, signal_handler);

    idx = con->index;

    tims_dbg("con[%02d]: %s: starting TCP/IP connection task\n",
             idx, inet_ntoa(con->addr.sin_addr));

    tcpMsg = malloc(maxMsgSize);
    if (!tcpMsg)
    {
        tims_print("con[%02d] %s error: Can't allocate memory for tcpTimsMsg\n",
                   idx, inet_ntoa(con->addr.sin_addr));
        connection_close(con);
        return;
    }

    while (!terminate)
    {
        if (con->socket < 0)    // invalid socket
            break;

        ret = recvTcpTimsMsg(con, tcpMsg); // waiting for new command
        if (ret < 0)
            break;

        if ( !tcpMsg->dest &&
             !tcpMsg->src )  // handle TiMS command (internal)
        {
            switch (tcpMsg->type)
            {
                case TIMS_MSG_OK:        // watchdog lifesign reply
                    con->watchdog = 0;
                    break;

                case TIMS_MSG_ROUTER_LOGIN:
                    break;

                case TIMS_MSG_ROUTER_MBX_INIT:
                    mailbox_init(con, tcpMsg, NULL);
                    break;

                case TIMS_MSG_ROUTER_MBX_DELETE:
                    mailbox_cleanup(con, tcpMsg, NULL);
                    break;

                case TIMS_MSG_ROUTER_MBX_INIT_WITH_REPLY:
                    mailbox_init(con, tcpMsg, &replyMsg);
                    break;

                case TIMS_MSG_ROUTER_MBX_DELETE_WITH_REPLY:
                    mailbox_cleanup(con, tcpMsg, &replyMsg);
                    break;

                case TIMS_MSG_ROUTER_MBX_PURGE:
                    mailbox_purge(con);
                    break;

                default:
                    tims_print("con[%02d]: %s: received unexpected TiMS "
                               "Message %x -> %x type %i msglen %i\n", idx,
                               inet_ntoa(con->addr.sin_addr), tcpMsg->src,
                               tcpMsg->dest, tcpMsg->type, tcpMsg->msglen);
            }
        }
        else // ( tcpMsg->dest || tcpMsg->src )
        {

            // forward tims message
            forwardConIndex = mailbox_get(tcpMsg->dest);

            if (forwardConIndex >= 0) // mbx is available
            {
                sndTcpTimsMsg(&conList[forwardConIndex], tcpMsg);
            }
            else // mbx is not available
            {
                if (tcpMsg->type > 0)
                {
                    tims_fillhead(&replyMsg, TIMS_MSG_NOT_AVAILABLE, tcpMsg->src,
                                  tcpMsg->dest, tcpMsg->priority, tcpMsg->seq_nr,
                                  0, TIMS_HEADLEN);
                    sndTcpTimsMsg(con, &replyMsg);
                }
            }
        }
    }

    tims_print("con[%02d]: %s: logout\n", idx, inet_ntoa(con->addr.sin_addr));
    mailbox_delete_all(con->index);

    if (con->socket != -1)
        connection_close(con);

    if (tcpMsg)
    {
        free(tcpMsg);
        tcpMsg = NULL;
        tims_dbgdetail("con[%02d]: %s: free tcp message buffer\n", con->index,
                       inet_ntoa(con->addr.sin_addr));
    }

    con->index = -1;
    return;
}