1 /*****************************************************************************
2 * netconf.c : Network configuration
3 *****************************************************************************
4 * Copyright (C) 2013 RĂ©mi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program 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 Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
29 #include <sys/types.h>
35 extern char **environ
;
37 #include <vlc_common.h>
39 #include <vlc_network.h>
42 * Determines the network proxy server to use (if any).
43 * @param url absolute URL for which to get the proxy server
44 * @return proxy URL, NULL if no proxy or error
46 char *vlc_getProxyUrl(const char *url
)
50 posix_spawn_file_actions_t actions
;
51 posix_spawnattr_t attr
;
52 char *argv
[3] = { (char *)"proxy", (char *)url
, NULL
};
58 posix_spawn_file_actions_init(&actions
);
59 posix_spawn_file_actions_addopen(&actions
, STDIN_FILENO
, "/dev/null",
61 posix_spawn_file_actions_adddup2(&actions
, fd
[1], STDOUT_FILENO
);
63 posix_spawnattr_init(&attr
);
68 posix_spawnattr_setsigmask(&attr
, &set
);
69 sigaddset (&set
, SIGPIPE
);
70 posix_spawnattr_setsigdefault(&attr
, &set
);
71 posix_spawnattr_setflags(&attr
, POSIX_SPAWN_SETSIGDEF
72 | POSIX_SPAWN_SETSIGMASK
);
75 if (posix_spawnp(&pid
, "proxy", &actions
, &attr
, argv
, environ
))
78 posix_spawnattr_destroy(&attr
);
79 posix_spawn_file_actions_destroy(&actions
);
89 ssize_t val
= read(fd
[0], buf
+ len
, sizeof (buf
) - len
);
94 while (len
< sizeof (buf
));
97 while (waitpid(pid
, &(int){ 0 }, 0) == -1);
99 if (len
>= 9 && !strncasecmp(buf
, "direct://", 9))
102 char *end
= memchr(buf
, '\n', len
);
108 /* Parse error: fallback (may be due to missing executable) */
113 /* Fallback to environment variable */
114 char *var
= getenv("http_proxy");