示例#1
0
static int rtsp_server_reply(struct rtsp_server_request_t *req, int code)
{
	rfc822_datetime_t datetime;
	datetime_format(time(NULL), datetime);

	snprintf(req->reply, sizeof(req->reply), 
		"RTSP/1.0 %d %s\r\n"
		"CSeq: %u\r\n"
		"Date: %s\r\n"
		"\r\n",
		code, rtsp_reason_phrase(code), req->cseq, datetime);

	return req->transport->send(req->session, req->reply, strlen(req->reply));
}
示例#2
0
/**
 * @brief Finalise, send and free an response object
 *
 * @param response The response to send
 *
 * This method generates an RTSP response message, following the indication of
 * RFC 2326 Section 7.
 */
void rtsp_response_send(RTSP_Response *response)
{
    GString *str = g_string_new("");

    /* Generate the status line, see RFC 2326 Sec. 7.1 */
    g_string_printf(str, "%s %d %s" RTSP_EL,
                    "RTSP/1.0", response->status,
                    rtsp_reason_phrase(response->status));

    /* Append the headers */
    g_hash_table_foreach(response->headers,
                         rtsp_response_append_headers,
                         str);

    /* If there is a body we need to calculate its length and append that to the
     * headers, see RFC 2326 Sec. 12.14. */
    if ( response->body )
        g_string_append_printf(str, "%s: %zu" RTSP_EL,
                               eris_hdr_content_length,
                               response->body->len + 2);

    g_string_append(str, RTSP_EL);

    if ( response->body ) {
        g_string_append(str, response->body->str);
        /* Make sure we add a final RTSP_EL here since the body string might
         * not have it at all. */
        g_string_append(str, RTSP_EL);
    }

    /* Now the whole response is complete, we can queue it to be sent away. */
    rtsp_bwrite(response->client, str);

    /* Log the access */
    rtsp_log_access(response);

    /* After we did output to access.log, we can free the response since it's no
     * longer necessary. */
    rtsp_response_free(response);
}