Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLC
Manage
Activity
Members
Labels
Plan
Issues
4k
Issue boards
Milestones
Code
Merge requests
458
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoLAN
VLC
Commits
d1edc1db
Commit
d1edc1db
authored
4 years ago
by
Rémi Denis-Courmont
Browse files
Options
Downloads
Patches
Plain Diff
http: add HTTP PUT helper API
parent
db8b32e0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
modules/access/http/Makefile.am
+1
-0
1 addition, 0 deletions
modules/access/http/Makefile.am
modules/access/http/outfile.c
+129
-0
129 additions, 0 deletions
modules/access/http/outfile.c
modules/access/http/outfile.h
+53
-0
53 additions, 0 deletions
modules/access/http/outfile.h
with
183 additions
and
0 deletions
modules/access/http/Makefile.am
+
1
−
0
View file @
d1edc1db
...
...
@@ -8,6 +8,7 @@ libvlc_http_la_SOURCES = \
access/http/resource.c access/http/resource.h
\
access/http/file.c access/http/file.h
\
access/http/live.c access/http/live.h
\
access/http/outfile.c access/http/outfile.h
\
access/http/hpack.c access/http/hpack.h access/http/hpackenc.c
\
access/http/h2frame.c access/http/h2frame.h
\
access/http/h2output.c access/http/h2output.h
\
...
...
This diff is collapsed.
Click to expand it.
modules/access/http/outfile.c
0 → 100644
+
129
−
0
View file @
d1edc1db
/*****************************************************************************
* resource.c: HTTP resource common code
*****************************************************************************
* Copyright (C) 2015 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include
<errno.h>
#include
<stdbool.h>
#include
<stdlib.h>
#include
<vlc_common.h>
#include
<vlc_url.h>
#include
<vlc_strings.h>
#include
"message.h"
#include
"connmgr.h"
#include
"outfile.h"
struct
vlc_http_outfile
*
vlc_http_outfile_create
(
struct
vlc_http_mgr
*
mgr
,
const
char
*
uri
,
const
char
*
ua
,
const
char
*
user
,
const
char
*
pwd
)
{
struct
vlc_http_msg
*
resp
=
NULL
;
vlc_url_t
url
;
bool
secure
;
if
(
vlc_UrlParse
(
&
url
,
uri
))
goto
error
;
if
(
url
.
psz_protocol
==
NULL
||
url
.
psz_host
==
NULL
)
{
errno
=
EINVAL
;
goto
error
;
}
if
(
!
vlc_ascii_strcasecmp
(
url
.
psz_protocol
,
"https"
))
secure
=
true
;
else
if
(
!
vlc_ascii_strcasecmp
(
url
.
psz_protocol
,
"http"
))
secure
=
false
;
else
{
errno
=
ENOTSUP
;
goto
error
;
}
char
*
authority
=
vlc_http_authority
(
url
.
psz_host
,
url
.
i_port
);
if
(
unlikely
(
authority
==
NULL
))
goto
error
;
struct
vlc_http_msg
*
req
=
vlc_http_req_create
(
"PUT"
,
url
.
psz_protocol
,
authority
,
url
.
psz_path
);
free
(
authority
);
if
(
unlikely
(
req
==
NULL
))
goto
error
;
vlc_http_msg_add_header
(
req
,
"Expect"
,
"100-continue"
);
if
(
user
!=
NULL
&&
pwd
!=
NULL
)
vlc_http_msg_add_creds_basic
(
req
,
false
,
user
,
pwd
);
if
(
ua
!=
NULL
)
vlc_http_msg_add_agent
(
req
,
ua
);
vlc_http_msg_add_cookies
(
req
,
vlc_http_mgr_get_jar
(
mgr
));
resp
=
vlc_http_mgr_request
(
mgr
,
secure
,
url
.
psz_host
,
url
.
i_port
,
req
,
false
,
true
);
vlc_http_msg_destroy
(
req
);
if
(
resp
==
NULL
)
goto
error
;
int
status
=
vlc_http_msg_get_status
(
resp
);
/* FIXME: check that HTTP version >= 1.1 */
if
(
status
<
100
||
status
>=
200
)
{
vlc_http_msg_destroy
(
resp
);
resp
=
NULL
;
}
error:
vlc_UrlClean
(
&
url
);
return
(
struct
vlc_http_outfile
*
)
resp
;
}
ssize_t
vlc_http_outfile_write
(
struct
vlc_http_outfile
*
f
,
block_t
*
b
)
{
struct
vlc_http_msg
*
msg
=
(
struct
vlc_http_msg
*
)
f
;
return
vlc_http_msg_write
(
msg
,
b
,
false
);
}
int
vlc_http_outfile_close
(
struct
vlc_http_outfile
*
f
)
{
struct
vlc_http_msg
*
msg
=
(
struct
vlc_http_msg
*
)
f
;
int
ret
=
vlc_http_msg_write
(
msg
,
NULL
,
true
);
if
(
ret
<
0
)
{
vlc_http_msg_destroy
(
msg
);
return
-
1
;
}
msg
=
vlc_http_msg_iterate
(
msg
);
if
(
msg
==
NULL
)
return
-
1
;
int
status
=
vlc_http_msg_get_status
(
msg
);
/* TODO: store cookies? */
vlc_http_msg_destroy
(
msg
);
return
(
status
>=
200
&&
status
<
300
)
?
0
:
-
1
;
}
This diff is collapsed.
Click to expand it.
modules/access/http/outfile.h
0 → 100644
+
53
−
0
View file @
d1edc1db
/*****************************************************************************
* outfile.h: HTTP write-only file
*****************************************************************************
* Copyright (C) 2015, 2020 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include
<stdint.h>
/**
* \defgroup http_outfile Output files
* HTTP write-only files
* \ingroup http
* @{
*/
struct
vlc_http_mgr
;
struct
vlc_http_outfile
;
struct
block_t
;
/**
* Creates an HTTP output file.
*
* @param url URL of the file to write
* @param ua user-agent string (NULL to ignore)
* @param user username for authentication (NULL to skip)
* @param pwd password for authentication (NULL to skip)
*
* @return an HTTP resource object pointer, or NULL on error
*/
struct
vlc_http_outfile
*
vlc_http_outfile_create
(
struct
vlc_http_mgr
*
mgr
,
const
char
*
url
,
const
char
*
ua
,
const
char
*
user
,
const
char
*
pwd
);
/**
* Writes data.
*/
ssize_t
vlc_http_outfile_write
(
struct
vlc_http_outfile
*
,
block_t
*
b
);
int
vlc_http_outfile_close
(
struct
vlc_http_outfile
*
);
/** @} */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment