static const char httpd_opts[]="c:d:h:"
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
"e:"
#define OPT_INC_1 1
#else
#define OPT_INC_1 0
#endif
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
"r:"
# ifdef CONFIG_FEATURE_HTTPD_AUTH_MD5
"m:"
# define OPT_INC_2 2
# else
# define OPT_INC_2 1
#endif
#else
#define OPT_INC_2 0
#endif
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
"p:v"
#ifdef CONFIG_FEATURE_HTTPD_SETUID
"u:"
#endif
#endif /* CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY */
;
#define OPT_CONFIG_FILE (1<<0)
#define OPT_DECODE_URL (1<<1)
#define OPT_HOME_HTTPD (1<<2)
#define OPT_ENCODE_URL (1<<(2+OPT_INC_1))
#define OPT_REALM (1<<(3+OPT_INC_1))
#define OPT_MD5 (1<<(4+OPT_INC_1))
#define OPT_PORT (1<<(3+OPT_INC_1+OPT_INC_2))
#define OPT_DEBUG (1<<(4+OPT_INC_1+OPT_INC_2))
#define OPT_SETUID (1<<(5+OPT_INC_1+OPT_INC_2))
#ifdef HTTPD_STANDALONE
int main(int argc, char *argv[])
#else
int httpd_main(int argc, char *argv[])
#endif
{
unsigned long opt;
const char *home_httpd = home;
char *url_for_decode;
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
const char *url_for_encode;
#endif
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
const char *s_port;
#endif
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
int server;
#endif
#ifdef CONFIG_FEATURE_HTTPD_SETUID
const char *s_uid;
long uid = -1;
#endif
#ifdef CONFIG_FEATURE_HTTPD_AUTH_MD5
const char *pass;
#endif
config = xcalloc(1, sizeof(*config));
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
config->realm = "Web Server Authentication";
#endif
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
config->port = 80;
#endif
config->ContentLength = -1;
opt = bb_getopt_ulflags(argc, argv, httpd_opts,
&(config->configFile), &url_for_decode, &home_httpd
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
, &url_for_encode
#endif
#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH
, &(config->realm)
# ifdef CONFIG_FEATURE_HTTPD_AUTH_MD5
, &pass
# endif
#endif
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
, &s_port
#ifdef CONFIG_FEATURE_HTTPD_SETUID
, &s_uid
#endif
#endif
);
if(opt & OPT_DECODE_URL) {
printf("%s", decodeString(url_for_decode, 1));
return 0;
}
#ifdef CONFIG_FEATURE_HTTPD_ENCODE_URL_STR
if(opt & OPT_ENCODE_URL) {
printf("%s", encodeString(url_for_encode));
return 0;
}
#endif
#ifdef CONFIG_FEATURE_HTTPD_AUTH_MD5
if(opt & OPT_MD5) {
printf("%s\n", pw_encrypt(pass, "$1$"));
return 0;
}
#endif
#ifndef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY
if(opt & OPT_PORT)
config->port = bb_xgetlarg(s_port, 10, 1, 0xffff);
config->debugHttpd = opt & OPT_DEBUG;
#ifdef CONFIG_FEATURE_HTTPD_SETUID
if(opt & OPT_SETUID) {
char *e;
uid = strtol(s_uid, &e, 0);
if(*e != '\0') {
/* not integer */
uid = my_getpwnam(s_uid);
}
}
#endif
#endif
}
|