qt: playlist: use item title if available
[vlc.git] / modules / access_output / http-put.c
blob872efe5f2d5e2af7e7b036448b2cc7e0909aaf7c
1 /*****************************************************************************
2 * http-put.c
3 *****************************************************************************
4 * Copyright (C) 2020 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <vlc_common.h>
26 #include <vlc_plugin.h>
27 #include <vlc_sout.h>
28 #include <vlc_block.h>
29 #include <vlc_strings.h>
30 #include "connmgr.h"
31 #include "outfile.h"
33 #define SOUT_CFG_PREFIX "sout-http-put-"
35 struct sout_http_put {
36 struct vlc_http_mgr *manager;
37 struct vlc_http_outfile *file;
40 static ssize_t Write(sout_access_out_t *access, block_t *block)
42 struct sout_http_put *sys = access->p_sys;
44 return vlc_http_outfile_write(sys->file, block);
47 static int Control(sout_access_out_t *access, int query, va_list args)
49 (void) access;
51 switch (query)
53 case ACCESS_OUT_CONTROLS_PACE:
54 *va_arg(args, bool *) = true;
55 break;
57 case ACCESS_OUT_CAN_SEEK:
58 *va_arg(args, bool *) = false;
59 break;
61 default:
62 return VLC_EGENERIC;
65 return VLC_SUCCESS;
68 static const char *const sout_options[] = {
69 "user", "pwd", NULL
72 static int Open(vlc_object_t *obj)
74 sout_access_out_t *access = (sout_access_out_t *)obj;
76 struct sout_http_put *sys = vlc_obj_malloc(obj, sizeof (*sys));
77 if (unlikely(sys == NULL))
78 return VLC_ENOMEM;
80 sys->manager = vlc_http_mgr_create(obj, NULL);
81 if (sys->manager == NULL)
82 return VLC_ENOMEM;
84 config_ChainParse(obj, SOUT_CFG_PREFIX, sout_options, access->p_cfg);
86 char *ua = var_InheritString(obj, "http-user-agent");
87 char *user = var_GetString(obj, SOUT_CFG_PREFIX"user");
88 char *pwd = var_GetString(obj, SOUT_CFG_PREFIX"pwd");
90 /* XXX: Empty user / password strings are not the same as NULL. No ways to
91 * distinguish with the VLC APIs.
94 sys->file = vlc_http_outfile_create(sys->manager, access->psz_path, ua,
95 user, pwd);
96 free(pwd);
97 free(user);
98 free(ua);
100 if (sys->file == NULL) {
101 msg_Err(obj, "cannot create HTTP resource %s", access->psz_path);
102 vlc_http_mgr_destroy(sys->manager);
103 return VLC_EGENERIC;
106 access->p_sys = sys;
107 access->pf_write = Write;
108 access->pf_control = Control;
110 return VLC_SUCCESS;
113 static void Close(vlc_object_t *obj)
115 sout_access_out_t *access = (sout_access_out_t *)obj;
116 struct sout_http_put *sys = access->p_sys;
118 if (vlc_http_outfile_close(sys->file))
119 msg_Err(obj, "server error while writing file");
121 vlc_http_mgr_destroy(sys->manager);
124 vlc_module_begin()
125 set_description(N_("HTTP PUT stream output"))
126 set_shortname(N_("HTTP PUT"))
127 set_capability("sout access", 0)
128 set_category(CAT_SOUT)
129 set_subcategory(SUBCAT_SOUT_ACO)
130 add_shortcut("http-put")
131 add_string(SOUT_CFG_PREFIX"user", NULL, N_("Username"), N_("Username"),
132 true)
133 add_password(SOUT_CFG_PREFIX"pwd", NULL, N_("Password"), N_("Password"))
134 set_callbacks(Open, Close)
135 vlc_module_end()