void WebProcessor::ParseURL() { // remove subfolder "nzbget" from the path (if exists) // http://localhost:6789/nzbget/username:password/jsonrpc -> http://localhost:6789/username:password/jsonrpc if (!strncmp(m_szUrl, "/nzbget/", 8)) { char* sz_OldUrl = m_szUrl; m_szUrl = strdup(m_szUrl + 7); free(sz_OldUrl); } // http://localhost:6789/nzbget -> http://localhost:6789 if (!strcmp(m_szUrl, "/nzbget")) { char szRedirectURL[1024]; snprintf(szRedirectURL, 1024, "%s/", m_szUrl); szRedirectURL[1024-1] = '\0'; SendRedirectResponse(szRedirectURL); return; } // authorization via URL in format: // http://localhost:6789/username:password/jsonrpc char* pauth1 = strchr(m_szUrl + 1, ':'); char* pauth2 = strchr(m_szUrl + 1, '/'); if (pauth1 && pauth1 < pauth2) { char* pstart = m_szUrl + 1; int iLen = 0; char* pend = strchr(pstart + 1, '/'); if (pend) { iLen = (int)(pend - pstart < (int)sizeof(m_szAuthInfo) - 1 ? pend - pstart : (int)sizeof(m_szAuthInfo) - 1); } else { iLen = strlen(pstart); } strncpy(m_szAuthInfo, pstart, iLen); m_szAuthInfo[iLen] = '\0'; char* sz_OldUrl = m_szUrl; m_szUrl = strdup(pend); free(sz_OldUrl); } debug("Final URL=%s", m_szUrl); }
void WebProcessor::ParseUrl() { // remove subfolder "nzbget" from the path (if exists) // http://localhost:6789/nzbget/username:password/jsonrpc -> http://localhost:6789/username:password/jsonrpc if (!strncmp(m_url, "/nzbget/", 8)) { m_url = CString(m_url + 7); } // http://localhost:6789/nzbget -> http://localhost:6789 if (!strcmp(m_url, "/nzbget")) { SendRedirectResponse(BString<1024>("%s/", *m_url)); return; } // authorization via URL in format: // http://localhost:6789/username:password/jsonrpc char* pauth1 = strchr(m_url + 1, ':'); char* pauth2 = strchr(m_url + 1, '/'); if (pauth1 && pauth1 < pauth2) { char* pstart = m_url + 1; int len = 0; char* pend = strchr(pstart + 1, '/'); if (pend) { len = (int)(pend - pstart < (int)sizeof(m_authInfo) - 1 ? pend - pstart : (int)sizeof(m_authInfo) - 1); } else { len = strlen(pstart); } strncpy(m_authInfo, pstart, len); m_authInfo[len] = '\0'; m_url = CString(pend); } debug("Final URL=%s", *m_url); }