[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xine-cvslog
Subject:    [xine-cvs] CVS: xine-lib/src/input http_helper.h,1.1,1.2 input_http.c,1.83,1.84
From:       Frantisek Dvorak <valtri () users ! sourceforge ! net>
Date:       2004-03-31 7:42:53
Message-ID: E1B8aNB-000101-Lh () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/xine/xine-lib/src/input
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3798/src/input

Modified Files:
	http_helper.h input_http.c 
Log Message:
New config option - list of domains without proxy.
Add help strings into HTTP proxy options.


Index: http_helper.h
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/input/http_helper.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- http_helper.h	26 Nov 2003 08:09:58 -0000	1.1
+++ http_helper.h	31 Mar 2004 07:42:50 -0000	1.2
@@ -22,6 +22,9 @@
  * $Id$ 
  */
 
+#ifndef HTTP_HELPER_H
+#define HTTP_HELPER_H
+
 /*
  * url parser
  * {proto}://{user}:{password}@{host}:{port}{uri}
@@ -31,8 +34,7 @@
  *   0  invalid url
  *   1  valid url
  */
-#ifndef HTTP_HELPER_H
-#define HTTP_HELPER_H
 int _x_parse_url (char *url, char **proto, char** host, int *port,
                   char **user, char **password, char **uri);
+
 #endif /* HTTP_HELPER_H */

Index: input_http.c
===================================================================
RCS file: /cvsroot/xine/xine-lib/src/input/input_http.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- input_http.c	15 Feb 2004 20:31:23 -0000	1.83
+++ input_http.c	31 Mar 2004 07:42:50 -0000	1.84
@@ -35,7 +35,6 @@
 #include <netinet/in.h>
 
 #ifndef WIN32
-#include <arpa/inet.h>
 #include <netdb.h>
 #include <errno.h>
 #endif /* WIN32 */
@@ -106,42 +105,90 @@
   xine_t           *xine;
   config_values_t  *config;
 
-  char             *proxyuser;
-  char             *proxypassword;
   char             *proxyhost;
   int               proxyport;
+  char             *proxyuser;
+  char             *proxypassword;
+  char             *noproxylist;
 
   char             *proxyhost_env;
   int               proxyport_env;
 } http_input_class_t;
 
-static void proxy_user_change_cb(void *data, xine_cfg_entry_t *cfg) {
-  http_input_class_t *this = (http_input_class_t *) data;
+static void proxy_host_change_cb (void *this_gen, xine_cfg_entry_t *cfg) {
+  http_input_class_t *this = (http_input_class_t *)this_gen;
+
+  this->proxyhost = cfg->str_value;
+
+  if(this->proxyhost && (!strlen(this->proxyhost)) && this->proxyhost_env) {
+    this->proxyhost = this->proxyhost_env;
+    this->proxyport = this->proxyport_env;
+  }
+}
+
+static void proxy_port_change_cb(void *this_gen, xine_cfg_entry_t *cfg) {
+  http_input_class_t *this = (http_input_class_t *)this_gen;
+  
+  this->proxyport = cfg->num_value;
+}
+
+static void proxy_user_change_cb(void *this_gen, xine_cfg_entry_t *cfg) {
+  http_input_class_t *this = (http_input_class_t *)this_gen;
 
   this->proxyuser = cfg->str_value;
 }
 
-static void proxy_password_change_cb(void *data, xine_cfg_entry_t *cfg) {
-  http_input_class_t *this = (http_input_class_t *) data;
+static void proxy_password_change_cb(void *this_gen, xine_cfg_entry_t *cfg) {
+  http_input_class_t *this = (http_input_class_t *)this_gen;
 
   this->proxypassword = cfg->str_value;
 }
 
-static void proxy_host_change_cb(void *data, xine_cfg_entry_t *cfg) {
-  http_input_class_t *this = (http_input_class_t *) data;
+static void no_proxy_list_change_cb(void *this_gen, xine_cfg_entry_t *cfg) {
+  http_input_class_t *this = (http_input_class_t *)this_gen;
 
-  this->proxyhost = cfg->str_value;
+  this->noproxylist = cfg->str_value;
+}
 
-  if(this->proxyhost && (!strlen(this->proxyhost)) && this->proxyhost_env) {
-    this->proxyhost = this->proxyhost_env;
-    this->proxyport = this->proxyport_env;
+/*
+ * handle no proxy list config option and returns, if use the proxy or not
+ * if error occured, is expected using the proxy
+ */
+static int _x_use_proxy(http_input_class_t *this, const char *host) {
+  const char *target;
+  char *no_proxy, *domain, *ptr;
+  struct hostent *info;
+  size_t i = 0, host_len, noprox_len;
+
+  /* 
+   * get full host name 
+   */
+  if ((info = gethostbyname(host)) == NULL) {
+    xine_log(this->xine, XINE_LOG_MSG, 
+        _("input_http: gethostbyname(%s) failed: %s\n"), host,
+        strerror(errno));
+    return 1;
+  }
+  if (!info->h_name) return 1;
+  target = info->h_name;
+
+  host_len = strlen(target);
+  no_proxy = strdup(this->noproxylist);
+  domain = strtok_r(no_proxy, ", ", &ptr);
+  while (domain) {
+    noprox_len = strlen(domain);
+    if (host_len >= noprox_len && strcmp(target + host_len - noprox_len, domain) == 0) {
+      lprintf("host '%s' is in no-proxy domain '%s'\n", target, domain);
+      return 1;
+    }
+    lprintf("host '%s' isn't in no-proxy domain '%s'\n", target, domain);
+    
+    domain = strtok_r(NULL, ", ", &ptr);
+    i++;
   }
-}
+  free(no_proxy);
 
-static void proxy_port_change_cb(void *data, xine_cfg_entry_t *cfg) {
-  http_input_class_t *this = (http_input_class_t *) data;
-  
-  this->proxyport = cfg->num_value;
+  return 0;
 }
 
 static int http_plugin_basicauth (const char *user, const char *password, char* dest, int len) {
@@ -571,13 +618,13 @@
   int                  shoutcast = 0, httpcode;
   int                  res, progress;
   int                  buflen;
+  int                  use_proxy;
+  int                  proxyport;
   
   this->shoutcast_pos = 0;
+  use_proxy = this_class->proxyhost && strlen(this_class->proxyhost);
   
-  if (this_class->proxyhost && strlen(this_class->proxyhost)) {
-    if (this_class->proxyport == 0)
-      this_class->proxyport = DEFAULT_HTTP_PORT;
-    
+  if (use_proxy) {
     if (this_class->proxyuser && strlen(this_class->proxyuser)) {
       if (http_plugin_basicauth (this_class->proxyuser,
 			         this_class->proxypassword,
@@ -594,29 +641,37 @@
     _x_message(this->stream, XINE_MSG_GENERAL_WARNING, "malformed url", NULL);
     return 0;
   }
+  if (use_proxy && _x_use_proxy(this_class, this->host)) {
+    use_proxy = 0;
+  }
   if (this->port == 0)
     this->port = DEFAULT_HTTP_PORT;
   
-  if ((this->user && strlen(this->user)) && (this_class->proxyhost && strlen(this_class->proxyhost))) {
+  if ((this->user && strlen(this->user)) && use_proxy) {
     if (http_plugin_basicauth (this->user, this->password, this->auth, BUFSIZE)) {
       _x_message(this->stream, XINE_MSG_CONNECTION_REFUSED, "basic auth error", NULL);
       return 0;
     }
   }
   
+  if (this_class->proxyport == 0)
+    proxyport = DEFAULT_HTTP_PORT;
+  else
+    proxyport = this_class->proxyport;
+
 #ifdef LOG
   {
-    printf ("input_http: opening >/%s< on host >%s<", this->filename, this->host);
+    printf ("input_http: opening >%s< (on host >%s<)", this->mrl, this->host);
     
-    if (this_class->proxyhost && strlen(this_class->proxyhost))
-      printf (" via proxy >%s:%d<", this_class->proxyhost, this_class->proxyport);
+    if (use_proxy)
+      printf (" via proxy >%s:%d<", this_class->proxyhost, proxyport);
     
     printf ("\n");
   }
-#endif
-  
-  if (this_class->proxyhost && strlen(this_class->proxyhost))
-    this->fh = _x_io_tcp_connect (this->stream, this_class->proxyhost, this_class->proxyport);
+
+#endif  
+  if (use_proxy)
+    this->fh = _x_io_tcp_connect (this->stream, this_class->proxyhost, proxyport);
   else
     this->fh = _x_io_tcp_connect (this->stream, this->host, this->port);
   
@@ -635,7 +690,7 @@
   if (res != XIO_READY)
     return 0;
   
-  if (this_class->proxyhost && strlen(this_class->proxyhost)) {
+  if (use_proxy) {
     if (this->port != DEFAULT_HTTP_PORT) {
       snprintf (this->buf, BUFSIZE, "GET http://%s:%d%s HTTP/1.0\015\012",
 	       this->host, this->port, this->uri);
@@ -855,7 +910,7 @@
   
   if(this->proxyhost_env)
     free(this->proxyhost_env);
-  
+
   free (this);
 }
 
@@ -877,22 +932,34 @@
   this->input_class.dispose            = http_class_dispose;
   this->input_class.eject_media        = NULL;
 
+  /*
+   * proxy settings
+   */
   this->proxyhost_env = NULL;
-  this->proxyuser     = config->register_string(config, "input.http_proxy_user",
-						"", _("http proxy username"),
-						NULL, 0, proxy_user_change_cb, (void *) this);
+  this->proxyhost = config->register_string(config, 
+      "input.http_proxy_host", "", _("HTTP proxy host"),
+      _("HTTP proxy server used for http streaming"), 0,
+      proxy_host_change_cb, (void *) this);
+  this->proxyport = config->register_num(config,
+      "input.http_proxy_port", DEFAULT_HTTP_PORT, _("HTTP proxy port"),
+      _("HTTP proxy port used for http streaming"), 0,
+      proxy_port_change_cb, (void *) this);
+  this->proxyuser = config->register_string(config,
+      "input.http_proxy_user", "", _("HTTP proxy username"),
+      _("HTTP proxy user used for http streaming"), 0,
+      proxy_user_change_cb, (void *) this);
   this->proxypassword = config->register_string(config,
-						"input.http_proxy_password", "", _("http proxy password"),
-						NULL, 0, proxy_password_change_cb, (void *) this);
-  this->proxyhost     = config->register_string(config,
-						"input.http_proxy_host", "", _("http proxy host"),
-						NULL, 0, proxy_host_change_cb, (void *) this);
-  this->proxyport     = config->register_num(config,
-					     "input.http_proxy_port", DEFAULT_HTTP_PORT,
-					     _("http proxy port"),
-					     NULL, 0, proxy_port_change_cb, (void *) this);
+      "input.http_proxy_password", "", _("HTTP proxy password"),
+      _("HTTP proxy password used for http streaming"), 0, 
+      proxy_password_change_cb, (void *) this);
+  this->noproxylist = config->register_string(config,
+      "input.http_no_proxy", "", _("Sites, where don't use HTTP proxy"),
+      _("Comma separated domains, where xine shouldn't use proxy"), 0,
+      no_proxy_list_change_cb, (void *) this);
 
-  /* Honour http_proxy envvar */
+  /* 
+   * honour http_proxy envvar 
+   */
   if((!this->proxyhost) || (!strlen(this->proxyhost))) {
     char *proxy_env;
 



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Xine-cvslog mailing list
Xine-cvslog@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xine-cvslog
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic