⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipp.cpp

📁 sip终端
💻 CPP
📖 第 1 页 / 共 5 页
字号:
      nb_net_cong++;      return -1;    }#endif    if(errno == EWOULDBLOCK) {      nb_net_cong++;      return -1;    }        if(errno == EPIPE) {      nb_net_send_errors++;      ERROR("Broken pipe on TCP connection, remote peer "            "probably closed the socket");    }    if(rc <= 0) {      nb_net_send_errors++;      ERROR_NO("Unable to send TCP message");      return -2;    }  } else { /* UDP */    unsigned int len = strlen(msg);        if(compression) {      static char comp_msg[SIPP_MAX_MSG_SIZE];      strcpy(comp_msg, msg);      if(comp_compress(comp_state,                       comp_msg,                        &len) != COMP_OK) {        ERROR("Compression pluggin error");      }      msg = (char *)comp_msg;      TRACE_MSG((s, "---\nCompressed message len: %d\n",                 len));    }    // different remote sending address from received    if (use_remote_sending_addr) {      L_dest = &remote_sending_sockaddr ;    }    if(sendto(s,               msg,               len,               0,              (struct sockaddr *)(void *)L_dest,              SOCK_ADDR_SIZE(L_dest)) == -1) {      nb_net_send_errors++;      ERROR_NO("Unable to send UDP message");      return -2;    }  }  return 0;}/****************************** Network Interface *******************/int recv_message(char * buffer, int buffer_size, int * poll_idx){  int size = 0;#ifdef _USE_OPENSSL   BIO *bio;  SSL *ssl;#endif  int err;    for((*poll_idx) = 0;      (*poll_idx) < pollnfds;      (*poll_idx)++) {    if(pollfiles[(*poll_idx)].revents) {            call * recv_call = pollcalls[(*poll_idx)];      int s = pollfiles[(*poll_idx)].fd;      int ss = s;      pollfiles[(*poll_idx)].revents = 0;#ifdef __3PCC__      if(s == localTwinSippSocket)        {          sipp_socklen_t len = sizeof(twinSipp_sockaddr);          twinSippSocket = accept(s,                                  (sockaddr *)(void *)&twinSipp_sockaddr,                                  &len);                    pollset_add(0, twinSippSocket);          return(-2);        }       else if (s == twinSippSocket)        {          size = recv_tcp_message(s,                                  buffer,                                  buffer_size,                                  E_ALTER_NO,                                  E_ALTER_YES);          if(size >= 0) {            buffer[size] = 0;          }          else            buffer[0] = 0;          return size;        }        else        {#endif      #ifdef _USE_OPENSSL      if(transport == T_TCP ||  transport == T_TLS ) {#else      if(transport == T_TCP ) {#endif                if(s == main_socket) {          /* New incoming connection */          sipp_socklen_t len = SOCK_ADDR_SIZE(&remote_sockaddr);          int new_sock = accept(s,                                (sockaddr *)(void *)&remote_sockaddr,                                &len);          #ifdef _USE_OPENSSL          if (transport == T_TLS) {            if ( (bio = BIO_new_socket(new_sock,BIO_NOCLOSE)) == NULL) {              ERROR("Unable to create the BIO- New TLS connection - recv_message\n");            }            /* Create a SSL object */            if (!(ssl = SSL_new(sip_trp_ssl_ctx))){              ERROR("Unable to create new SSL context recv_message: Fail SSL_new\n");            }            SSL_set_bio(ssl,bio,bio);            if ( (err = SSL_accept(ssl)) < 0 ) {              ERROR("SSL_accept Fails - recv_message()\n");            }            ssl_list[new_sock] = ssl;          }#endif          pollset_add(0, new_sock);          return -2;        }#ifdef _USE_OPENSSL        if ( transport == T_TLS ) {          int ss = s;          ssl = ssl_list[s];          size = recv_tls_message(ssl,                                  buffer,                                  buffer_size,                                  E_ALTER_YES);        } else {#endif        size = recv_tcp_message(s,                                buffer,                                buffer_size,                                E_ALTER_YES);#ifdef _USE_OPENSSL        }#endif                if(size <= 0) { /* Remote side closed TCP connection */                    nb_net_recv_errors++;                    /* Preventive cleaning */          if(size < 0) {            WARNING_P2("TCP/TLS recv error on socket %d, index = %d",                       s, *poll_idx);            ERROR_NO("TCP/TLS recv_error");          }          if(recv_call) {            recv_call -> call_socket = 0;            if(recv_call -> pollset_index) {              recv_call -> pollset_index = 0;            }          }                    pollset_remove((*poll_idx));          shutdown(s, SHUT_RDWR);          close(s);          return 0;        }              } else { /* T_UDP */                if(toolMode == MODE_SERVER) {          sipp_socklen_t len = SOCK_ADDR_SIZE(&remote_sockaddr);                    size  = recvfrom(s,                           buffer,                           buffer_size,                           0,                           (sockaddr *)(void *)&remote_sockaddr,                           &len);                  } else {          size  = recvfrom(s,                            buffer,                            buffer_size,                            0, NULL, NULL);        }                if(size < 0) {          WARNING_P3("Unexpected UDP recv error, idx = %d, "                     "socket = %d, recv_call = 0x%08x",                     (*poll_idx), s, recv_call);          ERROR_NO("Unexpected UDP recv error");#if 0          nb_net_recv_errors++;          pollset_remove((*poll_idx));          shutdown(s, SHUT_RDWR);          close(s);#endif          return 0;        }        if (size > 0) {          size = decompress_if_needed(s,                                      buffer,                                      size,                                      ((recv_call) ?                                        (&(recv_call -> comp_state)) :                                        &monosocket_comp_state));        }      } /* else ... T_UDP */            break;#ifdef __3PCC__      }#endif    } /* if(pollfiles[(*poll_idx)].revents) */  } /* for((*poll_idx)) */    buffer[size] = 0;  struct timeval currentTime;  GET_TIME (&currentTime);  TRACE_MSG((s, "----------------------------------------------- %s\n"             "%s message received [%d] bytes :\n\n%s\n",             CStat::instance()->formatTime(&currentTime),             TRANSPORT_TO_STRING(transport), size,             buffer));  return size;}void pollset_process(bool ipv6){  int rs; /* Number of times to execute recv().	     For TCP with 1 socket per call:	         no. of events returned by poll	     For UDP and TCP with 1 global socket:	         recv_count is a flag that stays up as	         long as there's data to read */  int loops = MAX_RECV_LOOPS;    while((loops-- > 0) && /* Ensure some minimal statistics display sometime */        (rs = poll(pollfiles, pollnfds,  1)) > 0) {    if((rs < 0) && (errno == EINTR)) {      return;    }        if(rs < 0) {      ERROR_NO("poll() error");    }        while(rs > 0) {      char            msg[SIPP_MAX_MSG_SIZE];      int             msg_size;      char          * call_id;      call          * call_ptr;      int             pollset_index = 0;            memset(msg,0,sizeof(msg));      msg_size = recv_message(msg,                               SIPP_MAX_MSG_SIZE,                               &pollset_index);            if(msg_size > 0) {		if (sipMsgCheck(msg, 			msg_size#ifdef __3PCC__			,pollset_index#endif // __3PCC__			) == true) {	            call_id = get_call_id(msg);          call_ptr = get_call(call_id);                  if(!call_ptr)            {              if(toolMode == MODE_SERVER)                {                  // Adding a new INCOMING call !                  CStat::instance()->computeStat                    (CStat::E_CREATE_INCOMING_CALL);                  call_ptr = add_call(call_id, ipv6);                              if((pollset_index) &&                      (pollfiles[pollset_index].fd != main_socket) &&                      (pollfiles[pollset_index].fd != tcp_multiplex) ) {				                      call_ptr -> call_socket = pollfiles[pollset_index].fd;                  }                }#ifdef __3PCC__              else if(toolMode == MODE_3PCC_CONTROLLER_B || toolMode == MODE_3PCC_A_PASSIVE)                {                  // Adding a new OUTGOING call !                  CStat::instance()->computeStat                    (CStat::E_CREATE_OUTGOING_CALL);                  call_ptr = add_call(call_id, ipv6);                              if((pollset_index) &&                      (pollfiles[pollset_index].fd != main_socket) &&                      (pollfiles[pollset_index].fd != tcp_multiplex) &&                     (pollfiles[pollset_index].fd != localTwinSippSocket) &&                     (pollfiles[pollset_index].fd != twinSippSocket)) {                    call_ptr -> call_socket = pollfiles[pollset_index].fd;                  }                }#endif              else // mode != from SERVER and 3PCC Controller B                {                  nb_out_of_the_blue++;                  CStat::instance()->computeStat                    (CStat::E_OUT_OF_CALL_MSGS);                  // This is a message that is not relating to any call                }            }		          if(call_ptr)            {#ifdef __3PCC__              if( (pollfiles[pollset_index].fd == localTwinSippSocket) ||                  (pollfiles[pollset_index].fd == twinSippSocket))                {                  if(!call_ptr -> process_twinSippCom(msg))                    {                      return;                    }                 }              else#endif                {                  if(!call_ptr -> process_incomming(msg))                    {                      /* Needs to rebuild the pollset (socket removed,                        * call deleted, etc... Cause pollcalls is now                        * invalid and will alway lead poll() to return                        * an error.*/                      return;                    }                }            }	} else { // sipMsgCheck == false	  // unrecognized message => discard it	  WARNING("non SIP message discarded");	}	if (pollnfds > 0) /* refer to note at the beginning of this function */               rs--;                 } // end if msg >=0      else       rs--;    }  }  cpu_max = loops <= 0;}/* Send loop & trafic generation*/void traffic_thread(bool ipv6){  unsigned int calls_to_open = 0;  unsigned int new_time;  unsigned int last_time;  int          timer_resolution = DEFAULT_TIMER_RESOLUTION;  bool         firstPass;  /* create the file */  char         L_file_name [200];  sprintf (L_file_name, "%s_%d_screen.log", scenario_file, getpid());  firstPass = true;  last_time = getmilliseconds();   /* Prepare pollset with basic sockets */  pollset_reset();  while(1) {    scheduling_loops ++;    /* update local time, except if resetted*/    new_time = getmilliseconds();    clock_tick += (new_time - last_time);    last_time = new_time;    if (signalDump) {       /* Screen dumping in a file */       if (screenf) {          print_screens();       } else {         /* If the -trace_screen option has not been set, */         /* create the file at this occasion              */         screenf = fopen(L_file_name, "a");	 if (!screenf) {            WARNING_P1("Unable to create '%s'", L_file_name);          }	 print_screens();	 fclose(screenf);	 screenf = 0;       }       signalDump = false ;    }    if ((!quitting) && (!paused)) {      calls_to_open =         (unsigned int) (((clock_tick - last_rate_change_time) * rate/rate_period_s) / 1000)        - calls_since_last_rate_change;      if( (toolMode == MODE_CLIENT)#ifdef __3PCC__          || (toolMode == MODE_3PCC_CONTROLLER_A)#endif          )        {          while((calls_to_open--) &&                 (open_calls < open_calls_allowed) &&                (total_calls < stop_after))             {              // adding a new OUTGOING CALL              CStat::instance()->computeStat(CStat::E_CREATE_OUTGOING_CALL);              call * call_ptr = add_call(ipv6);              call_ptr -> run();            }        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -