xine-lib  1.2.10
http_helper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2019 the xine project
3  *
4  * This file is part of xine, a free video player.
5  *
6  * xine is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * xine 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 General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19  *
20  * URL helper functions
21  */
22 
23 #ifndef HTTP_HELPER_H
24 #define HTTP_HELPER_H
25 
26 #include <xine/attributes.h>
27 #include <xine/xine_internal.h>
28 
29 /*
30  * user agent finder, using modified protcol names
31  * {proto}://...
32  * e.g. "qthttp://example.com/foo.mov" → "QuickTime"
33  *
34  * return:
35  * NULL or user agent prefix
36  */
37 const char *_x_url_user_agent (const char *url);
38 
39 /*
40  * url parser
41  * {proto}://{user}:{password}@{host}:{port}{uri}
42  * {proto}://{user}:{password}@{[host]}:{port}{uri}
43  *
44  * return:
45  * 0 invalid url
46  * 1 valid url
47  */
48 
49 typedef struct {
50  const char *proto;
51  const char *host;
52  int port;
53  const char *path;
54  const char *args;
55  const char *uri; /* <path>[?<args>] */
56  const char *user;
57  const char *password;
58  char *buf;
59 } xine_url_t;
60 
61 void _x_url_init (xine_url_t *url);
62 int _x_url_parse2 (const char *mrl, xine_url_t *url);
63 void _x_url_cleanup (xine_url_t *);
64 
72 size_t _x_merge_mrl (char *dest, size_t dsize, const char *base_mrl, const char *new_mrl);
73 
74 /*
75  * canonicalise url, given base
76  * base must be valid according to _x_parse_url
77  * url may only contain "://" if it's absolute
78  *
79  * return:
80  * the canonicalised URL (caller must free() it)
81  * NULL if error
82  */
83 static inline XINE_MALLOC char *_x_canonicalise_url (const char *base, const char *url) {
84 
85  size_t base_length;
86  char *cut;
87 
88  if ((cut = strstr (url, "://")))
89  return strdup (url);
90 
91  cut = strstr (base, "://");
92  _x_assert(cut); /* base is required to be valid according to _x_parse_url */
93 
94  if (url[0] == '/') {
95  /* absolute - base up to first '/' after "://", then url */
96  cut = cut ? strchr (cut + 3, '/') : NULL;
97  }
98  else {
99  /* relative - base up to & inc. last '/', then url */
100  cut = cut ? strrchr (cut, '/') : NULL;
101  if (cut)
102  ++cut;
103  }
104  base_length = cut ? (size_t)(cut - base) : strlen (base);
105 
106  return _x_asprintf ("%.*s%s", (int)base_length, base, url);
107 }
108 
109 #endif /* HTTP_HELPER_H */
110 
http_helper.h
XINE_MALLOC
#define XINE_MALLOC
Definition: attributes.h:139
mrlp_t::args_stop
uint32_t args_stop
Definition: http_helper.c:151
mrlp_t::user_start
uint32_t user_start
Definition: http_helper.c:147
mrlp_t::prot_start
uint32_t prot_start
Definition: http_helper.c:146
mrlp_t::port
uint32_t port
Definition: http_helper.c:153
_x_canonicalise_url
static char * _x_canonicalise_url(const char *base, const char *url)
Definition: http_helper.h:83
tab_esclen
static const uint8_t tab_esclen[256]
Definition: http_helper.c:70
xine_url_t::user
const char * user
Definition: http_helper.h:56
_x_merge_mrl
size_t _x_merge_mrl(char *dest, size_t dsize, const char *base_mrl, const char *new_mrl)
merge a new, possibly relative mrl with a given base. result will always be 0 terminated.
Definition: http_helper.c:394
mrlp_t::info_stop
uint32_t info_stop
Definition: http_helper.c:152
mrlp_t::host_start
uint32_t host_start
Definition: http_helper.c:149
xine_url_t
Definition: http_helper.h:49
_x_url_init
void _x_url_init(xine_url_t *url)
Definition: http_helper.c:356
_x_url_user_agent
const char * _x_url_user_agent(const char *url)
Definition: http_helper.c:495
_x_url_cleanup
void _x_url_cleanup(xine_url_t *url)
Definition: http_helper.c:374
_x_url_init
void _x_url_init(xine_url_t *url)
Definition: http_helper.c:356
tab_hex
static const uint8_t tab_hex[16]
Definition: http_helper.c:89
attributes.h
xine_url_t::password
const char * password
Definition: http_helper.h:57
mrlp_t::path_stop
uint32_t path_stop
Definition: http_helper.c:150
NULL
NULL
Definition: xine_plugin.c:78
tab_type
static const uint8_t tab_type[256]
Definition: http_helper.c:126
mrlp_t::prot_stop
uint32_t prot_stop
Definition: http_helper.c:146
_x_assert
#define _x_assert(exp)
Definition: xineutils.h:550
_x_url_parse2
int _x_url_parse2(const char *mrl, xine_url_t *url)
Definition: http_helper.c:156
mrlp_t::args_start
uint32_t args_start
Definition: http_helper.c:151
_x_url_parse2
int _x_url_parse2(const char *mrl, xine_url_t *url)
Definition: http_helper.c:156
xine_url_t::path
const char * path
Definition: http_helper.h:53
xine_url_t::proto
const char * proto
Definition: http_helper.h:50
_x_url_user_agent
const char * _x_url_user_agent(const char *url)
Definition: http_helper.c:495
xine_url_t::host
const char * host
Definition: http_helper.h:51
xine_url_t::buf
char * buf
Definition: http_helper.h:58
unescape
static void unescape(char **d, const char *s, size_t len)
Definition: http_helper.c:53
mrlp_t::pass_stop
uint32_t pass_stop
Definition: http_helper.c:148
_x_merge_mrl
size_t _x_merge_mrl(char *dest, size_t dsize, const char *base_mrl, const char *new_mrl)
merge a new, possibly relative mrl with a given base. result will always be 0 terminated.
Definition: http_helper.c:394
mrlp_t
Definition: http_helper.c:145
mrlp_t::user_stop
uint32_t user_stop
Definition: http_helper.c:147
esclen
static size_t esclen(const char *s, size_t len)
Definition: http_helper.c:91
xine_internal.h
mrlp_t::host_stop
uint32_t host_stop
Definition: http_helper.c:149
config.h
xine_url_t::args
const char * args
Definition: http_helper.h:54
xine_url_t::uri
const char * uri
Definition: http_helper.h:55
mrlp_t::path_start
uint32_t path_start
Definition: http_helper.c:150
xine_url_t::port
int port
Definition: http_helper.h:52
escape
static void escape(char **d, const char *s, size_t len)
Definition: http_helper.c:99
_x_asprintf
char * _x_asprintf(const char *format,...)
Definition: utils.c:783
tab_unhex
static const int8_t tab_unhex[256]
Definition: http_helper.c:34
mrlp_t::pass_start
uint32_t pass_start
Definition: http_helper.c:148
_x_url_cleanup
void _x_url_cleanup(xine_url_t *)
Definition: http_helper.c:374
mrlp_t::info_start
uint32_t info_start
Definition: http_helper.c:152