void gmpv_mpv_obj_load( GmpvMpvObj *mpv, const gchar *uri, gboolean append, gboolean update ) { const gchar *load_cmd[] = {"loadfile", NULL, NULL, NULL}; GtkListStore *playlist_store = gmpv_playlist_get_store(mpv->playlist); GtkTreeIter iter; gboolean empty; g_info( "Loading file (append=%s, update=%s): %s", append?"TRUE":"FALSE", update?"TRUE":"FALSE", uri?:"<PLAYLIST_ITEMS>" ); empty = !gtk_tree_model_get_iter_first (GTK_TREE_MODEL(playlist_store), &iter); load_cmd[2] = (append && !empty)?"append":"replace"; if(!append && uri && update) { gmpv_playlist_clear(mpv->playlist); mpv->state.new_file = TRUE; mpv->state.loaded = FALSE; } if(!uri) { gboolean append = FALSE; gboolean rc; if(!mpv->state.init_load) { gmpv_mpv_obj_set_property_flag(mpv, "pause", FALSE); } rc = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(playlist_store), &iter); while(rc) { gchar *uri; gtk_tree_model_get( GTK_TREE_MODEL(playlist_store), &iter, PLAYLIST_URI_COLUMN, &uri, -1 ); /* append = FALSE only on first iteration */ gmpv_mpv_obj_load(mpv, uri, append, FALSE); append = TRUE; rc = gtk_tree_model_iter_next (GTK_TREE_MODEL(playlist_store), &iter); g_free(uri); } } if(uri && playlist_store) { gchar *path = get_path_from_uri(uri); load_cmd[1] = path; if(!append) { mpv->state.loaded = FALSE; if(!mpv->state.init_load) { gmpv_mpv_obj_set_property_flag (mpv, "pause", FALSE); } } if(update) { gchar *name = get_name_from_path(path); gmpv_playlist_append(mpv->playlist, name, uri); g_free(name); } g_assert(mpv->mpv_ctx); mpv_check_error(mpv_request_event( mpv->mpv_ctx, MPV_EVENT_END_FILE, 0 )); mpv_check_error(mpv_command(mpv->mpv_ctx, load_cmd)); mpv_check_error(mpv_request_event( mpv->mpv_ctx, MPV_EVENT_END_FILE, 1 )); g_free(path); } }
static void static_files_cb(struct evhttp_request *req, void *arg) { http_serverlog_request(req); const char *static_root = arg; apr_pool_t *local_pool; const char *full_name; struct stat64 file_stat; const char *mime_type; if(!static_root) { LOG4C_ERROR(logger, "static root not configured"); evhttp_send_error(req, HTTP_NOTFOUND, "Static file server not configured"); return; } const char *uri = evhttp_request_get_uri(req); if (strstr(uri, "..") != NULL) { LOG4C_ERROR(logger, "illegal URL"); evhttp_send_error(req, HTTP_BADREQUEST, "Illegal URL"); return; } CREATE_POOL(local_pool, NULL); const char *path = get_path_from_uri(local_pool, uri); mime_type = guess_mime_type(uri); LOG4C_DEBUG(logger, "mime type is %s", mime_type); full_name = apr_pstrcat(local_pool, static_root, "/", path, NULL); if (lstat64(full_name, &file_stat) < 0) { LOG4C_ERROR(logger, "file not found"); evhttp_send_error(req, HTTP_NOTFOUND, NULL); return; } int fd = open(full_name, O_RDONLY); if (fd < 0) { LOG4C_ERROR(logger, "open failed"); evhttp_send_error(req, HTTP_NOTFOUND, NULL); return; } struct evbuffer *rep_buf = evbuffer_new(); evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", mime_type); evbuffer_set_flags(rep_buf, EVBUFFER_FLAG_DRAINS_TO_FD); //TODO: LIBEVENT DOES NOT SUPPORT LARGE FILES - USES off_t BUT _FILE_OFFSET_BITS=64 IS NOT DEFINED! evbuffer_add_file(rep_buf, fd, 0, file_stat.st_size); // evhttp_send_reply(req, HTTP_OK, "OK", rep_buf); evbuffer_free(rep_buf); RELEASE_POOL(local_pool); }