FS-9904 #resolve cleanup and refactor msrp
This commit is contained in:
parent
9dba32410f
commit
08603c7e89
|
@ -48,10 +48,9 @@ enum {
|
|||
MSRP_METHOD_SEND,
|
||||
MSRP_METHOD_AUTH,
|
||||
MSRP_METHOD_REPORT,
|
||||
|
||||
};
|
||||
|
||||
enum {
|
||||
typedef enum {
|
||||
MSRP_H_FROM_PATH,
|
||||
MSRP_H_TO_PATH,
|
||||
MSRP_H_MESSAGE_ID,
|
||||
|
@ -60,8 +59,14 @@ enum {
|
|||
MSRP_H_FAILURE_REPORT,
|
||||
MSRP_H_STATUS,
|
||||
MSRP_H_KEEPALIVE,
|
||||
|
||||
/* Fake headers */
|
||||
MSRP_H_TRASACTION_ID,
|
||||
MSRP_H_DELIMITER,
|
||||
MSRP_H_CODE_DESCRIPTION,
|
||||
|
||||
MSRP_H_UNKNOWN
|
||||
};
|
||||
} switch_msrp_header_type_t;
|
||||
|
||||
typedef struct switch_msrp_session_s switch_msrp_session_t;
|
||||
typedef struct msrp_client_socket_s switch_msrp_client_socket_t;
|
||||
|
@ -70,16 +75,16 @@ typedef struct msrp_socket_s switch_msrp_socket_t;
|
|||
typedef struct msrp_msg_s {
|
||||
int state;
|
||||
int method;
|
||||
char *headers[12];
|
||||
int last_header;
|
||||
char *transaction_id;
|
||||
char *delimiter;
|
||||
switch_event_t *headers;
|
||||
const char *transaction_id;
|
||||
const char *delimiter;
|
||||
int code_number;
|
||||
char *code_description;
|
||||
const char *code_description;
|
||||
switch_size_t byte_start;
|
||||
switch_size_t byte_end;
|
||||
switch_size_t bytes;
|
||||
switch_size_t payload_bytes;
|
||||
switch_size_t accumulated_bytes;
|
||||
int range_star; /* range-end is '*' */
|
||||
char *last_p;
|
||||
char *payload;
|
||||
|
@ -125,7 +130,15 @@ SWITCH_DECLARE(switch_status_t) switch_msrp_perform_send(switch_msrp_session_t *
|
|||
SWITCH_DECLARE(switch_status_t) switch_msrp_start_client(switch_msrp_session_t *msrp_session);
|
||||
SWITCH_DECLARE(const char *) switch_msrp_listen_ip(void);
|
||||
|
||||
SWITCH_DECLARE(switch_msrp_msg_t*) switch_msrp_msg_create();
|
||||
SWITCH_DECLARE(void) switch_msrp_msg_destroy(switch_msrp_msg_t **msg);
|
||||
|
||||
SWITCH_DECLARE(void) switch_msrp_load_apis_and_applications(switch_loadable_module_interface_t **moudle_interface);
|
||||
SWITCH_DECLARE(const char*) switch_msrp_msg_get_header(switch_msrp_msg_t *msrp_msg, switch_msrp_header_type_t htype);
|
||||
SWITCH_DECLARE(switch_status_t) switch_msrp_msg_add_header(switch_msrp_msg_t *msrp_msg, switch_msrp_header_type_t htype, char *fmt, ...);
|
||||
SWITCH_DECLARE(void) switch_msrp_msg_set_payload(switch_msrp_msg_t *msrp_msg, const char *buf, switch_size_t payload_bytes);
|
||||
SWITCH_DECLARE(char*) switch_msrp_header_name(switch_msrp_header_type_t htype);
|
||||
SWITCH_DECLARE(switch_msrp_msg_t *) switch_msrp_msg_dup(switch_msrp_msg_t *msg);
|
||||
|
||||
#define switch_msrp_send(ms, msg) switch_msrp_perform_send(ms, msg, __FILE__, __SWITCH_FUNC__, __LINE__)
|
||||
|
||||
|
|
|
@ -958,46 +958,40 @@ static switch_status_t sofia_read_text_frame(switch_core_session_t *session, swi
|
|||
switch_msrp_session_t *msrp_session = switch_core_media_get_msrp_session(session);
|
||||
switch_frame_t *rframe = &msrp_session->frame;
|
||||
switch_msrp_msg_t *msrp_msg = switch_msrp_session_pop_msg(msrp_session);
|
||||
const char *msrp_h_content_type = NULL;
|
||||
|
||||
if (msrp_msg) {
|
||||
msrp_h_content_type = switch_msrp_msg_get_header(msrp_msg, MSRP_H_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
rframe->flags = 0;
|
||||
|
||||
#if 0
|
||||
if (msrp_msg && msrp_msg->method == MSRP_METHOD_SEND) { /*echo back*/
|
||||
char *p;
|
||||
p = msrp_msg->headers[MSRP_H_TO_PATH];
|
||||
msrp_msg->headers[MSRP_H_TO_PATH] = msrp_msg->headers[MSRP_H_FROM_PATH];
|
||||
msrp_msg->headers[MSRP_H_FROM_PATH] = p;
|
||||
switch_msrp_send(msrp_session, msrp_msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
rframe->data = msrp_session->frame_data;
|
||||
rframe->buflen = sizeof(msrp_session->frame_data);
|
||||
|
||||
if (msrp_msg && msrp_msg->method == MSRP_METHOD_SEND &&
|
||||
msrp_msg->payload &&
|
||||
!switch_stristr("?OTRv3?", msrp_msg->payload) &&
|
||||
!switch_stristr("application/im-iscomposing", msrp_msg->payload) &&
|
||||
msrp_msg->headers[MSRP_H_CONTENT_TYPE] &&
|
||||
(switch_stristr("text/plain", msrp_msg->headers[MSRP_H_CONTENT_TYPE]) ||
|
||||
switch_stristr("text/html", msrp_msg->headers[MSRP_H_CONTENT_TYPE]) ||
|
||||
switch_stristr("message/cpim", msrp_msg->headers[MSRP_H_CONTENT_TYPE]))) {
|
||||
msrp_h_content_type &&
|
||||
(switch_stristr("text/plain", msrp_h_content_type) ||
|
||||
switch_stristr("text/html", msrp_h_content_type) ||
|
||||
switch_stristr("message/cpim", msrp_h_content_type))) {
|
||||
|
||||
rframe->datalen = msrp_msg->payload_bytes;
|
||||
rframe->packetlen = msrp_msg->payload_bytes;
|
||||
memcpy(rframe->data, msrp_msg->payload, msrp_msg->payload_bytes);
|
||||
|
||||
rframe->packetlen = msrp_msg->payload_bytes + 12;
|
||||
memcpy(rframe->data, msrp_msg->payload, msrp_msg->payload_bytes + 1); /* include the last NULL byte */
|
||||
|
||||
rframe->m = 1;
|
||||
|
||||
*frame = rframe;
|
||||
|
||||
if (msrp_msg->headers[MSRP_H_CONTENT_TYPE] && !strcasecmp(msrp_msg->headers[MSRP_H_CONTENT_TYPE], "message/cpim")) {
|
||||
|
||||
if (msrp_h_content_type && !strcasecmp(msrp_h_content_type, "message/cpim")) {
|
||||
char *stripped_text = switch_html_strip((char *)rframe->data);
|
||||
memcpy(rframe->data, stripped_text, strlen(stripped_text)+1);
|
||||
rframe->datalen = strlen(stripped_text)+1;
|
||||
free(stripped_text);
|
||||
}
|
||||
|
||||
switch_safe_free(msrp_msg);
|
||||
msrp_msg = NULL;
|
||||
switch_msrp_msg_destroy(&msrp_msg);
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
} else {
|
||||
rframe->datalen = 2;
|
||||
|
@ -1009,8 +1003,6 @@ static switch_status_t sofia_read_text_frame(switch_core_session_t *session, swi
|
|||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return switch_core_media_read_frame(session, frame, flags, stream_id, SWITCH_MEDIA_TYPE_TEXT);
|
||||
}
|
||||
|
||||
|
@ -1020,13 +1012,15 @@ static switch_status_t sofia_write_text_frame(switch_core_session_t *session, sw
|
|||
switch_msrp_session_t *msrp_session = switch_core_media_get_msrp_session(session);
|
||||
|
||||
if (frame && msrp_session) {
|
||||
switch_msrp_msg_t msrp_msg = { 0 };
|
||||
switch_msrp_msg_t *msrp_msg = switch_msrp_msg_create();
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
||||
//msrp_msg.headers[MSRP_H_CONTENT_TYPE] = "message/cpim";
|
||||
msrp_msg.headers[MSRP_H_CONTENT_TYPE] = "text/plain";
|
||||
msrp_msg.payload = frame->data;
|
||||
msrp_msg.payload_bytes = frame->datalen;
|
||||
return switch_msrp_send(msrp_session, &msrp_msg);
|
||||
// switch_msrp_msg_add_header(&msrp_msg, MSRP_H_CONTENT_TYPE, "message/cpim");
|
||||
switch_msrp_msg_add_header(msrp_msg, MSRP_H_CONTENT_TYPE, "text/plain");
|
||||
switch_msrp_msg_set_payload(msrp_msg, frame->data, frame->datalen);
|
||||
status = switch_msrp_send(msrp_session, msrp_msg);
|
||||
switch_msrp_msg_destroy(&msrp_msg);
|
||||
return status;
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_FALSE;
|
||||
|
|
|
@ -10509,7 +10509,7 @@ SWITCH_DECLARE(void) switch_core_media_gen_local_sdp(switch_core_session_t *sess
|
|||
msrp_session->active ? "active" : "passive");
|
||||
|
||||
if (!zstr(file_selector)) {
|
||||
switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
|
||||
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf),
|
||||
"a=sendonly\na=file-selector:%s\n", file_selector);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue