static int dash_server_onvod(void* /*dash*/, http_session_t* session, const char* /*method*/, const char* path)
{
    char fullpath[PATH_MAX];
    int r = path_concat(path + 5 /* /vod/ */, LOCALPATH, fullpath);
	printf("vod: %s\n", fullpath);

	if (0 == r && path_testfile(fullpath))
	{
		// MIME
		if (strendswith(fullpath, ".mpd"))
			http_server_set_content_type(session, "application/xml+dash");
		else if (strendswith(fullpath, ".mp4") || strendswith(fullpath, ".m4v"))
            http_server_set_header(session, "content-type", "video/mp4");
        else if (strendswith(fullpath, ".m4a"))
            http_server_set_header(session, "content-type", "audio/mp4");

		//http_server_set_header(session, "Transfer-Encoding", "chunked");

		// cross domain
		http_server_set_header(session, "Access-Control-Allow-Origin", "*");
		http_server_set_header(session, "Access-Control-Allow-Methods", "GET, POST, PUT");

		return http_server_sendfile(session, fullpath, NULL, NULL);
	}

	return http_server_send(session, 404, "", 0, NULL, NULL);
}
Example #2
0
File: httpd.c Project: ijz/ribs2
/*
 * file server
 */
void simple_file_server(void) {
    /* get the current http server context */
    struct http_server_context *ctx = http_server_get_context();

    /* uri decode the uri in the context */
    http_server_decode_uri(ctx->uri);

    /* remove the leading slash, we will be serving files from the
       current directory */
    const char *file = ctx->uri;
    if (*file == '/') ++file;

    int res = http_server_sendfile(file);
    if (0 > res) {
        /* not found */
        if (HTTP_SERVER_NOT_FOUND == res)
            http_server_response_sprintf(HTTP_STATUS_404,
                                         HTTP_CONTENT_TYPE_TEXT_PLAIN, "not found: %s", file);
        else
            http_server_response_sprintf(HTTP_STATUS_500,
                                         HTTP_CONTENT_TYPE_TEXT_PLAIN, "500 Internal Server Error: %s", file);
    }
    else if (0 < res) {
        /* directory */
        if (0 > http_server_generate_dir_list(ctx->uri)) {
            http_server_response_sprintf(HTTP_STATUS_404,
                                         HTTP_CONTENT_TYPE_TEXT_PLAIN, "dir not found: %s", ctx->uri);
            return;
        }
        http_server_response(HTTP_STATUS_200,
                             HTTP_CONTENT_TYPE_TEXT_HTML);
    }
}
static int dash_server_onlive(void* dash, http_session_t* session, const char* /*method*/, const char* path)
{
    char fullpath[PATH_MAX];
    int r = path_concat(path + 6 /* /live/ */, LOCALPATH, fullpath);
	printf("live: %s\n", fullpath);

	const char* name = path_basename(fullpath);
	if (strendswith(name, ".mpd"))
	{
        return dash_server_mpd(session, (dash_playlist_t*)dash);
	}
	else if (path_testfile(name))
	{
		// cross domain
		http_server_set_header(session, "Access-Control-Allow-Origin", "*");
		http_server_set_header(session, "Access-Control-Allow-Methods", "GET, POST, PUT");
		return http_server_sendfile(session, name, NULL, NULL);
	}

	return http_server_send(session, 404, "", 0, NULL, NULL);
}