/* Process incoming RTSP request */ static apt_bool_t rtsp_server_session_request_process(rtsp_server_t *server, rtsp_server_connection_t *rtsp_connection, rtsp_message_t *message) { rtsp_server_session_t *session = NULL; if(message->start_line.message_type != RTSP_MESSAGE_TYPE_REQUEST) { /* received response to ANNOUNCE request/event */ return TRUE; } if(rtsp_header_property_check(&message->header,RTSP_HEADER_FIELD_SESSION_ID) != TRUE) { /* no session-id specified */ session = rtsp_server_session_setup_process(server,rtsp_connection,message); if(session) { session->active_request = message; if(rtsp_server_session_message_handle(server,session,message) != TRUE) { rtsp_server_session_destroy(session); } } else { /* error case, failed to create a session */ apt_log(RTSP_LOG_MARK,APT_PRIO_WARNING,"Failed to Create RTSP Session"); return rtsp_server_error_respond(server,rtsp_connection,message, RTSP_STATUS_CODE_NOT_ACCEPTABLE, RTSP_REASON_PHRASE_NOT_ACCEPTABLE); } return TRUE; } /* existing session */ session = apr_hash_get( rtsp_connection->session_table, message->header.session_id.buf, message->header.session_id.length); if(!session) { /* error case, no such session */ apt_log(RTSP_LOG_MARK,APT_PRIO_WARNING,"No Such RTSP Session " APT_SID_FMT,message->header.session_id.buf); return rtsp_server_error_respond(server,rtsp_connection,message, RTSP_STATUS_CODE_NOT_FOUND, RTSP_REASON_PHRASE_NOT_FOUND); } if(session->terminating == TRUE) { /* error case, session is being terminated */ apt_log(RTSP_LOG_MARK,APT_PRIO_WARNING,"Not Acceptable Request " APT_SID_FMT,message->header.session_id.buf); return rtsp_server_error_respond(server,rtsp_connection,message, RTSP_STATUS_CODE_NOT_ACCEPTABLE, RTSP_REASON_PHRASE_NOT_ACCEPTABLE); } if(session->active_request) { apt_log(RTSP_LOG_MARK,APT_PRIO_DEBUG,"Push RTSP Request to Queue " APT_SID_FMT,session->id.buf); apt_list_push_back(session->request_queue,message,message->pool); return TRUE; } /* handle the request */ session->active_request = message; rtsp_server_session_message_handle(server,session,message); return TRUE; }
/* Process incoming RTSP request */ static apt_bool_t rtsp_server_session_request_process(rtsp_server_t *server, rtsp_server_connection_t *rtsp_connection, rtsp_message_t *message) { rtsp_server_session_t *session = NULL; if(message->start_line.message_type != RTSP_MESSAGE_TYPE_REQUEST) { /* received response to ANNOUNCE request/event */ return TRUE; } if(rtsp_header_property_check(&message->header.property_set,RTSP_HEADER_FIELD_SESSION_ID) != TRUE) { /* no session-id specified */ session = rtsp_server_session_setup_process(server,rtsp_connection,message); if(session) { session->active_request = message; if(rtsp_server_session_message_handle(server,session,message) != TRUE) { rtsp_server_session_destroy(session); } } return TRUE; } /* existing session */ session = apr_hash_get( rtsp_connection->session_table, message->header.session_id.buf, message->header.session_id.length); if(!session) { /* error case */ apt_log(APT_PRIO_WARNING,"No Such RTSP Session <%s>",message->header.session_id.buf); return rtsp_server_error_respond(server,rtsp_connection,message, RTSP_STATUS_CODE_NOT_FOUND, RTSP_REASON_PHRASE_NOT_FOUND); } if(session->active_request) { apt_log(APT_PRIO_DEBUG,"Push RTSP Request to Queue <%s>",session->id.buf); apt_list_push_back(session->request_queue,message); return TRUE; } /* handle the request */ session->active_request = message; rtsp_server_session_message_handle(server,session,message); return TRUE; }
/* Process outgoing RTSP response */ static apt_bool_t rtsp_server_session_response_process(rtsp_server_t *server, rtsp_server_session_t *session, rtsp_message_t *message) { if(message->start_line.message_type == RTSP_MESSAGE_TYPE_REQUEST) { /* RTSP ANNOUNCE request (asynch event) */ message->start_line.common.request_line.url = session->url; if(session->id.buf) { message->header.session_id = session->id; rtsp_header_property_add(&message->header.property_set,RTSP_HEADER_FIELD_SESSION_ID); } rtsp_server_message_send(server,session->connection->base,message); return TRUE; } if(session->id.buf) { message->header.session_id = session->id; rtsp_header_property_add(&message->header.property_set,RTSP_HEADER_FIELD_SESSION_ID); } rtsp_server_message_send(server,session->connection->base,message); if(session->active_request) { rtsp_message_t *request = session->active_request; if(request->start_line.common.request_line.method_id == RTSP_METHOD_SETUP) { if(message->start_line.common.status_line.status_code != RTSP_STATUS_CODE_OK) { rtsp_server_session_terminate_request(server,session); } } else if(request->start_line.common.request_line.method_id == RTSP_METHOD_DESCRIBE) { rtsp_server_session_terminate_request(server,session); } } session->active_request = apt_list_pop_front(session->request_queue); if(session->active_request) { rtsp_server_session_message_handle(server,session,session->active_request); } return TRUE; }
/* Process outgoing RTSP response */ static apt_bool_t rtsp_server_session_response_process(rtsp_server_t *server, rtsp_server_session_t *session, rtsp_message_t *message) { apt_bool_t terminate = FALSE; rtsp_message_t *request = NULL; if(message->start_line.message_type == RTSP_MESSAGE_TYPE_REQUEST) { /* RTSP ANNOUNCE request (asynch event) */ const char *resource_name = message->start_line.common.request_line.resource_name; if(resource_name) { request = apr_hash_get(session->resource_table,resource_name,APR_HASH_KEY_STRING); } if(!request) { return FALSE; } message->start_line.common.request_line.url = request->start_line.common.request_line.url; message->header.cseq = session->last_cseq; rtsp_header_property_add(&message->header,RTSP_HEADER_FIELD_CSEQ,message->pool); if(session->id.buf) { message->header.session_id = session->id; rtsp_header_property_add(&message->header,RTSP_HEADER_FIELD_SESSION_ID,message->pool); } rtsp_server_message_send(server,session->connection,message); return TRUE; } if(!session->active_request) { /* unexpected response */ return FALSE; } request = session->active_request; if(request->start_line.common.request_line.method_id == RTSP_METHOD_DESCRIBE) { terminate = TRUE; } else { if(session->id.buf) { message->header.session_id = session->id; rtsp_header_property_add(&message->header,RTSP_HEADER_FIELD_SESSION_ID,message->pool); } if(request->start_line.common.request_line.method_id == RTSP_METHOD_SETUP) { if(message->start_line.common.status_line.status_code == RTSP_STATUS_CODE_OK) { /* add resource */ const char *resource_name = request->start_line.common.request_line.resource_name; apr_hash_set(session->resource_table,resource_name,APR_HASH_KEY_STRING,request); } else if(apr_hash_count(session->resource_table) == 0) { terminate = TRUE; } } } session->last_cseq = message->header.cseq; rtsp_server_message_send(server,session->connection,message); if(terminate == TRUE) { session->active_request = NULL; rtsp_server_session_terminate_request(server,session); return TRUE; } session->active_request = apt_list_pop_front(session->request_queue); if(session->active_request) { rtsp_server_session_message_handle(server,session,session->active_request); } return TRUE; }