summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-08-02 17:02:34 +0200
committerwm4 <wm4@nowhere>2013-08-02 17:02:34 +0200
commitbc1d61cf4296ab41564adb896e454e48c292e451 (patch)
tree461dfa0cb61af73b62838608aa8fbb3dd99d3642 /core
parent964194b55bf86d7c8b76febe8bf54c49648e79c1 (diff)
downloadmpv-bc1d61cf4296ab41564adb896e454e48c292e451.tar.bz2
mpv-bc1d61cf4296ab41564adb896e454e48c292e451.tar.xz
stream: redo URL parsing, replace m_struct usage with m_config
Move the URL parsing code from m_option.c to stream.c, and simplify it dramatically. This code originates from times when http code used this, but now it's just relict from other stream implementations reusing this code. Remove the unused bits and simplify the rest. stream_vcd is insane, and the priv struct is different on every platform, so drop the URL parsing. This means you can't specify a track anymore, only the device. (Does anyone use stream_vcd? Not like this couldn't be fixed, but it doesn't seem worth the effort, especially because it'd require potentially touching platform specific code.)
Diffstat (limited to 'core')
-rw-r--r--core/m_option.c222
-rw-r--r--core/m_option.h7
2 files changed, 0 insertions, 229 deletions
diff --git a/core/m_option.c b/core/m_option.c
index abcb13c038..33da609fdd 100644
--- a/core/m_option.c
+++ b/core/m_option.c
@@ -2407,225 +2407,3 @@ const m_option_type_t m_option_type_obj_settings_list = {
.copy = copy_obj_settings_list,
.free = free_obj_settings_list,
};
-
-
-/* Replace escape sequences in an URL (or a part of an URL) */
-/* works like strcpy(), but without return argument,
- except that outbuf == inbuf is allowed */
-static void url_unescape_string(char *outbuf, const char *inbuf)
-{
- unsigned char c,c1,c2;
- int i,len=strlen(inbuf);
- for (i=0;i<len;i++) {
- c = inbuf[i];
- if (c == '%' && i<len-2) { //must have 2 more chars
- c1 = toupper(inbuf[i+1]); // we need uppercase characters
- c2 = toupper(inbuf[i+2]);
- if (((c1>='0' && c1<='9') || (c1>='A' && c1<='F')) &&
- ((c2>='0' && c2<='9') || (c2>='A' && c2<='F')) )
- {
- if (c1>='0' && c1<='9')
- c1-='0';
- else
- c1-='A'-10;
- if (c2>='0' && c2<='9')
- c2-='0';
- else
- c2-='A'-10;
- c = (c1<<4) + c2;
- i=i+2; //only skip next 2 chars if valid esc
- }
- }
- *outbuf++ = c;
- }
- *outbuf++='\0'; //add nullterm to string
-}
-
-static int parse_custom_url(const m_option_t *opt, struct bstr name,
- struct bstr url, void *dst)
-{
- int r;
- m_struct_t *desc = opt->priv;
-
- if (!desc) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %.*s: Custom URL needs "
- "a pointer to a m_struct_t in the priv field.\n", BSTR_P(name));
- return M_OPT_PARSER_ERR;
- }
-
- // extract the protocol
- int idx = bstr_find0(url, "://");
- if (idx < 0) {
- // Filename only
- if (m_option_list_find(desc->fields, "filename")) {
- m_struct_set(desc, dst, "filename", url);
- return 1;
- }
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: URL doesn't have a valid protocol!\n",
- BSTR_P(name));
- return M_OPT_INVALID;
- }
- struct bstr ptr1 = bstr_cut(url, idx + 3);
- if (m_option_list_find(desc->fields, "string")) {
- if (ptr1.len > 0) {
- m_struct_set(desc, dst, "string", ptr1);
- return 1;
- }
- }
- if (dst && m_option_list_find(desc->fields, "protocol")) {
- r = m_struct_set(desc, dst, "protocol", bstr_splice(url, 0, idx));
- if (r < 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: Error while setting protocol.\n",
- BSTR_P(name));
- return r;
- }
- }
-
- // check if a username:password is given
- idx = bstrchr(ptr1, '/');
- if (idx < 0)
- idx = ptr1.len;
- struct bstr hostpart = bstr_splice(ptr1, 0, idx);
- struct bstr path = bstr_cut(ptr1, idx);
- idx = bstrchr(hostpart, '@');
- if (idx >= 0) {
- struct bstr userpass = bstr_splice(hostpart, 0, idx);
- hostpart = bstr_cut(hostpart, idx + 1);
- // We got something, at least a username...
- if (!m_option_list_find(desc->fields, "username")) {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Option %.*s: This URL doesn't have a username part.\n",
- BSTR_P(name));
- // skip
- } else {
- idx = bstrchr(userpass, ':');
- if (idx >= 0) {
- // We also have a password
- if (!m_option_list_find(desc->fields, "password")) {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Option %.*s: This URL doesn't have a password part.\n",
- BSTR_P(name));
- // skip
- } else { // Username and password
- if (dst) {
- r = m_struct_set(desc, dst, "username",
- bstr_splice(userpass, 0, idx));
- if (r < 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: Error while setting username.\n",
- BSTR_P(name));
- return r;
- }
- r = m_struct_set(desc, dst, "password",
- bstr_splice(userpass, idx+1,
- userpass.len));
- if (r < 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: Error while setting password.\n",
- BSTR_P(name));
- return r;
- }
- }
- }
- } else { // User name only
- r = m_struct_set(desc, dst, "username", userpass);
- if (r < 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: Error while setting username.\n",
- BSTR_P(name));
- return r;
- }
- }
- }
- }
-
- // Before looking for a port number check if we have an IPv6 type
- // numeric address.
- // In an IPv6 URL the numeric address should be inside square braces.
- int idx1 = bstrchr(hostpart, '[');
- int idx2 = bstrchr(hostpart, ']');
- struct bstr portstr = hostpart;
- bool v6addr = false;
- if (idx1 >= 0 && idx2 >= 0 && idx1 < idx2) {
- // we have an IPv6 numeric address
- portstr = bstr_cut(hostpart, idx2);
- hostpart = bstr_splice(hostpart, idx1 + 1, idx2);
- v6addr = true;
- }
-
- idx = bstrchr(portstr, ':');
- if (idx >= 0) {
- if (!v6addr)
- hostpart = bstr_splice(hostpart, 0, idx);
- // We have an URL beginning like http://www.hostname.com:1212
- // Get the port number
- if (!m_option_list_find(desc->fields, "port")) {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Option %.*s: This URL doesn't have a port part.\n",
- BSTR_P(name));
- // skip
- } else {
- if (dst) {
- int p = bstrtoll(bstr_cut(portstr, idx + 1), NULL, 0);
- char tmp[100];
- snprintf(tmp, 99, "%d", p);
- r = m_struct_set(desc, dst, "port", bstr0(tmp));
- if (r < 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: Error while setting port.\n",
- BSTR_P(name));
- return r;
- }
- }
- }
- }
- // Get the hostname
- if (hostpart.len > 0) {
- if (!m_option_list_find(desc->fields, "hostname")) {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Option %.*s: This URL doesn't have a hostname part.\n",
- BSTR_P(name));
- // skip
- } else {
- r = m_struct_set(desc, dst, "hostname", hostpart);
- if (r < 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: Error while setting hostname.\n",
- BSTR_P(name));
- return r;
- }
- }
- }
- // Look if a path is given
- if (path.len > 1) { // not just "/"
- // copy the path/filename in the URL container
- if (!m_option_list_find(desc->fields, "filename")) {
- mp_msg(MSGT_CFGPARSER, MSGL_WARN,
- "Option %.*s: This URL doesn't have a filename part.\n",
- BSTR_P(name));
- // skip
- } else {
- if (dst) {
- char *fname = bstrdup0(NULL, bstr_cut(path, 1));
- url_unescape_string(fname, fname);
- r = m_struct_set(desc, dst, "filename", bstr0(fname));
- talloc_free(fname);
- if (r < 0) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR,
- "Option %.*s: Error while setting filename.\n",
- BSTR_P(name));
- return r;
- }
- }
- }
- }
- return 1;
-}
-
-/// TODO : Write the other needed funcs for 'normal' options
-const m_option_type_t m_option_type_custom_url = {
- .name = "Custom URL",
- .parse = parse_custom_url,
-};
diff --git a/core/m_option.h b/core/m_option.h
index 6d44ce6696..973da4daaa 100644
--- a/core/m_option.h
+++ b/core/m_option.h
@@ -155,12 +155,6 @@ int m_obj_parse_sub_config(struct bstr opt_name, struct bstr name,
struct bstr *pstr, struct m_config *config,
int flags, char ***ret);
-// Parse an URL into a struct.
-/** The option priv field (\ref m_option::priv) must point to a
- * \ref m_struct_st describing which fields of the URL must be used.
- */
-extern const m_option_type_t m_option_type_custom_url;
-
struct m_opt_choice_alternatives {
char *name;
int value;
@@ -193,7 +187,6 @@ struct m_sub_options {
#define CONF_TYPE_FOURCC (&m_option_type_fourcc)
#define CONF_TYPE_AFMT (&m_option_type_afmt)
#define CONF_TYPE_OBJ_SETTINGS_LIST (&m_option_type_obj_settings_list)
-#define CONF_TYPE_CUSTOM_URL (&m_option_type_custom_url)
#define CONF_TYPE_TIME (&m_option_type_time)
#define CONF_TYPE_CHOICE (&m_option_type_choice)
#define CONF_TYPE_INT_PAIR (&m_option_type_intpair)