Diff for /parser3/src/main/pa_common.C between versions 1.143.2.21.2.19 and 1.143.2.21.2.24

version 1.143.2.21.2.19, 2003/04/01 16:16:23 version 1.143.2.21.2.24, 2003/04/08 14:46:27
Line 144  static const String http_any_status_name Line 144  static const String http_any_status_name
   
 // functions  // functions
   
 void fix_line_breaks(char* buf, size_t& size) {  void fix_line_breaks(char *str, size_t& length) {
         if(size==0)  
                 return;  
   
         //_asm int 3;          //_asm int 3;
         const char* const eob=buf+size;          const char* const eob=str+length;
         char* dest=buf;          char* dest=str;
         // fix DOS: \r\n -> \n          // fix DOS: \r\n -> \n
         // fix Macintosh: \r -> \n          // fix Macintosh: \r -> \n
         char* bol=buf;          char* bol=str;
         while(char* eol=(char*)memchr(bol, '\r', eob -bol)) {          while(char* eol=(char*)memchr(bol, '\r', eob -bol)) {
                 size_t len=eol-bol;                  size_t len=eol-bol;
                 if(dest!=bol)                  if(dest!=bol)
Line 163  void fix_line_breaks(char* buf, size_t& Line 160  void fix_line_breaks(char* buf, size_t&
   
                 if(&eol[1]<eob && eol[1]=='\n') { // \r, \n = DOS                  if(&eol[1]<eob && eol[1]=='\n') { // \r, \n = DOS
                         bol=eol+2;                          bol=eol+2;
                         size--;                           length--; 
                 } else // \r, not \n = Macintosh                  } else // \r, not \n = Macintosh
                         bol=eol+1;                          bol=eol+1;
         }          }
Line 232  static int http_read_response(String& re Line 229  static int http_read_response(String& re
 /* ********************** request *************************** */  /* ********************** request *************************** */
   
 #if defined(SIGALRM) && defined(HAVE_SIGSETJMP) && defined(HAVE_SIGLONGJMP)  #if defined(SIGALRM) && defined(HAVE_SIGSETJMP) && defined(HAVE_SIGLONGJMP)
 #       define WE_CAN_USE_ALARM  #       define PA_USE_ALARM
 #endif  #endif
   
 #ifdef WE_CAN_USE_ALARM  #ifdef PA_USE_ALARM
 static sigjmp_buf timeout_env;  static sigjmp_buf timeout_env;
 static void timeout_handler(int sig){  static void timeout_handler(int sig){
     siglongjmp(timeout_env, 1);       siglongjmp(timeout_env, 1); 
 }  }
 #endif  #endif
   
 static int http_request(  static int http_request(String& response,
                         String& response,  
                         const char* host, int port,                           const char* host, int port, 
                         const char* request,                           const char* request, 
                         int timeout,                          int timeout,
Line 253  static int http_request( Line 249  static int http_request(
                         0,                           0, 
                         "zero hostname");  //never                          "zero hostname");  //never
   
 #ifdef WE_CAN_USE_ALARM  #ifdef PA_USE_ALARM
     signal(SIGALRM, timeout_handler);           signal(SIGALRM, timeout_handler); 
 #endif  #endif
         int sock=-1;          int sock=-1;
         try {  #ifdef PA_USE_ALARM
                 int result;          if(sigsetjmp(timeout_env, 1)) {
 #ifdef WE_CAN_USE_ALARM                  // stupid gcc [2.95.4] generated bad code
                 if(sigsetjmp(timeout_env, 1))                  // which failed to handle sigsetjmp+throw: crashed inside of pre-throw code.
                         throw Exception("http.timeout",                   // rewritten simplier [though duplicating closesocket code]
                                 0,                   if(sock>=0) 
                                 "timeout occured while retrieving document");                           closesocket(sock); 
                 else {                  throw Exception("http.timeout", 
                         alarm(timeout);                           origin_string, 
                           "timeout occured while retrieving document"); 
                   return 0; // never
           } else {
                   alarm(timeout); 
 #endif  #endif
                   try {
                           int result;
                         struct sockaddr_in dest;                          struct sockaddr_in dest;
                                   
                 if(!set_addr(&dest, host, port))                          if(!set_addr(&dest, host, port))
                                 throw Exception("http.host",                                   throw Exception("http.host", 
                                         0,                                           0, 
                                         "can not resolve hostname \"%s\"", host);                                           "can not resolve hostname \"%s\"", host); 
Line 290  static int http_request( Line 292  static int http_request(
   
                         result=http_read_response(response, sock, fail_on_status_ne_200);                           result=http_read_response(response, sock, fail_on_status_ne_200); 
                         closesocket(sock);                           closesocket(sock); 
 #ifdef WE_CAN_USE_ALARM  #ifdef PA_USE_ALARM
                         alarm(0)                          alarm(0)
                 }  
 #endif  #endif
                 return result;                          return result;
         } catch(...) {                  } catch(...) {
                 if(sock>=0)   #ifdef PA_USE_ALARM
                         closesocket(sock);                           alarm(0)
 #ifdef WE_CAN_USE_ALARM  
                 alarm(0)  
 #endif  #endif
                 rethrow;                          if(sock>=0) 
                                   closesocket(sock); 
                           rethrow;
                   }
   #ifdef PA_USE_ALARM
         }          }
   #endif
 }  }
   
 #ifndef DOXYGEN  #ifndef DOXYGEN
Line 486  File_read_result file_read(Charset& char Line 490  File_read_result file_read(Charset& char
 #ifdef PA_HTTP  #ifdef PA_HTTP
         if(file_spec.starts_with("http://")) {          if(file_spec.starts_with("http://")) {
                 // fail on read problem                  // fail on read problem
                 File_read_http_result http;//=file_read_http(charset, file_spec, params);                  File_read_http_result http=file_read_http(charset, file_spec, params);
                 result.success=true;                  result.success=true;
                 result.str="HELLO";//http.str;                  result.str=http.str;
                 result.length=5;//http.length;                  result.length=http.length;
                 result.headers=new HashStringValue;//http.headers;                   result.headers=http.headers; 
         } else {          } else {
 #endif  #endif
                 File_read_action_info info={&result.str, &result.length};                   File_read_action_info info={&result.str, &result.length}; 
Line 505  File_read_result file_read(Charset& char Line 509  File_read_result file_read(Charset& char
                 // UTF-8 signature: EF BB BF                  // UTF-8 signature: EF BB BF
                 if(result.length>=3) {                  if(result.length>=3) {
                         char *in=(char *)result.str;                          char *in=(char *)result.str;
                         if((in[0] == '\xEF') && (in[1] == '\xBB') &&                          if(strncmp(in, "\xEB\xBB\xBF", 3)==0) {
                                 (in[2] == '\xBF')) {  
                                 result.str=in+3; result.length-=3;// skip prefix                                  result.str=in+3; result.length-=3;// skip prefix
                         }                          }
                 }                  }
Line 519  File_read_result file_read(Charset& char Line 522  File_read_result file_read(Charset& char
         return result;          return result;
 }  }
   
   #ifdef PA_SAFE_MODE 
   void check_safe_mode(stat finfo, const String& file_spec, const char* fname) { 
           if(finfo.st_uid/*foreign?*/!=geteuid() 
                   && finfo.st_gid/*foreign?*/!=getegid()) 
                   throw Exception("parser.runtime",  
                           &file_spec,  
                           "parser is in safe mode: " 
                           "reading files of foreign group and user disabled " 
                           "[recompile parser with --disable-safe-mode configure option], " 
                           "actual filename '%s', " 
                           "fuid(%d)!=euid(%d) or fgid(%d)!=egid(%d)",  
                                   fname, 
                                   finfo.st_uid, geteuid(), 
                                   finfo.st_gid, getegid()); 
   } 
   #endif 
   
 bool file_read_action_under_lock(const String& file_spec,   bool file_read_action_under_lock(const String& file_spec, 
                                 const char* action_name, File_read_action action, void *context,                                   const char* action_name, File_read_action action, void *context, 
                                 bool as_text,                                   bool as_text, 
Line 551  bool file_read_action_under_lock(const S Line 571  bool file_read_action_under_lock(const S
                                                 strerror(errno), errno, fname);                                                  strerror(errno), errno, fname);
   
 #ifdef PA_SAFE_MODE  #ifdef PA_SAFE_MODE
                         if(finfo.st_uid/*foreign?*/!=geteuid()                          check_safe_mode(finfo, file_spec, fname);
                                 && finfo.st_gid/*foreign?*/!=getegid())  
                                 throw Exception("parser.runtime",   
                                         &file_spec,   
                                         "parser is in safe mode: reading files of foreign group and user disabled [recompile parser with --disable-safe-mode configure option], actual filename '%s'",   
                                                 fname);  
 #endif  #endif
   
                         action(finfo, f, file_spec, fname, as_text, context);                           action(finfo, f, file_spec, fname, as_text, context); 

Removed from v.1.143.2.21.2.19  
changed lines
  Added in v.1.143.2.21.2.24


E-mail: