gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ./ChangeLog server/StreamProvider.cpp


From: Sandro Santilli
Subject: [Gnash-commit] gnash ./ChangeLog server/StreamProvider.cpp
Date: Wed, 17 May 2006 11:05:10 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Branch:         
Changes by:     Sandro Santilli <address@hidden>        06/05/17 11:05:10

Modified files:
        .              : ChangeLog 
        server         : StreamProvider.cpp 

Log message:
        * server/StreamProvider.cpp: added temporary support for
        prompting user about Grant/Bock of URL accesses. If input
        is not a terminal default to allow from all.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/ChangeLog.diff?tr1=1.348&tr2=1.349&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/gnash/gnash/server/StreamProvider.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gnash/ChangeLog
diff -u gnash/ChangeLog:1.348 gnash/ChangeLog:1.349
--- gnash/ChangeLog:1.348       Wed May 17 09:47:15 2006
+++ gnash/ChangeLog     Wed May 17 11:05:09 2006
@@ -1,5 +1,8 @@
 2006-05-17 Sandro Santilli <address@hidden>
        
+       * server/StreamProvider.cpp: added temporary support for
+       prompting user about Grant/Bock of URL accesses. If input
+       is not a terminal default to allow from all.
        * backend/gtksup.h: fixed preprocessor instructions comments
        * gui/gnash.cpp: fixed handling of -h flag (force exit 
        after printing usage string); added comments to
Index: gnash/server/StreamProvider.cpp
diff -u gnash/server/StreamProvider.cpp:1.1 gnash/server/StreamProvider.cpp:1.2
--- gnash/server/StreamProvider.cpp:1.1 Tue May 16 13:56:56 2006
+++ gnash/server/StreamProvider.cpp     Wed May 17 11:05:09 2006
@@ -55,10 +55,114 @@
 
 // temporary use of console for confirm load of network urls
 #include <iostream>
+#include <unistd.h>
+#include <cstdio>
+#include <map>
+#include <string>
 
 namespace gnash
 {
 
+// stuff for an URLAccessManager
+namespace URLAccessManager {
+
+/// Possible access policies for URLs
+enum AccessPolicy {    
+
+       /// Forbid access 
+       BLOCK,
+
+       /// Allow access
+       GRANT
+};
+
+const char*
+accessPolicyString(AccessPolicy policy)
+{
+       switch(policy)
+       {
+               case BLOCK:
+                       return "BLOCKED";
+               case GRANT:
+                       return "GRANTED";
+               default:
+                       return "UNKNOWN";
+       }
+}
+
+/// The default AccessPolicy when prompting user is not possible
+/// (this happens when input is not a tty, at the moment)
+static AccessPolicy defaultAccessPolicy = GRANT;
+
+/// A cache of AccessPolicy defined for URLs
+typedef std::map< std::string, AccessPolicy > AccessPolicyCache;
+
+/// A global AccessPolicyCache
+static AccessPolicyCache policyCache;
+
+
+/// Is access allowed to given url ?
+/// This function uses the global AccessPolicyCache
+/// so once a policy is defined for an url it will
+/// be remembered for the whole run.
+///
+/// Prompts the user on the tty. If inut is not a tty
+/// uses the global defaultAccessPolicy.
+///
+bool
+allow(std::string& url)
+{
+       // Look in cached policy first
+       AccessPolicyCache::iterator it = policyCache.find(url);
+       if ( it != policyCache.end() )
+       {
+               log_msg("%s access to %s (cached).\n",
+                       accessPolicyString(it->second),
+                       url.c_str());
+
+               return ( it->second == GRANT );
+       }
+
+       if ( ! isatty(fileno(stdin)) )
+       {
+               log_msg("%s access to %s (input is not a terminal).\n",
+                       accessPolicyString(defaultAccessPolicy),
+                       url.c_str());
+
+               // If we can't prompt user return default policy
+               return ( defaultAccessPolicy == GRANT );
+       }
+
+       /// I still don't like this method, typing just
+       /// a newline doesn't spit another prompt
+       std::string yesno;
+       do {
+               std::cout << "Attempt to access url " << url << std::endl;
+               std::cout << "Block it [yes/no] ? "; 
+               std::cin >> yesno;
+       } while (yesno != "yes" && yesno != "no");
+
+       AccessPolicy userChoice;
+
+       if ( yesno == "yes" ) {
+               userChoice = BLOCK;
+       } else {
+               userChoice = GRANT;
+       }
+
+       // cache for next time
+       policyCache[url] = userChoice;
+       
+       log_msg("%s access to %s (user choice).\n",
+               accessPolicyString(userChoice),
+               url.c_str());
+
+       return userChoice;
+
+}
+
+} // AccessManager
+
 tu_file*
 StreamProvider::getStream(const URL& url)
 {
@@ -80,8 +184,13 @@
        else
        {
 #ifdef USE_CURL
-               log_msg("Loaded url: %s\n", url.str().c_str());
-               return curl_adapter::make_stream(url.str().c_str());
+               std::string url_str = url.str();
+               const char* c_url = url_str.c_str();
+               if ( URLAccessManager::allow(url_str) ) {
+                       return curl_adapter::make_stream(c_url);
+               } else {
+                       return NULL;
+               }
 #else
                log_error("Unsupported network connections");
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]