1 /*****************************************************************************
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 *****************************************************************************/
25 #include <vlc_common.h>
26 #include <vlc_plugin.h>
28 #include <vlc_block.h>
29 #include <vlc_strings.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
)
53 case ACCESS_OUT_CONTROLS_PACE
:
54 *va_arg(args
, bool *) = true;
57 case ACCESS_OUT_CAN_SEEK
:
58 *va_arg(args
, bool *) = false;
68 static const char *const sout_options
[] = {
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
))
80 sys
->manager
= vlc_http_mgr_create(obj
, NULL
);
81 if (sys
->manager
== NULL
)
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
,
100 if (sys
->file
== NULL
) {
101 msg_Err(obj
, "cannot create HTTP resource %s", access
->psz_path
);
102 vlc_http_mgr_destroy(sys
->manager
);
107 access
->pf_write
= Write
;
108 access
->pf_control
= Control
;
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
);
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"),
133 add_password(SOUT_CFG_PREFIX
"pwd", NULL
, N_("Password"), N_("Password"))
134 set_callbacks(Open
, Close
)