xine-lib 1.2.11
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 */
37const 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
49typedef 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;
60
61void _x_url_init (xine_url_t *url);
62int _x_url_parse2 (const char *mrl, xine_url_t *url);
64
72size_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 */
83static 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
const char * _x_url_user_agent(const char *url)
Definition: http_helper.c:497
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:396
void _x_url_cleanup(xine_url_t *)
Definition: http_helper.c:376
static char * _x_canonicalise_url(const char *base, const char *url)
Definition: http_helper.h:83
void _x_url_init(xine_url_t *url)
Definition: http_helper.c:358
int _x_url_parse2(const char *mrl, xine_url_t *url)
Definition: http_helper.c:158
#define XINE_MALLOC
Definition: attributes.h:141
Definition: http_helper.h:49
const char * password
Definition: http_helper.h:57
const char * host
Definition: http_helper.h:51
const char * uri
Definition: http_helper.h:55
const char * proto
Definition: http_helper.h:50
const char * path
Definition: http_helper.h:53
const char * user
Definition: http_helper.h:56
char * buf
Definition: http_helper.h:58
int port
Definition: http_helper.h:52
const char * args
Definition: http_helper.h:54
char * _x_asprintf(const char *format,...)
Definition: utils.c:783
NULL
Definition: xine_plugin.c:78
#define _x_assert(exp)
Definition: xineutils.h:559