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

📄 callapiproxy.c

📁 未改进的经典的SIP NETWORK API。 请尽快给下载权限
💻 C
📖 第 1 页 / 共 3 页
字号:
 * ABSTRACT:
 *
 *      The SIP call cancel reception callback
 *
 * FORMAL PARAMETERS:
 *
 *      instance      : The SIP call handling instance
 *      call          : The call identifier
 *      dialog        : The dialog identifier
 *      transaction   : The transaction identifier
 *      request_uri   : The request URI in the message
 *      request       : Additional headers in the INVITE
 *      body          : The received body
 *      user_info     : The user info
 *
 * RETURN VALUE:
 *
 *      SIP_NORMAL : successful completion
 *
 */

sip_status_t sip_call_on_cancel
  (
    sip_call_inst_t               instance,
    sip_call_t                    call,
    sip_dialog_t                  dialog,
    sip_trans_t                   trans,
    sip_msg_uri_t               * request_uri,
    sip_msg_header_vector_t     * request,
    sip_msg_body_t              * body,
    sip_user_info_t             * user_info
   )
{
  printf("The current call has been canceled\n");

  return SIP_NORMAL;
}

/*
 * FACILITY:
 *
 *      sip_call_on_get_media
 *
 * ABSTRACT:
 *
 *      The SIP get_media reception callback
 *
 * FORMAL PARAMETERS:
 *
 *      instance      : The SIP call instance
 *      call          : The call identifier
 *      dialog        : The dialog identifier
 *      transaction   : The transaction identifier
 *      status_code   : The status code (1xx) received in the response 
 *      reason_phrase : The character string in the received status line
 *      response      : Additional headers in the response
 *      body          : The received body
 *      user_info     : The user info
 *
 * RETURN VALUE:
 *
 *      SIP_NORMAL : successful completion
 *
 */

sip_status_t sip_call_on_get_media
  (
    sip_call_inst_t               instance,
    sip_call_t                    call,
    sip_dialog_t                  dialog,
    sip_trans_t                   transaction,
    sip_uint32_t                  status_code,
    char                        * reason_phrase,
    sip_msg_header_vector_t     * response,
    sip_msg_body_t              * body,
    sip_user_info_t             * user_info
  )
{
  sip_trans_t new_trans;

  printf("Get media received\n");

  sip_status_t    sip_status;
  /* We should forward the response */
  sip_status = sip_trans_forward_response(instance,
                                          transaction,
                                          status_code,
                                          reason_phrase,
                                          response,
                                          body,
                                          NULL);
  if (sip_status != SIP_NORMAL)
    {
      printf("Error %d in forwarding a response 200\n", sip_status);
    } 
  else 
    {
      printf("%d %s response 200 forwarded.\n",
             status_code, reason_phrase);
    }
    
    sip_exit = SIP_TRUE;
  
  return SIP_NORMAL;
}


/*
 * FACILITY:
 *
 *      sip_call_on_request
 *
 * ABSTRACT:
 *
 *      Any request that cannot be mapped on defined callback
 *
 * FORMAL PARAMETERS:
 *
 *      instance      : The SIP call instance
 *      call          : The call identifier
 *      dialog        : The dialog identifier
 *      transaction   : The transaction identifier
 *      subscription  : The subscription identifier
 *      method        : The method type
 *      method_name   : The method name
 *      request_uri   : The request URI in the message
 *      from          : The from header
 *      to            : The to header
 *      request       : Additional headers in the INVITE
 *      body          : The received body
 *      user_info     : The user info
 *
 * RETURN VALUE:
 *
 *      SIP_NORMAL : successful completion
 *
 */

sip_status_t sip_call_on_request
  (
    sip_call_inst_t               instance,
    sip_call_t                    call,
    sip_dialog_t                  dialog,
    sip_trans_t                   transaction,
    sip_subs_t                    subscription,
    sip_msg_method_t              method,
    char                        * method_name,
    sip_msg_uri_t               * request_uri,
    sip_msg_header_t            * from,
    sip_msg_header_t            * to,
    sip_msg_header_vector_t     * request,
    sip_msg_body_t              * body,
    sip_user_info_t             * user_info
  )
{
  printf("Unknown request received\n");
  
  return SIP_NORMAL;
}


/*
 * FACILITY:
 *
 *      sip_call_on_reply
 *
 * ABSTRACT:
 *
 *      Any response that cannot be mapped on defined callback
 *
 * FORMAL PARAMETERS:
 *
 *      instance      : The SIP call instance
 *      call          : The call identifier
 *      dialog        : The dialog identifier
 *      transaction   : The transaction identifier
 *      subscription  : The subscription identifier
 *      method        : The method type
 *      method_name   : The method name
 *      status_code   : The status code (1xx) received in the response 
 *      reason_phrase : The character string in the received status line
 *      response      : Additional headers in the response
 *      body          : The received body
 *      user_info     : The user info
 *
 * RETURN VALUE:
 *
 *      SIP_NORMAL : successful completion
 *
 */

sip_status_t sip_call_on_reply
  (
    sip_call_inst_t               instance,
    sip_call_t                    call,
    sip_dialog_t                  dialog,
    sip_trans_t                   transaction,
    sip_subs_t                    subscription,
    sip_msg_method_t              method,
    char                        * method_name,
    sip_uint32_t                  status_code,
    char                        * reason_phrase,
    sip_msg_header_vector_t     * response,
    sip_msg_body_t              * body,
    sip_user_info_t             * user_info
  )
{
  printf("Response received: '%d", status_code);
  if(reason_phrase) {
    printf(" %s", reason_phrase);
  }
  sip_status_t    sip_status;
  /* We should forward the response */
  sip_status = sip_trans_forward_response(instance,
                                          transaction,
                                          status_code,
                                          reason_phrase,
                                          response,
                                          body,
                                          NULL);
  if (sip_status != SIP_NORMAL)
    {
      printf("Error %d in forwarding a response 200\n", sip_status);
    } 
  else 
    {
      printf("%d %s response 200 forwarded.\n",
             status_code, reason_phrase);
    }
  printf("'\n");
  return SIP_NORMAL;
}

/*
 * FACILITY:
 *
 *      The SIP call subscription reception callback
 *
 * FORMAL PARAMETERS:
 *
 *      instance      : The SIP call instance
 *      call          : The call identifier
 *      dialog        : The dialog identifier
 *      transaction   : The transaction identifier
 *      subscription  : The subscription identifier
 *      request_uri   : The request URI to forward the INVITE
 *      from          : The from header
 *      to            : The to header
 *      contact       : The contact header
 *      event         : The event header for subscription
 *      expires       : The event expiration header
 *      request       : Additional headers in the INVITE
 *      body          : The INVITE body
 *      user_info     : The user info
 *
 * RETURN VALUE:
 *
 *      SIP_NORMAL : successful completion
 *
 */

sip_status_t sip_call_on_evt_subscribe
  (
    sip_call_inst_t               instance,
    sip_call_t                    call,
    sip_dialog_t                  dialog,
    sip_trans_t                   transaction,
    sip_subs_t                    subscription,
    sip_msg_uri_t               * request_uri,
    sip_msg_header_t            * from,
    sip_msg_header_t            * to,
    sip_msg_header_t            * contact,
    sip_msg_header_t            * event,
    sip_msg_header_t            * expires,
    sip_msg_header_vector_t     * request,
    sip_msg_body_t              * body,
    sip_user_info_t             * user_info
)
{
  sip_status_t       sip_status;
  int                index;
  sip_msg_header_t * contact_response;
  sip_msg_header_t * expires_response;
  sip_msg_header_t * subscription_state;
  char from_string[255];

  if(sip_msg_print_header(from, from_string, 255, SIP_FALSE, NULL) > 0) {
    printf("Subscription for event '%s' received  %s\n",
	   event -> structured_header -> content.event.event_type,
	   from_string);
  }
  
  contact_response = sip_msg_new_contact_header
    (request_uri, NULL, -1, -1, NULL, NULL);

  if(!contact_response) {
    printf("Unable to build the Contact: header\n");
    exit(1);
  }
  
  expires_response = sip_msg_new_expires_header(10, NULL, NULL);

  if(!expires_response) {
    printf("Unable to build the Expires: header\n");
    exit(1);
  }

  /* Then send a call accept */
  sip_status = sip_call_evt_accept(instance,
				   call,
				   dialog,
				   transaction,
				   subscription,
				   200,
				   "OK",
				   contact_response,
				   expires_response,
				   NULL,
				   body,
				   NULL);
  
  if (sip_status != SIP_NORMAL) {
    printf("The subscription can't be accepted, rc = %d.\n", sip_status);
  } else {
    printf("Subscription accepted...\n");
  }
  
  sip_msg_free_header(contact_response);
  sip_msg_free_header(expires_response);
  
  for(index = 0; index < 5; index ++) {

    char value[10];
    sip_trans_t new_transaction;

    sprintf(value, "value_%d", index);

    subscription_state = sip_msg_new_subscription_state_header
      (value, NULL, -1, -1, NULL, NULL);
    
    sleep(1);

    sip_status = sip_call_evt_notify(instance,
				     call,
				     dialog,
				     &new_transaction,
				     subscription,
				     subscription_state,
				     NULL,
				     body,
				     NULL);
    
    if (sip_status != SIP_NORMAL) {
      printf("Notification can't be sent, rc = %d.\n", sip_status);
    } else {
      printf("Notify sent with status '%s'.\n", value);
    }

    sip_msg_free_header(subscription_state);
  }

  return SIP_NORMAL;
}

/*
 * FACILITY:
 *
 *      The SIP call notify reception callback
 *
 * FORMAL PARAMETERS:
 *
 *      instance           : The SIP call instance
 *      call               : The call identifier
 *      dialog             : The dialog identifier
 *      transaction        : The transaction identifier
 *      subscription       : The subscription identifier
 *      subscription state : The state of the recieved event
 *      request            : Additional headers in the INVITE
 *      body               : The INVITE body
 *      user_info          : The user info
 *
 * RETURN VALUE:
 *
 *      SIP_NORMAL : successful completion
 *
 */

sip_status_t sip_call_on_evt_notify
  (
    sip_call_inst_t               instance,
    sip_call_t                    call,
    sip_dialog_t                  dialog,
    sip_trans_t                   transaction,
    sip_subs_t                    subscription,
    sip_msg_uri_t               * request_uri,
    sip_msg_header_t            * event,
    sip_msg_header_t            * subscription_state,
    sip_msg_header_vector_t     * request,
    sip_msg_body_t              * body,
    sip_user_info_t             * user_info
)
{
  sip_status_t       sip_status;
  sip_msg_header_t * contact_response;

  printf("NOTIFY received with status '%s' for event '%s'...",
	 subscription_state -> structured_header -> 
	 content.subscription_state.value,
	 event -> structured_header -> content.event.event_type);
  fflush(stdout);
  
  /* Then send a 200 OK */
  sip_status = sip_call_reply(instance,
			      call,
			      dialog,
			      transaction,
			      subscription,
			      200,
			      NULL,
			      NULL,
			      NULL,
			      SIP_FALSE,
			      NULL);
  
  if (sip_status != SIP_NORMAL) {
    printf("\nError sending the NOTIFY 200 OK, rc = %d.\n", sip_status);
  } else {
    printf(" 200 OK sent.\n");
  }
  
  if (unscuscribe_counter) {
    unscuscribe_counter--;

⌨️ 快捷键说明

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