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

📄 mg_user.c

📁 一个Megaco实现源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
  ASSERT_OK(status);  delete_pending(*ref); // Ignore returned data  state = MgsStopUser;  prepare_session(&dummy, &session_pid);  V( ("send stopUser\n") );  Megaco_Session_stopUser(NULL, *ref, &session_user_pid, 			  &mid, send_env);  free ((void*)status);  return (Megaco_SessionUser_disconnectResponse__rs*)NULL;}Megaco_SessionUser_cancelResponse__rs* Megaco_SessionUser_cancelResponse__cb(Megaco_SessionUser oe_obj, 				      CORBA_long *ref, 				      Megaco_Status *status, 				      CORBA_Environment *oe_env) {      W( ("(session) received cancelResponse (NOT IMPLEMENTED)\n") );  delete_pending(*ref); // Ignore returned data  free ((void*)status);  return (Megaco_SessionUser_cancelResponse__rs*)NULL;}  /************************************************************ * TCP User Callback Functions ************************************************************//* This function is fro an MGC */MegacoSessionTcpUser_listenResponse__rs*MegacoSessionTcpUser_listenResponse__cb(MegacoSessionTcpUser oe_obj,					CORBA_long *ref,					Megaco_Status *status, 					CORBA_Environment *oe_env) {  V( ("(TCP) received listenResponse\n") );  ASSERT_OK(status);  delete_pending(*ref); // Ignore returned data  free ((void*)status);  return (MegacoSessionTcpUser_listenResponse__rs*)NULL;}MegacoSessionTcpUser_connectResponse__rs* MegacoSessionTcpUser_connectResponse__cb(MegacoSessionTcpUser oe_obj, 					 CORBA_long *ref, 					 Megaco_Status *status, 					 erlang_binary *bin, 					 erlang_pid *pid, 					 CORBA_Environment *oe_env){  Megaco_UserMid preliminary_mid;  V( ("(TCP) received connectResponse\n") );  P( print_pid("controlPid: ", pid) );  ASSERT_OK(status);  state = MgsTransportInit;  /* Store received info */  bincpy(&send_handle, bin);  pidcpy(&control_pid, pid);  delete_pending(*ref); // Ignore returned data  /* Prepare sending */  prepare_session(&dummy, &session_pid);  preliminary_mid._d = MegacoMessage_MIdChoice_preliminary;  V( ("send megaco connect\n") );  Megaco_Session_connect(NULL, ref_counter, 			 &session_user_pid, &recv_handle, &preliminary_mid,			 &send_handle, &control_pid, send_env);  ASSERT_SEND();  free ((void*)status);  free ((void*)bin);  return (MegacoSessionTcpUser_connectResponse__rs*)NULL;}MegacoSessionTcpUser_closeResponse__rs* MegacoSessionTcpUser_closeResponse__cb(MegacoSessionTcpUser oe_obj,				       CORBA_long *ref, 				       Megaco_Status *status, 				       CORBA_Environment *oe_env){  W( ("(TCP) received closeResponse\n") );  ASSERT_OK(status);  delete_pending(*ref); // Ignore returned data/*   state = MgsDisconnecting; *//*   prepare_session(&dummy, &session_pid); *//*   V( ("send megaco disconnect\n") ); *//*   Megaco_Session_disconnect(NULL, ref_counter,  *//* 			    &session_user_pid, &conn_handle,  *//* 			    "time to disco...", send_env); *//*   ASSERT_SEND(); */  free ((void*)status);  return (MegacoSessionTcpUser_closeResponse__rs*)NULL;}MegacoSessionTcpUser_blockResponse__rs* MegacoSessionTcpUser_blockResponse__cb(MegacoSessionTcpUser oe_obj, 				       CORBA_long *ref, 				       Megaco_Status *status, 				       CORBA_Environment *oe_env){  W( ("(TCP) received blockResponse (NOT IMPLEMENTED)\n") );  ASSERT_OK(status);  delete_pending(*ref); // Ignore returned data   free ((void*)status);  return (MegacoSessionTcpUser_blockResponse__rs*)NULL;}MegacoSessionTcpUser_unblockResponse__rs* MegacoSessionTcpUser_unblockResponse__cb(MegacoSessionTcpUser oe_obj, 					 CORBA_long *ref, 					 Megaco_Status *status, 					 CORBA_Environment *oe_env){  W( ("(TCP) received unblockResponse (NOT IMPLEMENTED)\n") );  ASSERT_OK(status);  delete_pending(*ref); // Ignore returned data   free ((void*)status);  return (MegacoSessionTcpUser_unblockResponse__rs*)NULL;}/************************************************************ * UDP User Callback Functions ************************************************************/MegacoSessionUdpUser_openResponse__rs* MegacoSessionUdpUser_openResponse__cb(MegacoSessionUdpUser oe_obj, 				      CORBA_long *ref, 				      Megaco_Status *status, 				      erlang_binary *bin, 				      erlang_pid *pid, 				      CORBA_Environment *oe_env){  Megaco_UserMid preliminary_mid;  V( ("(UDP) received openResponse\n") );  P( print_pid("controlPid: ", pid) );  ASSERT_OK(status);  state = MgsTransportInit;  /* Store received info */  bincpy(&send_handle, bin);  pidcpy(&control_pid, pid);  delete_pending(*ref); // Ignore returned data  /* Prepare sending */  prepare_session(&dummy, &session_pid);  preliminary_mid._d = MegacoMessage_MIdChoice_preliminary;  V( ("send megaco connect\n") );  Megaco_Session_connect(NULL, ref_counter, 			 &session_user_pid, &recv_handle, &preliminary_mid,			 &send_handle, &control_pid, send_env);  ASSERT_SEND();  free ((void*)status);  free ((void*)bin);  return (MegacoSessionUdpUser_openResponse__rs*)NULL;}MegacoSessionUdpUser_closeResponse__rs* MegacoSessionUdpUser_closeResponse__cb(MegacoSessionUdpUser oe_obj, 				       CORBA_long *ref, 				       Megaco_Status *status, 				       CORBA_Environment *oe_env){  V( ("(UDP) received closeResponse\n") );  ASSERT_OK(status);  delete_pending(*ref); // Ignore returned data  state = MgsDisconnecting;  prepare_session(&dummy, &session_pid);  V( ("send megaco disconnect\n") );  Megaco_Session_disconnect(NULL, ref_counter, 			    &session_user_pid, &conn_handle, 			    "time to disco...", send_env);  ASSERT_SEND();  free ((void*)status);  return (MegacoSessionUdpUser_closeResponse__rs*)NULL;}MegacoSessionUdpUser_blockResponse__rs* MegacoSessionUdpUser_blockResponse__cb(MegacoSessionUdpUser oe_obj, 				       CORBA_long *ref, 				       Megaco_Status *status, 				       CORBA_Environment *oe_env){  W( ("(UDP) received blockResponse (NOT IMPLEMENTED)\n") );  ASSERT_OK(status);  delete_pending(*ref); // Ignore returned data   free ((void*)status);  return (MegacoSessionUdpUser_blockResponse__rs*)NULL;}MegacoSessionUdpUser_unblockResponse__rs* MegacoSessionUdpUser_unblockResponse__cb(MegacoSessionUdpUser oe_obj, 					 CORBA_long *ref, 					 Megaco_Status *status, 					 CORBA_Environment *oe_env){  W( ("(UDP) received unblockResponse (NOT IMPLEMENTED)\n") );  ASSERT_OK(status);  delete_pending(*ref); // Ignore returned data   free ((void*)status);  return (MegacoSessionUdpUser_unblockResponse__rs*)NULL;}/* * Transaction reply functions * The assumption here is that the only reply we will get * is that of the service change! */static int handle_transaction_replies(Megaco_ActionReplies* actRepliesP) {  int i, res = TRUE;  if (actRepliesP->_length <= 0)    return ( FALSE );  for (i = 0 ; (i < actRepliesP->_length) && res ; i++) {    res = handle_transaction_reply(&actRepliesP->_buffer[i]);  }  return ( res );}static int handle_transaction_reply(MegacoMessage_ActionReply* actReplyP) {  MegacoMessage_ActionReply_commandReply* cmdRepP;  MegacoMessage_OptErrorDescriptor*       errDescP;  int res = TRUE;  /* We shuld verify the context id... */  V( ("context id: %d\n", (int) actReplyP->id) );  /* Check that we did not get any errors */  errDescP = &actReplyP->errorDescriptor;  if (errDescP->_d) {    print_error_desc("Service change reply: ", &errDescP->_u.val);    return ( FALSE );  }      /* Ignore optional context request... */  /* Handle the command reply */  cmdRepP  = &actReplyP->commandReply;  {    int i;    for(i = 0 ; (i < cmdRepP->_length) && res ; i++) {      res = handle_command_reply(actReplyP->id, &cmdRepP->_buffer[i]);    }  }  return ( res );}static int handle_command_reply(int                              cid,				MegacoMessage_CommandReplyUnion* repP) {  int res = TRUE;   V( ("handle command reply %d when MG in state %d\n",      repP->_d, state) );  /* This simple example handles noting other than the service change */  switch (repP->_d) {  case MegacoMessage_CommandReplyChoice_serviceChangeReply:    if (state == MgsConnected) {      res = handle_service_change_rep(cid, &repP->_u.serviceChange);    } else {      V( ("MG not yet connected to the MGC...\n") );    }    break;  default:    V( ("command %d not implemented\n", repP->_d) );    break;  }  return ( res );}          static int handle_service_change_rep(int                               cid,				     MegacoMessage_ServiceChangeReply* repP) {  V( ("handle service change reply\n") );  /* We only support service change on the root termination! */  if (repP->termIdList._length == 1) {    MegacoMessage_TerminationIdUnion* tidP = repP->termIdList._buffer;    if (tidP->_d == MegacoMessage_Encoding_text) {  /* text   */      char* ttid = *tidP->_u.text.id._buffer;      V( ("service change on (text) tid: %s\n", ttid) );      if (strcmp(ttid,"root") == 0) {	return ( TRUE );      } else {	V( ("service change only supported for the root termination (%s)\n", 	    ttid) );	return ( FALSE );      }    } else {                                        /* binary */      MegacoMessage_BinaryTerminationId* btidP = &tidP->_u.binary;      // We don't handle wildcards. Rember this is a simple example...      if (btidP->wildcard._length == 0) {	int i;	if (btidP->id._length != sizeof(bin_root)) {	  W( ("unexpected binary termination (length): %d, %d\n", 	      (int) btidP->id._length, sizeof(bin_root)) );	  return ( FALSE );	} else {	  if (memcmp((void*)btidP->id._buffer,		     (void*)bin_root, 		     sizeof(bin_root)) == 0) {	    V( ("service change on the (binary) root termination\n") );	    return ( TRUE );	  } else {	    W( ("service change on a non-root termination:\n") );	    for (i = 0 ; i < btidP->id._length ; i++) {	      W( ("bin term-id[%d]: 0x%X, 0x%X\n", 		  i, btidP->id._buffer[i], bin_root[i]) );	    }	    return ( FALSE );	  }	}      } else {	V( ("service change only supported for the root (e.g. no wildcards allowed)\n") );	return ( FALSE );      }    }  } else {    V( ("termination id list longer than 1: %d\n", (int) repP->termIdList._length) );    return ( FALSE );  }  return ( FALSE );}/*  * Various utility functions  */static void bincpy(erlang_binary* to, erlang_binary* from) {  to->_maximum = from->_maximum;  to->_length  = from->_length;  to->_buffer  = malloc(from->_length);  if (to->_buffer == NULL)    mg_exit(send_env, receive_env);  memcpy(to->_buffer, from->_buffer, from->_length);}static void pidcpy(erlang_pid* to, erlang_pid* from) {  to->num      = from->num;  to->serial   = from->serial;  to->creation = from->creation;  strcpy(to->node, from->node);}static void mchcpy(Megaco_ConnHandle* to, Megaco_ConnHandle* from){  midcpy(&to->localMid,  &from->localMid);  midcpy(&to->remoteMid, &from->remoteMid);}static void midcpy(MegacoMessage_MIdUnion* to, MegacoMessage_MIdUnion* from){  to->_d = from->_d;  switch (from->_d) {  case MegacoMessage_MIdChoice_ip4Address:    ip4cpy(&to->_u.ip4, &from->_u.ip4);    break;  case MegacoMessage_MIdChoice_ip6Address:    ip6cpy(&to->_u.ip6, &from->_u.ip6);    break;  case MegacoMessage_MIdChoice_domainName:    domcpy(&to->_u.domain, &from->_u.domain);    break;  case MegacoMessage_MIdChoice_deviceName:    devcpy(&to->_u.device, from->_u.device);    break;  case MegacoMessage_MIdChoice_mtpAddress:    mtpcpy(&to->_u.mtp, &from->_u.mtp);    break;  case MegacoMessage_MIdChoice_preliminary:    // Nothing to copy in this case    break;  }}static void ip4cpy(MegacoMessage_IP4Address* to, 		   MegacoMessage_IP4Address* from) {  /* the address */  to->address._maximum = from->address._maximum;  to->address._length  = from->address._length;  to->address._buffer  = malloc(from->address._length);  if (to->address._buffer == NULL)    mg_exit(send_env, receive_env);  memcpy(to->address._buffer, from->address._buffer, from->address._length);    /* the port */  to->portNumber = from->portNumber;}static void ip6cpy(MegacoMessage_IP6Address* to, 		   MegacoMessage_IP6Address* from) {  /* the address */  to->address._maximum = from->address._maximum;  to->address._length  = from->address._length;  to->address._buffer  = malloc(from->address._length);  if (to->address._buffer == NULL)    mg_exit(send_env, receive_env);  memcpy(to->address._buffer, from->address._buffer, from->address._length);    /* the port */  to->portNumber = from->portNumber;}static void domcpy(MegacoMessage_DomainName* to,		   MegacoMessage_DomainName* from){  /* the name */  to->name = malloc(strlen(from->name)+1);  if (to->name == NULL)    mg_exit(send_env, receive_env);  strcpy(to->name, from->name);  /* the port */  to->portNumber = from->portNumber;  }static void devcpy(CORBA_char** to,		   CORBA_char* from){  *to = malloc(strlen(from) + 1);  if (*to == NULL)    mg_exit(send_env, receive_env);  strcpy(*to, from);}static void mtpcpy(MegacoMessage_OctetString* to,		   MegacoMessage_OctetString* from){  to->_maximum = from->_maximum;  to->_length  = from->_length;  to->_buffer  = malloc(from->_length);  if (to->_buffer == NULL)    mg_exit(send_env, receive_env);  memcpy(to->_buffer, from->_buffer, from->_length);  }

⌨️ 快捷键说明

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