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 if (posix_spawn_file_actions_init(&actions
))
60 if (posix_spawn_file_actions_addopen(&actions
, STDIN_FILENO
, "/dev/null",
62 posix_spawn_file_actions_adddup2(&actions
, fd
[1], STDOUT_FILENO
))
64 posix_spawn_file_actions_destroy(&actions
);
68 posix_spawnattr_init(&attr
);
73 posix_spawnattr_setsigmask(&attr
, &set
);
74 sigaddset (&set
, SIGPIPE
);
75 posix_spawnattr_setsigdefault(&attr
, &set
);
76 posix_spawnattr_setflags(&attr
, POSIX_SPAWN_SETSIGDEF
77 | POSIX_SPAWN_SETSIGMASK
);
80 if (posix_spawnp(&pid
, "proxy", &actions
, &attr
, argv
, environ
))
83 posix_spawnattr_destroy(&attr
);
84 posix_spawn_file_actions_destroy(&actions
);
94 ssize_t val
= read(fd
[0], buf
+ len
, sizeof (buf
) - len
);
99 while (len
< sizeof (buf
));
102 while (waitpid(pid
, &(int){ 0 }, 0) == -1);
104 if (len
>= 9 && !strncasecmp(buf
, "direct://", 9))
107 char *end
= memchr(buf
, '\n', len
);
113 /* Parse error: fallback (may be due to missing executable) */
118 /* Fallback to environment variable */
119 char *var
= getenv("http_proxy");