summaryrefslogtreecommitdiffstats
path: root/core/m_option.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/m_option.c')
-rw-r--r--core/m_option.c222
1 files changed, 0 insertions, 222 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,
-};