/[hydra]/hydra/src/request.c
ViewVC logotype

Diff of /hydra/src/request.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.25 by nmav, Thu Oct 3 11:26:15 2002 UTC revision 1.26 by nmav, Fri Oct 4 09:11:43 2002 UTC
# Line 106  void get_request(server_params* params, Line 106  void get_request(server_params* params,
106      struct SOCKADDR salocal;      struct SOCKADDR salocal;
107      int remote_addrlen = sizeof (struct SOCKADDR);      int remote_addrlen = sizeof (struct SOCKADDR);
108      request *conn;              /* connection */      request *conn;              /* connection */
109      size_t len;      int len;
110      static int system_bufsize = 0; /* Default size of SNDBUF given by system */      static int system_bufsize = 0; /* Default size of SNDBUF given by system */
111  #ifdef ENABLE_SSL  #ifdef ENABLE_SSL
112      gnutls_session ssl_state = NULL;      gnutls_session ssl_state = NULL;
# Line 794  char *p = NULL; Line 794  char *p = NULL;
794    
795  /* Parses HTTP/1.1 range values.  /* Parses HTTP/1.1 range values.
796   */   */
797  static int parse_range( const char* value, unsigned long *p1, unsigned long *p2)  static int parse_range( const char* value, off64_t *val1, off64_t *val2)
798  {  {
 int ret = 0;  
799  int len;  int len;
800    char *p;
801    
802          *p1 = *p2 = 0;          *val1 = *val2 = 0;
803    
804          len = strlen( value);          len = strlen( value);
805          if (len < 7) return -1;          if (len < 7) return -1;
806    
807          /* we do not accept ranges of the form 10-20,21-30          /* we do not accept ranges of the form "bytes=10-20,21-30"
808           */           */
809          if (strchr( value, ',') != NULL) return -1;          if (strchr( value, ',') != NULL) return -1;
810    
# Line 812  int len; Line 812  int len;
812                  return -1;                  return -1;
813          } else value += 6;          } else value += 6;
814    
815          if (strchr( value, '-') == NULL) return -1;          while( *value==' ') value++;
816            if ((p=strchr( value, '-')) == NULL) return -1;
817    
818          if (value[0] == '-') {          if (value[0] == '-') { /* Handle case "bytes=-1024" */
819             *p2 = boa_atol( &value[1]);             *val1 = 0;
820               *val2 = boa_atoll( &value[1]);
821               return 0;
822            } else {
823               char buf[43];
824               int len;
825              
826               /* two values of the form "xxx-yyy" */
827    
828               if ((len=strlen( value)) >= sizeof(buf))
829                  return -1;
830              
831               memcpy( buf, value, len);
832               buf[len] = 0;
833              
834               p=strchr( buf, '-');
835               if (p==NULL) return -1;
836               *p = 0;
837               p++;
838    
839               while( *p==' ') p++;
840              
841               *val1 = boa_atoll( buf);
842              
843               if (*p == '\0') /* form: "xxx-" */
844                  *val2 = 0;
845               else
846                  *val2 = boa_atoll( p);
847              
848               if ( *val1 == -1) return -1;
849              
850             return 0;             return 0;
         } else  
            ret = sscanf( value, "%lu-%lu", p1, p2);  
   
         if (ret == 1) {  
            /* This one accepts ranges of both "-stop" and "start-"  
             */  
            return 0;  
851          }          }
852            
         if (ret == 2)  
                 return 0;  
                   
853          return -1;          return -1;
854  }  }
855    
856  inline  inline
857  static void init_range_stuff( request* req, char* value)  static void init_range_stuff( request* req, char* value)
858  {  {
859          unsigned long int p1, p2;          off64_t p1, p2;
860          if (parse_range( value, &p1, &p2) == 0) {          if (parse_range( value, &p1, &p2) == 0) {
861              req->range_start = p1;              req->range_start = p1;
862              req->range_stop = p2;              req->range_stop = p2;

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26