chan_h323.c

来自「一个非常美妙的proxy。功能强大。基于sip的协议。如果还要的话」· C语言 代码 · 共 2,305 行 · 第 1/5 页

C
2,305
字号
      case AST_CONTROL_CONGESTION:         if(!ast_test_flag(p, H323_ALREADYGONE)){            ast_mutex_lock(&ooh323c_cmd_lock);            ooHangCall(callToken, OO_REASON_LOCAL_CONGESTED);            ast_mutex_unlock(&ooh323c_cmd_lock);            ast_set_flag(p, H323_ALREADYGONE);         }         break;      case AST_CONTROL_BUSY:         if(!ast_test_flag(p, H323_ALREADYGONE)){            ast_mutex_lock(&ooh323c_cmd_lock);            ooHangCall(callToken, OO_REASON_LOCAL_BUSY);            ast_mutex_unlock(&ooh323c_cmd_lock);            ast_set_flag(p, H323_ALREADYGONE);         }         break;      case AST_CONTROL_PROCEEDING:      case AST_CONTROL_RINGING:      case AST_CONTROL_PROGRESS:         break;      default:         ast_log(LOG_WARNING,"Don't know how to indicate condition %d on %s\n",                              condition, callToken);   }   if(gH323Debug)      ast_verbose("++++  ooh323_indicate %d on %s\n", condition, callToken);   return -1;}static int ooh323_fixup   (struct ast_channel *oldchan, struct ast_channel *newchan){   if(gH323Debug)      ast_verbose("ooh323c ooh323_fixup\n");  return 0;}void ooh323_set_write_format(ooCallData *call, int fmt){#if 0   struct ooh323_pvt *p = NULL;   char formats[512];#ifdef print_debug   printf("---   ooh323_update_writeformat %s\n",                               ast_getformatname_multiple(formats,512, fmt));#endif      p = find_call(call);   if(!p)   {      ast_log(LOG_ERROR, "No matching call found for %s\n", call->callToken);      return;   }   ast_mutex_lock(&p->lock);   p->writeformat = fmt;   ast_mutex_unlock(&p->lock);   if(p->owner){     printf("Writeformat before update %s\n",               ast_getformatname_multiple(formats,512, p->owner->writeformat));     ast_set_write_format(p->owner, fmt);   }   else     ast_log(LOG_ERROR, "No owner found\n");#ifdef print_debug  printf("+++   ooh323_update_writeformat\n");#endif#endif}void ooh323_set_read_format(ooCallData *call, int fmt){#if 0   struct ooh323_pvt *p = NULL;   char formats[512];#ifdef print_debug   printf("---   ooh323_update_readformat %s\n",                                  ast_getformatname_multiple(formats,512, fmt));#endif   p = find_call(call);   if(!p)   {      ast_log(LOG_ERROR, "No matching call found for %s\n", call->callToken);      return;   }   ast_mutex_lock(&p->lock);   p->readformat = fmt;   ast_mutex_unlock(&p->lock);   ast_set_read_format(p->owner, fmt);      #ifdef print_debug  printf("+++   ooh323_update_readformat\n");#endif#endif}int onAlerting(ooCallData *call){   struct ooh323_pvt *p=NULL;   struct ast_channel *c = NULL;   if(gH323Debug)      ast_verbose("--- onAlerting %s\n", call->callToken);   p = find_call(call);   if(!p)   {      ast_log(LOG_ERROR, "No matching call found\n");      return -1;   }     ast_mutex_lock(&p->lock);   if(!ast_test_flag(p, H323_OUTGOING))   {      c = ooh323_new(p, AST_STATE_RING, p->username);      if(!c)      {         ast_mutex_unlock(&p->lock);         ast_log(LOG_ERROR, "Could not create ast_channel\n");         return -1;      }       }else{      if (!p->owner) {         ast_mutex_unlock(&p->lock);         ast_log(LOG_ERROR, "Channel has no owner\n");         return 0;      }      c = p->owner;      ast_setstate(c, AST_STATE_RINGING);      ast_queue_control(c, AST_CONTROL_RINGING);   }      ast_mutex_unlock(&p->lock);   if(gH323Debug)      ast_verbose("+++ onAlerting %s\n", call->callToken);   return OO_OK;}/**  * Callback for sending digits from H.323 up to asterisk  *  */int ooh323_onReceivedDigit(OOH323CallData *call, const char* digit){   struct ooh323_pvt *p=NULL;   struct ast_frame f;   int res;   ast_log(LOG_DEBUG, "Received Digit: %c\n", digit);   p = find_call(call);   if(!p)   {      ast_log(LOG_ERROR, "Failed to find a matching call.\n");      return -1;   }   ast_mutex_lock(&p->lock);   memset(&f, 0, sizeof(f));   f.frametype = AST_FRAME_DTMF;   f.subclass = digit[0];   f.datalen = 0;   f.samples = 800;   f.offset = 0;   f.data = NULL;   f.mallocd = 0;   f.src = "SEND_DIGIT";	   res = ast_queue_frame(p->owner, &f);   ast_mutex_unlock(&p->lock);   return res;}int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg){   struct ooh323_pvt *p=NULL;   struct ooh323_user *user=NULL;   ooAliases *alias=NULL;   char *at=NULL;   char number [OO_MAX_NUMBER_LENGTH];   if(gH323Debug)      ast_verbose("---   ooh323_onReceivedSetup %s\n", call->callToken);   p = ooh323_alloc(call->callReference, call->callToken);   if(!p)   {      ast_log(LOG_ERROR, "Failed to create a new call.\n");      return -1;   }   ast_mutex_lock(&p->lock);   ast_clear_flag(p, H323_OUTGOING);     if(call->remoteDisplayName){      p->callerid_name = strdup(call->remoteDisplayName);   }   if(ooCallGetCallingPartyNumber(call, number, OO_MAX_NUMBER_LENGTH) == OO_OK)   {      p->callerid_num = strdup(number);   }   if(call->remoteAliases)   {      alias = call->remoteAliases;               while(alias)      {         if(alias->type == T_H225AliasAddress_h323_ID)         {	   if(!p->callerid_name){               p->callerid_name = strdup(alias->value);           }           strncpy(p->caller_h323id, alias->value, sizeof(p->caller_h323id)-1);         }else if(alias->type == T_H225AliasAddress_dialedDigits)         {            if(!p->callerid_num)               p->callerid_num = strdup(alias->value);            strncpy(p->caller_dialedDigits, alias->value,                                              sizeof(p->caller_dialedDigits)-1);         }else if(alias->type == T_H225AliasAddress_email_ID)         {            strncpy(p->caller_email, alias->value, sizeof(p->caller_email)-1);         }else if(alias->type == T_H225AliasAddress_url_ID)         {            strncpy(p->caller_url, alias->value, sizeof(p->caller_url)-1);         }         alias = alias->next;      }   }   number[0]='\0';   if(ooCallGetCalledPartyNumber(call, number, OO_MAX_NUMBER_LENGTH)== OO_OK)   {      strncpy(p->exten, number, sizeof(p->exten)-1);   }else{         update_our_aliases(call, p);      if(!ast_strlen_zero(p->callee_dialedDigits)){         strncpy(p->exten, p->callee_dialedDigits, sizeof(p->exten)-1);      }else if(!ast_strlen_zero(p->callee_h323id)){         strncpy(p->exten, p->callee_h323id, sizeof(p->exten)-1);      }else if(!ast_strlen_zero(p->callee_email)){         strncpy(p->exten, p->callee_email, sizeof(p->exten)-1);         if((at=strchr(p->exten, '@')))            *at='\0';      }   }   /* if no extension found, set to default 's' */   if(ast_strlen_zero(p->exten))   {           p->exten[0]='s';      p->exten[1]='\0';   }   if(!p->callerid_name)   {      p->callerid_name = strdup(call->remoteIP);   }      if(p->callerid_name)   {      p->username = strdup(p->callerid_name);      user = find_user(p->username);      if(user)      {         ast_mutex_lock(&user->lock);         strncpy(p->context, user->context, sizeof(p->context)-1);         strncpy(p->accountcode, user->accountcode, sizeof(p->accountcode)-1);         p->amaflags = user->amaflags;         p->capability = user->capability;         memcpy(&p->prefs, &user->prefs, sizeof(struct ast_codec_pref));         p->dtmfmode = user->dtmfmode;         /* Since, call is coming from a pbx user, no need to use gk */         OO_SETFLAG(p->flags, H323_DISABLEGK);         OO_SETFLAG(call->flags, OO_M_DISABLEGK);         ast_mutex_unlock(&user->lock);      }   }   ooh323c_set_capability_for_call(call, &p->prefs, p->capability,p->dtmfmode);   configure_local_rtp(p, call);   ast_mutex_unlock(&p->lock);   if(gH323Debug)      ast_verbose("+++   ooh323_onReceivedSetup - Determined context %s, "                  "extension %s\n", p->context, p->exten);   return OO_OK;}int onNewCallCreated(ooCallData *call){   struct ooh323_pvt *p = NULL;   int i=0;   if(gH323Debug)      ast_verbose("---   onNewCallCreated %s\n", call->callToken);   if(!strcmp(call->callType, "outgoing"))   {      p = find_call(call);      if(!p)      {         ast_log(LOG_ERROR, "No matching call found for outgoing call\n");         return -1;      }      ast_mutex_lock(&p->lock);      if(p->callerid_name){         ooCallSetCallerId(call, p->callerid_name);      }      if(p->callerid_num)      {         i=0;         while(*(p->callerid_num+i) != '\0')         {            if(!isdigit(*(p->callerid_num+i)))               break;            i++;         }         if(*(p->callerid_num+i) == '\0')            ooCallSetCallingPartyNumber(call, p->callerid_num);         else{            if(!p->callerid_name)               ooCallSetCallerId(call, p->callerid_num);         }      }            if(!ast_strlen_zero(p->caller_h323id))         ooCallAddAliasH323ID(call, p->caller_h323id);      if(!ast_strlen_zero(p->caller_dialedDigits)){         if(gH323Debug) {            ast_log(LOG_DEBUG, "Setting dialed digits %s\n",                p->caller_dialedDigits);         }         ooCallAddAliasDialedDigits(call, p->caller_dialedDigits);      }else if(p->callerid_num) {         if(ooIsDigitString(p->callerid_num)) {            if(gH323Debug) {               ast_verbose("setting callid number %s\n", p->callerid_num);            }            ooCallAddAliasDialedDigits(call, p->callerid_num);         }         else if(ast_strlen_zero(p->caller_h323id)) {            ooCallAddAliasH323ID(call, p->callerid_num);         }      }       if(!ast_strlen_zero(p->exten))       {         for(i=0; *(p->exten+i) != '\0'; i++)         {            if(!isdigit(*(p->exten+i)))               break;         }         if(*(p->exten+i) == '\0'){            ooCallSetCalledPartyNumber(call, p->exten);            ooCallAddRemoteAliasDialedDigits(call, p->exten);         }         else           ooCallAddRemoteAliasH323ID(call, p->exten);     }     if(gH323Debug)     {       char prefsBuf[256];       ast_codec_pref_string(&p->prefs, prefsBuf, 256);       ast_verbose(" Outgoing call %s(%s) - Codec prefs - %s\n",                     p->username?p->username:"NULL", call->callToken, prefsBuf);     }     ooh323c_set_capability_for_call(call, &p->prefs, p->capability,                                      p->dtmfmode);         configure_local_rtp(p, call);      ast_mutex_unlock(&p->lock);   }   if(gH323Debug)      ast_verbose("+++   onNewCallCreated %s\n", call->callToken);   return OO_OK;}int onCallEstablished(ooCallData *call){  struct ooh323_pvt *p = NULL;   if(gH323Debug)      ast_verbose("---   onCallEstablished %s\n", call->callToken);   p = find_call(call);   if(!p)   {      ast_log(LOG_ERROR, "Failed to find a matching call.\n");      return -1;   }   ast_mutex_lock(&p->lock);   if (!p->owner) {      ast_mutex_unlock(&p->lock);      ast_log(LOG_ERROR, "Channel has no owner\n");      return -1;   }      if(p->owner->_state != AST_STATE_UP)   {      ast_mutex_lock(&p->owner->lock);      ast_setstate(p->owner, AST_STATE_UP);      ast_mutex_unlock(&p->owner->lock);   }   if(ast_test_flag(p, H323_OUTGOING))      ast_queue_control(p->owner, AST_CONTROL_ANSWER);   ast_mutex_unlock(&p->lock);   if(gH323Debug)      ast_verbose("+++   onCallEstablished %s\n", call->callToken);  return OO_OK;}int onCallCleared(ooCallData *call){   struct ooh323_pvt *p = NULL;   struct ast_channel *c=NULL;   if(gH323Debug)      ast_verbose("---   onCallCleared %s \n", call->callToken);   p = find_call(call);    if (!p) {      return 0;   }   ast_mutex_lock(&p->lock);  retrylock:   if(p->owner && ast_mutex_trylock(&p->owner->lock))   {      ast_log(LOG_DEBUG,"Failed to grab lock, trying again\n");      ast_mutex_unlock(&p->lock);      usleep(1);      ast_mutex_lock(&p->lock);      goto retrylock;   }    

⌨️ 快捷键说明

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