abyss_bool auth_hook(TSession * r) { char *domain_name, *e; abyss_bool ret = FALSE; if (!strncmp(r->requestInfo.uri, "/domains/", 9)) { domain_name = strdup(r->requestInfo.uri + 9); switch_assert(domain_name); if ((e = strchr(domain_name, '/'))) { *e++ = '\0'; } if (!strcmp(domain_name, "this")) { free(domain_name); domain_name = strdup(r->requestInfo.host); } ret = !http_directory_auth(r, domain_name); free(domain_name); } else { char tmp[512]; const char *list[2] = { "index.html", "index.txt" }; int x; if (!strncmp(r->requestInfo.uri, "/pub", 4)) { char *p = (char *) r->requestInfo.uri; char *new_uri = p + 4; if (!new_uri) { new_uri = "/"; } switch_snprintf(tmp, sizeof(tmp), "%s%s", SWITCH_GLOBAL_dirs.htdocs_dir, new_uri); if (switch_directory_exists(tmp, NULL) == SWITCH_STATUS_SUCCESS) { for (x = 0; x < 2; x++) { switch_snprintf(tmp, sizeof(tmp), "%s%s%s%s", SWITCH_GLOBAL_dirs.htdocs_dir, new_uri, end_of(new_uri) == *SWITCH_PATH_SEPARATOR ? "" : SWITCH_PATH_SEPARATOR, list[x] ); if (switch_file_exists(tmp, NULL) == SWITCH_STATUS_SUCCESS) { switch_snprintf(tmp, sizeof(tmp), "%s%s%s", new_uri, end_of(new_uri) == '/' ? "" : "/", list[x] ); new_uri = tmp; break; } } } r->requestInfo.uri = strdup(new_uri); free(p); } else { if (globals.realm && strncmp(r->requestInfo.uri, "/pub", 4)) { ret = !http_directory_auth(r, NULL); } } } return ret; }
abyss_bool auth_hook(TSession * r) { char *domain_name, *e; abyss_bool ret = FALSE; if (globals.enable_websocket && !strncmp(r->requestInfo.uri, "/socket", 7)) { // Chrome has no Authorization support yet // https://code.google.com/p/chromium/issues/detail?id=123862 return websocket_hook(r); } if (!strncmp(r->requestInfo.uri, "/portal", 7) && strlen(r->requestInfo.uri) <= 8) { ResponseAddField(r, "Location", "/portal/index.html"); ResponseStatus(r, 302); return TRUE; } if (!strncmp(r->requestInfo.uri, "/domains/", 9)) { domain_name = strdup(r->requestInfo.uri + 9); switch_assert(domain_name); if ((e = strchr(domain_name, '/'))) { *e++ = '\0'; } if (!strcmp(domain_name, "this")) { free(domain_name); domain_name = strdup(r->requestInfo.host); } ret = !http_directory_auth(r, domain_name); free(domain_name); } else { char tmp[512]; const char *list[2] = { "index.html", "index.txt" }; int x; if (!strncmp(r->requestInfo.uri, "/pub", 4)) { char *p = (char *) r->requestInfo.uri; char *new_uri = p + 4; if (!new_uri) { new_uri = "/"; } switch_snprintf(tmp, sizeof(tmp), "%s%s", SWITCH_GLOBAL_dirs.htdocs_dir, new_uri); if (switch_directory_exists(tmp, NULL) == SWITCH_STATUS_SUCCESS) { for (x = 0; x < 2; x++) { switch_snprintf(tmp, sizeof(tmp), "%s%s%s%s", SWITCH_GLOBAL_dirs.htdocs_dir, new_uri, end_of(new_uri) == *SWITCH_PATH_SEPARATOR ? "" : SWITCH_PATH_SEPARATOR, list[x] ); if (switch_file_exists(tmp, NULL) == SWITCH_STATUS_SUCCESS) { switch_snprintf(tmp, sizeof(tmp), "%s%s%s", new_uri, end_of(new_uri) == '/' ? "" : "/", list[x] ); new_uri = tmp; break; } } } r->requestInfo.uri = strdup(new_uri); free(p); } else { if (globals.realm && strncmp(r->requestInfo.uri, "/pub", 4)) { ret = !http_directory_auth(r, NULL); } } } return ret; }