Exemplo n.º 1
0
/**
 * @brief Open a new resource and create a new instance
 *
 * @param srv The server object for the vhost requesting the resource
 * @param inner_path The path, relative to the avroot, for the
 *                   resource
 *
 * @return A new Resource object
 * @retval NULL Error while opening resource
 */
Resource *r_open(const char *inner_path, OpenMode mode)
{
    Resource *r;
    const Demuxer *dmx;
    gchar *mrl, *path;
	gint ls, ls_store;		/* ls: use demuxer_ls; ls_store: demuxer_ls with history streams */

	path = get_media_path(inner_path, &ls, &ls_store);
	mrl = g_strdup_printf("%s%s", RESOURCE_ROOT, path);
	g_free(path);

    if ((dmx = r_find_demuxer(mrl)) == NULL)
    {
        rc_log(RC_LOG_DEBUG,
                "[MT] Could not find a valid demuxer for resource %s\n",
                mrl);
        goto error;
    }

    rc_log(RC_LOG_DEBUG, "[MT] registrered demuxer \"%s\" for resource"
                               "\"%s\"\n", dmx->info->name, mrl);

    r = g_slice_new0(Resource);
    r->info = g_slice_new0(ResourceInfo);
    r->info->mrl = mrl;
    r->info->mtime = 0;
    r->info->name = g_path_get_basename(mrl);
    r->info->seekable = (dmx->seek != NULL);

    if (ls && !ls_store)
		r->info->seekable = FALSE;

    r->demuxer = dmx;
	r->mode = mode;

    if (r->demuxer->init(r))
    {
        r_free_cb(r, NULL);
        return NULL;
    }

    /* Now that we have opened the actual resource we can proceed with
     * the extras */

    r->lock = g_mutex_new();

#ifdef HAVE_METADATA
    cpd_find_request(srv, r, filename);
#endif

    return r;
 error:
    g_free(mrl);
    return NULL;
}
Exemplo n.º 2
0
/**
 * @brief Open a new resource and create a new instance
 *
 * @param srv The server object for the vhost requesting the resource
 * @param inner_path The path, relative to the avroot, for the
 *                   resource
 *
 * @return A new Resource object
 * @retval NULL Error while opening resource
 */
Resource *r_open(struct feng *srv, const char *inner_path)
{
    Resource *r;
    const Demuxer *dmx;
    gchar *mrl = g_strjoin ("/",
                            srv->config_storage[0].document_root->ptr,
                            inner_path,
                            NULL);
	struct stat filestat;

	if (stat(mrl, &filestat) == -1 ) {
		switch(errno) {
        case ENOENT:
            fnc_log(FNC_LOG_ERR,"%s: file not found\n", mrl);
            break;
        default:
            fnc_log(FNC_LOG_ERR,"Cannot stat file %s\n", mrl);
            break;
		}
        goto error;
	}

	if ( S_ISFIFO(filestat.st_mode) ) {
		fnc_log(FNC_LOG_ERR, "%s: not a file\n");
        goto error;
    }

    if ( (dmx = r_find_demuxer(mrl)) == NULL ) {
        fnc_log(FNC_LOG_DEBUG,
                "[MT] Could not find a valid demuxer for resource %s\n",
                mrl);
        goto error;
    }

    fnc_log(FNC_LOG_DEBUG, "[MT] registrered demuxer \"%s\" for resource"
                               "\"%s\"\n", dmx->info->name, mrl);

    r = g_slice_new0(Resource);

    r->info = g_slice_new0(ResourceInfo);

    r->info->mrl = mrl;
    r->info->mtime = filestat.st_mtime;
    r->info->name = g_path_get_basename(inner_path);
    r->info->seekable = (dmx->seek != NULL);

    r->demuxer = dmx;
    r->srv = srv;

    if (r->demuxer->init(r)) {
        r_free_cb(r, NULL);
        return NULL;
    }

    /* Now that we have opened the actual resource we can proceed with
     * the extras */

    r->lock = g_mutex_new();

#ifdef HAVE_METADATA
    cpd_find_request(srv, r, filename);
#endif

    return r;
 error:
    g_free(mrl);
    return NULL;
}