Advertisement
Guest User

MikelSV StormServer / RewriteEngine

a guest
Jun 10th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #ifdef USEMSV_PCRE
  2.         //RewriteEngine
  3.         if(listen_http_options.GetOptionGlobal("RewriteEngine", host).compareu("on")){
  4.             ilink.Link(url);
  5.  
  6.             // rewrite
  7.             listen_http_option *rw_host = host;
  8.             listen_http_option *opt = 0;
  9.             while(1){
  10.                 opt = listen_http_options.FindOption("RewriteRule", opt, rw_host);
  11.  
  12.                 if(!opt && rw_host){
  13.                     opt = listen_http_options.FindOption("RewriteRule", 0, 0);
  14.                     rw_host = 0;
  15.                 }
  16.  
  17.                 if(!opt)
  18.                     break;
  19.  
  20.  
  21.                 // init
  22.                 VString rule, result, options;
  23.                 const char *errptr; int erroffset;
  24.                 int opt_l = 0, opt_qsa = 0;
  25.                 int arr[255];
  26.  
  27.                 VString rurl = ilink.GetPathFile().str(1);
  28.                 rule = PartLine(opt->val, result, " ");
  29.                 result = PartLine(result, options, " ");
  30.                
  31.                 // compile
  32.                 pcre *p = pcre_compile(it.set(rule), 0, &errptr, &erroffset, 0);               
  33.                 // find
  34.                 int f = pcre_exec(p, 0, rurl, rurl, 0, 0, arr, 255);
  35.  
  36.                 // found
  37.                 if(f > 0){
  38.                     // options
  39.                     if(options[0] == '[' && options.endo() == ']'){
  40.                         options = options.str(1, -2);
  41.                    
  42.                         while(options){
  43.                             VString k = PartLine(options, options, ",");
  44.                             if(k == "L" || k == "last")
  45.                                 opt_l = 1;
  46.                             else if(k == "SQA" || k == "qsappend")
  47.                                 opt_qsa = 1;
  48.                         }
  49.                     }
  50.  
  51.                     it.Reserv(prmf_pcre_result(0, 0, result, result, rurl, rule, arr, f, opt_qsa, ilink.iquest));
  52.                     prmf_pcre_result(it, it, result, result, rurl, rule, arr, f, opt_qsa, ilink.iquest);
  53.                     ilink.Link(url = it);
  54.                 }
  55.  
  56.                 pcre_free(p);
  57.  
  58.                 if(opt_l)
  59.                     break;             
  60.             }
  61.         }
  62. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement