bool RequestURI::process(const VirtualHost *vhost, Transport *transport, const string &sourceRoot, const string &pathTranslation, const char *url) { splitURL(url, m_originalURL, m_queryString); m_originalURL = StringUtil::UrlDecode(m_originalURL, false); m_rewritten = false; // Fast path for files that exist if (vhost->checkExistenceBeforeRewrite()) { String canon( Util::canonicalize(m_originalURL.c_str(), m_originalURL.size()), AttachString); if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) { m_rewrittenURL = canon; m_resolvedURL = canon; return true; } } if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) { // Redirection m_done = true; return true; } if (!resolveURL(vhost, pathTranslation, sourceRoot)) { // Can't find return false; } return true; }
bool RequestURI::process(const VirtualHost *vhost, Transport *transport, const string &sourceRoot, const string &pathTranslation, const char *url) { splitURL(url, m_originalURL, m_queryString); m_originalURL = StringUtil::UrlDecode(m_originalURL, false); // Fast path for files that exist String canon = Util::canonicalize(string(m_originalURL.c_str(), m_originalURL.size())); String relUrl(canon.charAt(0) == '/' ? canon.substr(1) : canon); if (virtualFileExists(vhost, sourceRoot, pathTranslation, relUrl)) { m_rewrittenURL = relUrl; m_resolvedURL = relUrl; PrependSlash(m_resolvedURL); return true; } if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) { // Redirection m_done = true; return true; } if (!resolveURL(vhost, pathTranslation, sourceRoot)) { // Can't find return false; } return true; }
bool RequestURI::process(const VirtualHost *vhost, Transport *transport, const string &sourceRoot, const string &pathTranslation, const char *url) { splitURL(url, m_originalURL, m_queryString); m_originalURL = StringUtil::UrlDecode(m_originalURL, false); m_rewritten = false; // Fast path for files that exist unless VirtualHost option StaticFastPath is false, in // which case rewrite rules are applied even if the original path points to an existing static file. String canon(Util::canonicalize(m_originalURL.c_str(), m_originalURL.size()), AttachString); if ( vhost->staticfastpath() ) { if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) { m_rewrittenURL = canon; m_resolvedURL = canon; return true; } } if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) { // Redirection m_done = true; return true; } if (!resolveURL(vhost, pathTranslation, sourceRoot)) { // Can't find return false; } return true; }
bool RequestURI::process(const VirtualHost *vhost, Transport *transport, const std::string &sourceRoot, const std::string &pathTranslation, const char *url) { splitURL(url, m_originalURL, m_queryString); m_originalURL = StringUtil::UrlDecode(m_originalURL, false); m_rewritten = false; auto scriptFilename = transport->getScriptFilename(); if (!scriptFilename.empty()) { // The transport is overriding everything and just handing us the filename m_originalURL = scriptFilename; if (!resolveURL(vhost, pathTranslation, sourceRoot)) { return false; } if (m_origPathInfo.empty()) { // PATH_INFO wasn't filled by resolveURL() because m_originalURL // didn't contain it. We set it now, based on PATH_TRANSLATED. m_origPathInfo = transport->getPathTranslated(); if (!m_origPathInfo.empty() && m_origPathInfo.charAt(0) != '/') { m_origPathInfo = "/" + m_origPathInfo; } } if (transport->isPathInfoSet()) { m_pathInfo =transport->getPathInfo(); } else { m_pathInfo = m_origPathInfo; } return true; } // Fast path for files that exist if (vhost->checkExistenceBeforeRewrite()) { String canon = FileUtil::canonicalize(m_originalURL); if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) { m_rewrittenURL = canon; m_resolvedURL = canon; return true; } } if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) { // Redirection m_done = true; return true; } if (!resolveURL(vhost, pathTranslation, sourceRoot)) { // Can't find return false; } return true; }
bool RequestURI::process(const VirtualHost *vhost, Transport *transport, const std::string &sourceRoot, const std::string &pathTranslation, const char *url) { splitURL(url, m_originalURL, m_queryString); m_originalURL = StringUtil::UrlDecode(m_originalURL, false); m_rewritten = false; auto pathTranslated = transport->getPathTranslated(); if (!pathTranslated.empty()) { // The transport is overriding everything and just handing us the filename m_path = m_absolutePath = pathTranslated; processExt(); return true; } // Fast path for files that exist if (vhost->checkExistenceBeforeRewrite()) { String canon( Util::canonicalize(m_originalURL.c_str(), m_originalURL.size()), AttachString); if (virtualFileExists(vhost, sourceRoot, pathTranslation, canon)) { m_rewrittenURL = canon; m_resolvedURL = canon; return true; } } if (!rewriteURL(vhost, transport, pathTranslation, sourceRoot)) { // Redirection m_done = true; return true; } if (!resolveURL(vhost, pathTranslation, sourceRoot)) { // Can't find return false; } return true; }
PRIVATE void processRSSList(auto_handle *session, CURL *curl_session, const simple_list items, const rss_feed * feed) { simple_list current_item = items; HTTPResponse *torrent = NULL; char fname[MAXPATHLEN]; char *download_folder = NULL; char *feedID = NULL; char *download_url = NULL; if(!curl_session && !session) { printf("curl_session == NULL && session == NULL\n"); abort(); } if(feed != NULL) { feedID = feed->id; } while(current_item && current_item->data) { feed_item item = (feed_item)current_item->data; if(isMatch(session->filters, item->name, feedID, &download_folder)) { if(!session->match_only) { if(has_been_downloaded(session->downloads, item)) { dbg_printf(P_INFO, "Duplicate torrent: %s", item->name); } else { int8_t result = -1; dbg_printft(P_MSG, "[%s] Found new download: %s (%s)", feedID, item->name, item->url); if(isMagnetURI(item->url)) { result = addMagnetToTM(session, item->url, download_folder); } else { // It's a torrent file // Rewrite torrent URL, if necessary if((feed != NULL) && (feed->url_pattern != NULL) && (feed->url_replace != NULL)) { download_url = rewriteURL(item->url, feed->url_pattern, feed->url_replace); } torrent = downloadTorrent(curl_session, download_url != NULL ? download_url : item->url); if(torrent) { get_filename(fname, torrent->content_filename, item->url, session->torrent_folder); /* add torrent to Transmission */ result = addTorrentToTM(session, torrent->data, torrent->size, fname, download_folder); HTTPResponse_free(torrent); } am_free(download_url); } // process result if( result >= 0) { //result == 0 -> duplicate torrent if(result > 0) { //torrent was added if(session->prowl_key_valid) { prowl_sendNotification(PROWL_NEW_DOWNLOAD, session->prowl_key, item->name); } if(session->toasty_key) { toasty_sendNotification(PROWL_NEW_DOWNLOAD, session->toasty_key, item->name); } if(session->pushalot_key) { pushalot_sendNotification(PUSHALOT_NEW_DOWNLOAD, session->pushalot_key, item->name); } if(session->pushover_key) { pushover_sendNotification(PUSHOVER_NEW_DOWNLOAD, session->pushover_key, item->name); } } /* add url to bucket list */ result = addToBucket(item->guid != NULL ? item->guid : item->url, &session->downloads, session->max_bucket_items); if (result == 0) { session->bucket_changed = 1; save_state(session->statefile, session->downloads); } } else { //an error occurred if(session->prowl_key_valid) { prowl_sendNotification(PROWL_DOWNLOAD_FAILED, session->prowl_key, item->name); } if(session->toasty_key) { toasty_sendNotification(PROWL_DOWNLOAD_FAILED, session->toasty_key, item->name); } if(session->pushalot_key) { pushalot_sendNotification(PUSHALOT_DOWNLOAD_FAILED, session->pushalot_key, item->name); } if(session->pushover_key) { pushover_sendNotification(PUSHOVER_DOWNLOAD_FAILED, session->pushover_key, item->name); } } } } else { dbg_printft(P_MSG, "[%s] Match: %s (%s)", feedID, item->name, item->url); } } current_item = current_item->next; } }