Unnamed Fossil Project

Check-in [5efd835985]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:updated.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5efd8359852eee20d19e2eabf5d097bbe61f923c
User & Date: monster 2012-08-07 05:12:04
Context
2012-08-09
01:06
mySQL backend for XDDB check-in: 64eb4d0d7d user: monster tags: trunk
2012-08-07
05:12
updated. check-in: 5efd835985 user: monster tags: trunk
2012-08-03
06:54
xtmpl added check-in: 5cba536d25 user: monster tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to buffer.hc.

    82     82   #ifdef _YO_BUFFER_BUILTIN
    83     83     {
    84     84       if ( capacity < 0 )
    85     85         __Raise(YO_ERROR_OUT_OF_RANGE,0);
    86     86   
    87     87       if ( !bf ) bf = Buffer_Init(0);
    88     88   
    89         -    if ( bf->capacity < capacity )
           89  +    if ( bf->capacity < capacity || !bf->at )
    90     90         {
    91     91           bf->at = __Realloc_Npl(bf->at,capacity+1);
    92     92           bf->capacity = capacity;
           93  +        STRICT_REQUIRE(bf->count <= bf->capacity );
           94  +        bf->at[bf->count] = 0;
    93     95         }
    94     96         
    95     97       return bf;
    96     98     }
    97     99   #endif
    98    100     ;
    99    101   
................................................................................
   261    263       
   262    264       E = p + len;
   263    265       
   264    266       while ( p != E )
   265    267         {
   266    268           do 
   267    269             { 
   268         -            if ( *p < 30 || *p == '\\' || *p == brk ) 
          270  +            if ( *p < 30 || *p == '\\' || *p == brk || *p == '"' || *p == '\'' ) 
   269    271                 break; 
   270    272               ++p; 
   271    273             } 
   272    274           while ( p != E );
   273    275           
   274    276           if ( q != p )
   275    277             Buffer_Append(bf,q,p-q);
................................................................................
   281    283               else if ( *p == '\r' ) Buffer_Append(bf,"\\r",2);
   282    284               else if ( *p == '\\' ) Buffer_Append(bf,"\\\\",2);
   283    285               else if ( *p == brk )  
   284    286                 { 
   285    287                   Buffer_Fill_Append(bf,'\\',1);
   286    288                   Buffer_Fill_Append(bf,brk,1);
   287    289                 }
   288         -            else if ( *p == '"' ) Buffer_Append(bf,"\\\"",2);
          290  +            else if ( *p == '"' ) 
          291  +              Buffer_Append(bf,"\\\"",2);
          292  +            else if ( *p == '\'' ) 
          293  +              Buffer_Append(bf,"\\'",2);
   289    294               else if ( *p < 30 ) 
   290    295                 {
   291    296                   Buffer_Append(bf,"\\x",2);
   292    297                   Buffer_Hex_Append(bf,p,1);
   293    298                 }
   294    299             
   295    300               ++p;

Changes to dicto.hc.

    50     50   #define _YO_DICTO_BUILTIN
    51     51   #endif
    52     52   
    53     53   #include "yoyo.hc"
    54     54   #include "crc.hc"
    55     55   #include "buffer.hc"
    56     56   #include "array.hc"
           57  +#include "string.hc"
    57     58   
    58     59   typedef struct _YO_DICTO_REC
    59     60     {
    60     61       struct _YO_DICTO_REC *next;
    61     62       void *ptr;
    62     63       byte_t hashcode;
    63     64       char key[1];
................................................................................
   382    383       dicto_apply_filter_t filter = _filter;
   383    384       if ( o && o->table ) 
   384    385         for ( i = 0; i < o->width; ++i )
   385    386           {      
   386    387             nrec = o->table[i];
   387    388             while ( nrec )
   388    389               {
   389         -              filter(nrec->key,nrec->ptr,state);
          390  +              __Auto_Release filter(nrec->key,nrec->ptr,state);
   390    391                 nrec = nrec->next;
   391    392               }  
   392    393           }
   393    394     }
   394    395   #endif
   395    396     ;
   396    397   
................................................................................
   460    461                     Buffer_Append(bf,", ",2); 
   461    462                 else 
   462    463                   j = 1; 
   463    464                 if ( pretty )
   464    465                   Buffer_Fill_Append(bf,' ',2); 
   465    466                 Buffer_Append(bf,nrec->key,-1);
   466    467                 Buffer_Append(bf,": ",2);
   467         -              print(bf,nrec->ptr);
          468  +              __Auto_Release print(bf,nrec->ptr);
   468    469                 nrec = nrec->next;
   469    470               }  
   470    471           }
   471    472       
   472    473       if ( j && pretty )
   473    474         Buffer_Fill_Append(bf,'\n',1); 
   474    475       Buffer_Fill_Append(bf,'}',1);
................................................................................
   477    478         return Buffer_Take_Data(bf);
   478    479       else
   479    480         return bf->at+start;
   480    481     }
   481    482   #endif
   482    483     ;
   483    484   
          485  +YO_DICTO *Dicto_Set_Str(YO_DICTO *dicto, char *key, void *val)
          486  +#ifdef _YO_DICTO_BUILTIN  
          487  +  {
          488  +    if ( !dicto )
          489  +      dicto = Dicto_Ptrs();
          490  +    Dicto_Put(dicto,key,Str_Copy_Npl(val,-1));
          491  +    return dicto; 
          492  +  }
          493  +#endif
          494  +  ;
          495  +  
   484    496   #endif /* C_once_38B1FFE7_1462_42EB_BABE_AA8E0BE62203 */
   485    497   

Changes to file.hc.

  1063   1063       if ( Raise_If_Cfile_Is_Not_Opened(f) )
  1064   1064         {
  1065   1065           YO_BUFFER *L;
  1066   1066           quad_t len = Cfile_Available(f);
  1067   1067           if ( len > INT_MAX )
  1068   1068             Yo_Raise(YO_ERROR_IO,
  1069   1069               "file to big to be read in one pass",__Yo_FILE__,__LINE__);
  1070         -        L = Buffer_Init(0);
         1070  +        L = Buffer_Reserve(0,len);
  1071   1071           while ( len ) 
  1072   1072             /* windoze text mode reads less then available, so we need to read carefully*/
  1073   1073             {
  1074   1074               Buffer_Grow_Reserve(L,L->count+(int)len);
  1075   1075               L->count += Cfile_Read(f,L->at+L->count,(int)len,0);
  1076   1076               L->at[L->count] = 0;
  1077   1077               len = Cfile_Available(f);

Added linebuf.hc.

            1  +
            2  +/*
            3  +
            4  +Copyright © 2010-2011, Alexéy Sudachén, alexey@sudachen.name, Chile
            5  +
            6  +In USA, UK, Japan and other countries allowing software patents:
            7  +
            8  +    This program is free software: you can redistribute it and/or modify
            9  +    it under the terms of the GNU General Public License as published by
           10  +    the Free Software Foundation, either version 3 of the License, or
           11  +    (at your option) any later version.
           12  +
           13  +    This program is distributed in the hope that it will be useful,
           14  +    but WITHOUT ANY WARRANTY; without even the implied warranty of
           15  +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
           16  +    GNU General Public License for more details.
           17  +
           18  +    http://www.gnu.org/licenses/
           19  +
           20  +Otherwise:
           21  +
           22  +Permission is hereby granted, free of charge, to any person obtaining a copy
           23  +of this software and associated documentation files (the "Software"), to deal
           24  +in the Software without restriction, including without limitation the rights
           25  +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
           26  +copies of the Software, and to permit persons to whom the Software is
           27  +furnished to do so, subject to the following conditions:
           28  +
           29  +The above copyright notice and this permission notice shall be included in
           30  +all copies or substantial portions of the Software.
           31  +
           32  +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
           33  +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
           34  +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
           35  +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
           36  +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
           37  +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
           38  +THE SOFTWARE.
           39  +
           40  +Except as contained in this notice, the name of a copyright holder shall not
           41  +be used in advertising or otherwise to promote the sale, use or other dealings
           42  +in this Software without prior written authorization of the copyright holder.
           43  +
           44  +*/
           45  +
           46  +#ifndef C_once_FAC5C358_605A_4663_A129_F9C093097A9C
           47  +#define C_once_FAC5C358_605A_4663_A129_F9C093097A9C
           48  +
           49  +#include "yoyo.hc"
           50  +#include "string.hc"
           51  +#include "buffer.hc"
           52  +
           53  +#ifdef _LIBYOYO
           54  +#define _YO_DEFPARS_BUILTIN
           55  +#endif
           56  +
           57  +typedef struct _YO_LINEBUF
           58  +  {
           59  +    void *file;
           60  +    char *file_name;
           61  +    void *fast_file_obj;
           62  +    int  (*fast_file_read)(void *obj, void *bf, int count, int mincount);
           63  +    char *at;
           64  +    byte_t *tail;
           65  +    int  tail_len;
           66  +    int  cur_line;
           67  +    int  next_line;
           68  +    int  eof;
           69  +    YO_BUFFER *line;
           70  +  } YO_LINEBUF;
           71  +
           72  +void YO_LINEBUF_Destruct(YO_LINEBUF *lb)
           73  +  {
           74  +    __Unrefe(lb->line);
           75  +    __Unrefe(lb->file);
           76  +    free(lb->file_name);
           77  +  }
           78  +
           79  +YO_LINEBUF *Linebuf_Init(void *file, char *file_name)
           80  +  {
           81  +    YO_LINEBUF *lb = __Object_Dtor(sizeof(YO_LINEBUF),YO_LINEBUF_Destruct);
           82  +    lb->file = __Refe(file);
           83  +    lb->file_name = Str_Copy_Npl(file_name,-1);
           84  +    lb->line = __Refe(Buffer_Init(0));
           85  +    lb->fast_file_obj = lb->file;
           86  +    lb->fast_file_read = Yo_Find_Method_Of(&lb->fast_file_obj,Oj_Read_OjMID,YO_RAISE_ERROR);
           87  +    return lb;
           88  +  }
           89  +  
           90  +int Linebuf_Nextline(YO_LINEBUF *lb)
           91  +  {
           92  +    int i,j;
           93  +
           94  +    byte_t *tail;
           95  +
           96  +    tail = lb->line->at;
           97  +    
           98  +    if ( lb->tail_len )
           99  +      {
          100  +        memmove(lb->line->at,lb->tail,lb->tail_len);
          101  +        Buffer_Resize(lb->line,lb->tail_len);
          102  +      }
          103  +
          104  +    lb->cur_line = lb->next_line;
          105  +    lb->tail = 0;
          106  +    lb->tail_len = 0;
          107  +    i = 0;      
          108  +    for (;;)
          109  +      {
          110  +        for ( ; tail[i] ; ++i )
          111  +          if ( tail[i] == '\n' )
          112  +            {
          113  +              tail[i] = 0;
          114  +              lb->tail = tail +i;
          115  +              lb->tail_len = lb->line->count - i;
          116  +              ++lb->next_line;
          117  +              break;
          118  +            }
          119  +          else if ( tail[i] == '\r' && i+1 < lb->line->count && tail[i+1] == '\n')
          120  +            {
          121  +              tail[i] = 0;
          122  +              lb->tail = tail + i + 1;
          123  +              lb->tail_len = lb->line->count - (i+1);
          124  +              ++lb->next_line;
          125  +              break;
          126  +            }
          127  +
          128  +        if ( !lb->tail )
          129  +          {
          130  +            Buffer_Reserve(lb->line,i+256);
          131  +            j = lb->fast_file_read(lb->fast_file_obj,lb->line->at+i,256,0);
          132  +            if ( j )
          133  +              Buffer_Resize(lb->line,i+j);
          134  +            else
          135  +              break;
          136  +          }
          137  +        else
          138  +          break;
          139  +      }
          140  +  
          141  +    lb->at = lb->line->at;
          142  +    lb->eof = !lb->at[0] && lb->next_line == lb->cur_line;
          143  +    return !lb->eof;
          144  +  }
          145  +
          146  +int Linebuf_ExtendLine(YO_LINEBUF *lb)
          147  +  {
          148  +    return 0;
          149  +  }
          150  +  
          151  +int Linebuf_Eof(YO_LINEBUF *lb)
          152  +  {
          153  +    return lb->eof;
          154  +  }
          155  +  
          156  +int Linebuf_Lineno(YO_LINEBUF *lb)
          157  +  {
          158  +    return lb->cur_line;
          159  +  }
          160  +
          161  +#endif /* C_once_FAC5C358_605A_4663_A129_F9C093097A9C */

Changes to string.hc.

  1769   1769           }
  1770   1770           
  1771   1771       return __Pool(R);
  1772   1772     }
  1773   1773   #endif
  1774   1774     ;
  1775   1775   
         1776  +char *Str_Quote(char *S)
         1777  +#ifdef _YO_STRING_BUILTIN  
         1778  +  {
         1779  +    int S_len = S? strlen(S):0;
         1780  +    int R_count = 0;
         1781  +    int R_capacity = S_len+1;
         1782  +    char *R = 0;
         1783  +
         1784  +    if ( S )
         1785  +      for ( ; *S; ++S )
         1786  +        {
         1787  +          if ( 0 ) ;
         1788  +          else if ( *(signed char*)S < 30
         1789  +            || *S == '"' || *S == '\'' ||*S == '\\' 
         1790  +          )
         1791  +            {
         1792  +              char b[5] = {0,};
         1793  +              Str_Hex_Byte(*S,'\\',b);
         1794  +              R_count += __Elm_Append_Npl(&R,R_count,b,4,1,&R_capacity);
         1795  +            }
         1796  +          else R_count += __Elm_Append_Npl(&R,R_count,S,1,1,&R_capacity);
         1797  +        }
         1798  +        
         1799  +    return __Pool(R);
         1800  +  }
         1801  +#endif
         1802  +  ;
         1803  +    
  1776   1804   #endif /* C_once_0ED387CD_668B_44C3_9D91_A6336A2F5F48 */
  1777   1805   

Changes to webcfg.hc.

    58     58     {
    59     59       char *foo;
    60     60   
    61     61       if ( !host ) host = Webhost_Init();
    62     62   
    63     63       foo = cfg?Xnode_Value_Get_Str(&cfg->root,"doc_root",0):0;
    64     64       if ( !foo ) foo = Current_Directory();
    65         -    Webhost_Set_Doc_Root(host,foo);
           65  +    Webhost_Add_Doc_Root(host,foo);
    66     66     
    67     67       foo = cfg?Xnode_Value_Get_Str(&cfg->root,"exec_root",0):0;
    68     68       Webhost_Set_Exec_Root(host,foo);
    69     69   
    70     70       return host;
    71     71     }
    72     72   #endif
    73     73     ;
    74     74   
    75     75   #endif /*C_once_A719E9E5_B5AB_4A78_A061_34860A495936*/
    76     76   

Changes to webhost.hc.

    84     84       __Destruct(svc);
    85     85     }
    86     86   #endif
    87     87     ;
    88     88       
    89     89   typedef struct _YO_WEBHOST
    90     90     {
    91         -    char *doc_root;
    92     91       char *exec_root;
           92  +    YO_ARRAY *doc_roots;
    93     93       YO_ARRAY *indexes;
    94     94       YO_ARRAY *services;
    95     95       
    96     96       int disable_index: 1;
    97     97     } YO_WEBHOST;
    98     98     
    99     99   void YO_WEBHOST_Destruct(YO_WEBHOST *host)
   100    100   #ifdef _YO_WEBHOST_BUILTIN
   101    101     {
   102    102       __Unrefe(host->indexes);
   103         -    free(host->doc_root);
          103  +    __Unrefe(host->doc_roots);
   104    104       free(host->exec_root);
   105    105       __Destruct(host);
   106    106     }
   107    107   #endif
   108    108     ;
   109    109     
   110    110   typedef struct _YO_WEBHOST_CGIST
................................................................................
   136    136     ;
   137    137     
   138    138   YO_WEBHOST *Webhost_Init()
   139    139   #ifdef _YO_WEBHOST_BUILTIN
   140    140     {
   141    141       YO_WEBHOST *host = __Object_Dtor(sizeof(YO_WEBHOST),YO_WEBHOST_Destruct);
   142    142       host->indexes = __Refe(Array_Pchars());
          143  +    host->doc_roots = __Refe(Array_Pchars());
   143    144       return host;
   144    145     }
   145    146   #endif
   146    147     ;
   147    148     
   148         -YO_WEBHOST *Webhost_Set_Doc_Root(YO_WEBHOST *host, char *doc_root)
          149  +YO_WEBHOST *Webhost_Add_Doc_Root(YO_WEBHOST *host, char *doc_root)
   149    150   #ifdef _YO_WEBHOST_BUILTIN
   150    151     {
   151         -    free(host->doc_root);
   152         -    host->doc_root = doc_root?Str_Copy_Npl(doc_root,-1):0;
          152  +    if ( doc_root )
          153  +      Array_Push(host->doc_roots,Str_Copy_Npl(doc_root,-1));
   153    154       return host;
   154    155     }
   155    156   #endif
   156    157     ;
   157    158     
   158    159   YO_WEBHOST *Webhost_Set_Exec_Root(YO_WEBHOST *host, char *exec_root)
   159    160   #ifdef _YO_WEBHOST_BUILTIN
................................................................................
   320    321         }
   321    322         
   322    323       return fpath;    
   323    324     }
   324    325   #endif
   325    326     ;
   326    327       
   327         -char *Webhost_Find_Handler(YO_WEBHOST *host, char *query, char **script, char **pathinfo,YO_WEBHOST_SERVICE **h)
          328  +char *Webhost_Find_Handler(YO_WEBHOST *host, char *doc_root, char *query, char **script, char **pathinfo,YO_WEBHOST_SERVICE **h)
   328    329   #ifdef _YO_WEBHOST_BUILTIN
   329    330     {
   330    331       char *fpath = 0;
   331    332       
   332    333       if ( !host->services ) return 0;
   333    334       __Auto_Ptr(fpath)
   334    335         {
   335    336           int i, L;
   336    337   
   337    338           YO_ARRAY *extL = Array_Init();
   338    339           YO_ARRAY *patL = Str_Split(query,"/");
   339         -        YO_BUFFER *bf  = Buffer_Acquire(Path_Normilize_Npl(host->doc_root));
          340  +        YO_BUFFER *bf  = Buffer_Acquire(Path_Normilize_Npl(doc_root));
   340    341           
   341    342           for ( i = 0; i < host->services->count; ++i )
   342    343             {
   343    344               YO_WEBHOST_SERVICE *svc = host->services->at[i];
   344    345               if ( svc->ext ) Array_Push(extL,svc->ext);
   345    346             }
   346    347                     
................................................................................
   364    365         }
   365    366         
   366    367       return fpath;    
   367    368     }
   368    369   #endif
   369    370     ;
   370    371   
   371         -YO_ARRAY *Webhost_Setup_Environment(YO_WEBHOST *host, YO_HTTPD_REQUEST *rqst, char *path, char *script, char *pathinfo, YO_URL *url)
          372  +YO_ARRAY *Webhost_Setup_Environment(char *doc_root, YO_HTTPD_REQUEST *rqst, char *path, char *script, char *pathinfo, YO_URL *url)
   372    373   #ifdef _YO_WEBHOST_BUILTIN
   373    374     {
   374    375       YO_ARRAY *env;
   375    376       __Auto_Ptr(env)
   376    377         {    
   377    378           char *method = 0;
   378    379           env = Array_Pchars();
................................................................................
   404    405               case HTTPD_PUT_METHOD:  method = "PUT";  break;
   405    406             }
   406    407           
   407    408           Array_Push(env,Str_Concat_Npl("REQUEST_METHOD=",method));
   408    409           Array_Push(env,Str_Concat_Npl("REMOTE_ADDR=",rqst->remote_addr));
   409    410           Array_Push(env,Str_Concat_Npl("REMOTE_HOST=",rqst->remote_addr));
   410    411           Array_Push(env,Str_Concat_Npl("REQUEST_URI=",url->uri));
   411         -        Array_Push(env,Str_Concat_Npl("DOCUMENT_ROOT=",host->doc_root));
          412  +        if ( doc_root )
          413  +          Array_Push(env,Str_Concat_Npl("DOCUMENT_ROOT=",doc_root));
   412    414           Array_Push(env,Str_Concat_Npl("HTTP_REFERRER=",Dicto_Get(rqst->qhdr,"REFERRER","")));
   413    415           if ( Dicto_Has(rqst->qhdr,"COOKIE") )
   414    416             Array_Push(env,Str_Concat_Npl("HTTP_COOKIE=",Dicto_Get(rqst->qhdr,"COOKIE","")));
   415    417           
   416    418           //("HTTP_USER_AGENT");
   417    419           //("HTTP_ACCEPT_LANGUAGE");
   418    420           //("SERVER_NAME");
................................................................................
   445    447             }
   446    448         }
   447    449       return 0;
   448    450     }
   449    451   #endif
   450    452     ;
   451    453       
   452         -void Webhost_Execute_Service(YO_WEBHOST_CGIST *st)
          454  +void Webhost_Execute_Service(YO_WEBHOST_CGIST *st, char *doc_root)
   453    455   #ifdef _YO_WEBHOST_BUILTIN
   454    456     {
   455         -    YO_ARRAY *env = Webhost_Setup_Environment(st->host,st->rqst,st->path,st->script,st->pathinfo,st->url);
          457  +    YO_ARRAY *env;
          458  +    if ( !doc_root ) doc_root = st->host->doc_roots->count?st->host->doc_roots->at[0]:0;
          459  +    env = Webhost_Setup_Environment(doc_root,st->rqst,st->path,st->script,st->pathinfo,st->url);
   456    460       st->rqst->outstrm_type = Mime_String_Of_Npl(YO_MIME_HTML);
   457    461       st->rqst->outstrm = __Refe(Cfile_Temp());
   458    462       st->cgi = __Refe(Cgi_Init_2(st->rqst->instrm,st->rqst->outstrm,(char**)env->at));
   459    463       Tasque_Alert(0,st->svc->callback,st);
   460    464     }
   461    465   #endif
   462    466     ;
................................................................................
   598    602       __Auto_Release 
   599    603         {
   600    604           char *curdir = Current_Directory();
   601    605           
   602    606           __Try_Except
   603    607             {
   604    608               YO_ARRAY *env;
          609  +            char *doc_root = st->host->doc_roots->count?st->host->doc_roots->at[0]:0;
   605    610               Change_Directory(Path_Dirname(st->path));
   606         -            env = Webhost_Setup_Environment(st->host,st->rqst,st->path,st->script,st->pathinfo,st->url);
          611  +            env = Webhost_Setup_Environment(doc_root,st->rqst,st->path,st->script,st->pathinfo,st->url);
   607    612               
   608    613               st->pipex = __Refe(Pipex_Exec(Path_Basename(st->path),0,PIPEX_TMPFILE,PIPEX_NONE,(char**)env->at));
   609    614               
   610    615               if ( st->rqst->instrm )
   611    616                 {
   612    617                   int c = Oj_Copy_File(st->rqst->instrm,st->pipex->fin);
   613    618                   Oj_Flush(st->pipex->fin);
................................................................................
   668    673               for ( i = 0; i < L; ++i ) if ( b[i] < 30 || b[i] > 127 ) b[i] = '.';
   669    674               if ( rqst->instrm_length > MAX_L ) memcpy(b+MAX_L-3,">>>",3);
   670    675               Log_Info("[%p] POSTDTA %s",rqst,b);
   671    676             }
   672    677           
   673    678           if ( host->services )
   674    679             {
   675         -            YO_WEBHOST_SERVICE *svc;
          680  +            YO_WEBHOST_SERVICE *svc = 0;
   676    681               svc = Webhost_Find_Service(host->services,url->query,&script,&pathinfo);
   677    682               if ( svc )
   678    683                 {
   679    684                   YO_WEBHOST_CGIST *st = Webhost_CGI_State(host, rqst, __Retain(path), script, pathinfo, url);
   680    685                   st->svc = __Refe(svc);
   681         -                Webhost_Execute_Service(st);
          686  +                Webhost_Execute_Service(st,host->doc_roots->at[0]);
   682    687                   return 0;
   683    688                 }
   684    689             }
   685    690           
   686    691           #ifdef __windoze
   687    692           if ( host->exec_root )
   688    693             {
................................................................................
   690    695               if ( path )
   691    696                 return Webhost_Execute_CGI(Webhost_CGI_State(host, rqst, __Retain(path), script, pathinfo, url));
   692    697             }
   693    698           #endif
   694    699           
   695    700           if ( host->services )
   696    701             {
          702  +            char *doc_root = 0;
          703  +            char *path = 0;
   697    704               YO_WEBHOST_SERVICE *svc = 0;
   698         -            path = Webhost_Find_Handler(host,url->query,&script,&pathinfo,&svc);
          705  +            for ( i = 0; i < host->doc_roots->count; ++i )
          706  +              {
          707  +                doc_root = host->doc_roots->at[i];
          708  +                path = Webhost_Find_Handler(host,doc_root,url->query,&script,&pathinfo,&svc);
          709  +                if ( path ) break;
          710  +              }
   699    711               if ( svc )
   700    712                 {
   701    713                   YO_WEBHOST_CGIST *st = Webhost_CGI_State(host, rqst, __Retain(path), script, pathinfo, url);
   702    714                   st->svc = __Refe(svc);
   703         -                Webhost_Execute_Service(st);
          715  +                Webhost_Execute_Service(st,doc_root);
   704    716                   return 0;
   705    717                 }
   706    718             }
   707    719             
   708         -        path = Path_Join(host->doc_root,url->query);
   709         -        path = Path_Normposix(path);
          720  +        for ( i = 0; i < host->doc_roots->count; ++i )
          721  +          {
          722  +            path = Path_Join(host->doc_roots->at[i],url->query);
          723  +            path = Path_Normposix(path);
          724  +            if ( File_Get_Stats(path,&stats,1)->f.exists )
          725  +              break;
          726  +            else
          727  +              path = 0;
          728  +          }
   710    729           
   711         -        if ( File_Get_Stats(path,&stats,1)->f.exists )
          730  +        if ( path )
   712    731             {
   713    732               if ( stats.f.is_directory )
   714    733                 {
   715    734                   for ( i = 0; i < host->indexes->count; ++i )
   716    735                     {
   717    736                       char *path1 = Path_Join(path,host->indexes->at[i]);
   718    737                       if ( File_Get_Stats(path1,&stats,1)->f.exists )

Changes to xdata.hc.

   846    846   #endif
   847    847     ;
   848    848   
   849    849   YO_XNODE *Xnode_Next_If(YO_XNODE *node, char *tag_name)
   850    850   #ifdef _YO_XDATA_BUILTIN
   851    851     {
   852    852       ushort_t tag;
   853         -    YO_XNODE *n;
          853  +    YO_XNODE *n = node;
   854    854         
   855    855       if ( !node ) return 0;
   856         -    n = Xnode_Refacc(node);
          856  +    //n = Xnode_Refacc(node);
   857    857       
   858    858       STRICT_REQUIRE( n );
   859    859       STRICT_REQUIRE( tag_name );
   860    860       STRICT_REQUIRE( (n->opt&XVALUE_OPT_IS_VALUE) == 0 );
   861    861       
   862    862       tag = (ushort_t)(longptr_t)Xdata_Resolve_Name(n->xdata,tag_name,0);
   863    863       

Added xddbmsql.hc.


Added xddbsql3.hc.


Changes to xdef.hc.

   410    410   void Def_Parse_In_Node( YO_XDEF_STATE *st, YO_XNODE *n )
   411    411   #ifdef _YO_XDEF_BUILTIN
   412    412     {
   413    413       Def_Parse_Skip_Spaces(st);
   414    414       
   415    415       for ( ; *st->text && *st->text != '}' ; Def_Parse_Skip_Spaces(st) ) 
   416    416         {
          417  +        int set_if_not_set = 0;
   417    418           int go_deeper = 0;
   418    419           YO_XNODE *nn = 0;
   419    420           
   420    421           __Auto_Release
   421    422             {
   422    423               YO_XDEF_VALUE value = {0};
   423    424               char *name; 
................................................................................
   434    435                   if ( *st->text != ')' )
   435    436                     __Raise(YO_ERROR_ILLFORMED,__Format("expected ')' at line %d",st->lineno));
   436    437                   ++st->text;
   437    438                   Def_Parse_Skip_Spaces(st);
   438    439                 }
   439    440               
   440    441               
          442  +            if ( *st->text == '?' && st->text[1] == '=' )
          443  +              {
          444  +                set_if_not_set = 1;
          445  +                ++st->text;
          446  +              }
          447  +
   441    448               if ( *st->text == '=' )
   442    449                 {
   443    450                   ++st->text;
   444    451                   Def_Parse_Skip_Spaces(st);
   445    452                   Def_Parse_Get_Value(st,&value);
   446    453                   Def_Parse_Skip_Spaces(st);
   447    454                 }
................................................................................
   448    455               
   449    456               if ( *st->text == '<' && st->text[1] == '=' )
   450    457                 {
   451    458                   YO_XDATA *xd = 0; 
   452    459                   YO_XNODE *sn = 0;
   453    460                   char *include_file;
   454    461                   char *subnode = 0;
          462  +                int  skip_if_dsnt_exists = 0;
   455    463                   st->text += 2;
   456    464                   Def_Parse_Skip_Spaces(st);
   457    465                   include_file = Def_Parse_Get_Literal(st);
   458    466                   Def_Parse_Skip_Spaces(st);
          467  +                if ( *include_file == '?' )
          468  +                  {
          469  +                    ++include_file;
          470  +                    skip_if_dsnt_exists = 1;
          471  +                  }
   459    472                   subnode = strchr(include_file,':');
   460    473                   if ( subnode ) *subnode++ = 0;
   461    474                   if ( st->dirname ) include_file = Path_Join(st->dirname,include_file);
   462         -                xd = Def_Parse_File(include_file);
   463         -                sn = subnode?Xnode_Query_Node(&xd->root,subnode):&xd->root;
   464         -                if ( sn )
          475  +                if ( !skip_if_dsnt_exists || File_Exists(include_file) )
   465    476                     {
   466         -                    nn = Xnode_Append_Refnode(n,name,sn);
   467         -                    name = 0;
          477  +                    xd = Def_Parse_File(include_file);
          478  +                    sn = subnode?Xnode_Query_Node(&xd->root,subnode):&xd->root;
          479  +                    if ( sn )
          480  +                      {
          481  +                        nn = Xnode_Append_Refnode(n,name,sn);
          482  +                        name = 0;
          483  +                      }
   468    484                     }
   469    485                 }
   470    486               
   471    487               if ( nodename )
   472    488                 {
   473    489                   if ( !nn )
   474    490                     nn = Xnode_Append(n,name);
................................................................................
   484    500                     nn = Xnode_Append(n,name);
   485    501                   if ( value.type )
   486    502                     Def_Parse_In_Node_Set_Value(nn,"$",&value);
   487    503                 }
   488    504               else if ( value.type )
   489    505                 {
   490    506                   if ( name || !nn )
   491         -                  Def_Parse_In_Node_Set_Value(n,name,&value);
          507  +                  {
          508  +                    if ( !set_if_not_set || !Xnode_Value(n,name,0) )
          509  +                      Def_Parse_In_Node_Set_Value(n,name,&value);
          510  +                  }
   492    511                   else
   493    512                     Def_Parse_In_Node_Set_Value(nn,"$",&value);
   494    513                 }
   495    514                 
   496    515             }
   497    516           
   498    517           if ( go_deeper )

Changes to xtmpl.hc.

   111    111           return source - S_source;
   112    112         }
   113    113         
   114    114       return 0;
   115    115     }
   116    116   #endif
   117    117     ;
          118  +
          119  +int Xtmpl_Quote_Template(YO_XNODE *n, char *source)
          120  +#ifdef _YO_XTMPL_BUILTIN 
          121  +  {
          122  +    char *S_source = source;
          123  +    for ( ; *source && *source != '}'; ) ++source;
          124  +    
          125  +    if ( *source == '}' )
          126  +      {
          127  +        YO_XNODE *ext = Xnode_Append(n,"quote");
          128  +        YO_XVALUE *val = Xnode_Value(ext,"$",1);
          129  +        Xvalue_Set_Str(val,S_source,source-S_source);
          130  +        ++source;
          131  +        return source - S_source;
          132  +      }
          133  +      
          134  +    return 0;
          135  +  }
          136  +#endif
          137  +  ;
   118    138   
   119    139   int Xtmpl_Dump_Template(YO_XNODE *n, char *source)
   120    140   #ifdef _YO_XTMPL_BUILTIN 
   121    141     {
   122    142       char *S_source = source;
   123    143       for ( ; *source && *source != '}'; ) ++source;
   124    144       
................................................................................
   225    245           YO_XNODE *ext = Xnode_Append(n,tag);
   226    246           char *expr = Str_Trim_Copy_L(S_source,source-S_source);
   227    247           if ( expr && *expr )
   228    248             {
   229    249               YO_XVALUE *val = Xnode_Value(ext,"$",1);
   230    250               Xvalue_Set_Or_Put_Str(val,expr);
   231    251             }
   232         -        source += Xtmpl_Macro_Template(ext,source+1,close_tag);
          252  +        ++source;
          253  +        source += Xtmpl_Macro_Template(ext,source,close_tag);
   233    254           return source - S_source;
   234    255         }
   235    256         
   236    257       return 0;
   237    258     }
   238    259   #endif
   239    260     ;
................................................................................
   289    310       static char t_set[]      = "set{";
   290    311       static char t_repeat[]   = "repeat{";
   291    312       static char t_at[]       = "at{";
   292    313       static char t_at1[]      = "at1{";
   293    314       static char t_inc[]      = "inc{";
   294    315       static char t_dec[]      = "dec{";
   295    316       static char t_expand[]   = "{";
          317  +    static char t_quote[]    = "quote{";
   296    318       static char t_comment[]  = "/*";
   297    319       char *S_source = source;
   298    320       char *Q;
   299    321       int close_len = close_tag?strlen(close_tag):0;
   300    322       
   301    323       for ( Q = source; *source; )
   302    324         {
................................................................................
   327    349                   Q = source;
   328    350                 }
   329    351               else if ( !strncmp(source+1,t_expand,sizeof(t_expand)-1) )
   330    352                 {
   331    353                   source += sizeof(t_expand);
   332    354                   source += Xtmpl_Expand_Template(n,source);
   333    355                   Q = source;
          356  +              }
          357  +            else if ( !strncmp(source+1,t_quote,sizeof(t_quote)-1) )
          358  +              {
          359  +                source += sizeof(t_quote);
          360  +                source += Xtmpl_Quote_Template(n,source);
          361  +                Q = source;
   334    362                 }
   335    363               else if ( !strncmp(source+1,t_liftup,sizeof(t_liftup)-1) )
   336    364                 {
   337    365                   source += sizeof(t_liftup);
   338    366                   source += Xtmpl_Liftup_Template(n,source);
   339    367                   Q = source;
   340    368                 }
................................................................................
  1050   1078               char S[3];
  1051   1079               sprintf(S,"%d",i);
  1052   1080               Dicto_Put(ctx->global,S,__Refe(m));
  1053   1081               Xvalue_Set_Str(&m->value,L->at[i],strlen(L->at[i]));
  1054   1082             }
  1055   1083           Xtmpl_Query_Str_Bf(ctx,L->at[0],bf);
  1056   1084         }
         1085  +    else if ( Xnode_Tag_Is(n,"quote") )
         1086  +      {
         1087  +        int i;
         1088  +        char *query = Xnode_Value_Get_Str(n,"$",0);
         1089  +        YO_XVALUE *m = Xtmpl_Query_Value(ctx,query);
         1090  +        if ( m ) Buffer_Quote_Append(bf,Xvalue_Get_Str(m,""),-1,0);
         1091  +      }
  1057   1092       else if ( Xnode_Tag_Is(n,"def") )
  1058   1093         {
  1059   1094           Xtmpl_Def_Macro(ctx,n);
  1060   1095         }
  1061   1096       else if ( Xnode_Tag_Is(n,"set") )
  1062   1097         {
  1063   1098           Xtmpl_Set_Value(ctx,n);
................................................................................
  1140   1175             Xtmpl_Handle_Node_Out(bf,n,&ctx);
  1141   1176           n = Xnode_Next(n);
  1142   1177         }
  1143   1178     }
  1144   1179   #endif
  1145   1180     ;
  1146   1181     
  1147         -void Xtmpl_Step_Down(YO_BUFFER *bf, YO_XNODE *tmpl, YO_XDATA *model)
         1182  +#ifdef _YO_XTMPL_BUILTIN 
         1183  +void Xtmpl_Glob_Set(char *key, char *val, YO_DICTO *glob)
         1184  +  {
         1185  +      YO_XNODE *t;
         1186  +      YO_BUFFER *bf = Buffer_Init(0);
         1187  +      YO_XTMPL_VALUE *m = YO_XTMPL_VALUE_Init();
         1188  +      Dicto_Put(glob,key,__Refe(m));
         1189  +      Xvalue_Set_Str(&m->value,val,-1);
         1190  +  }
         1191  +#endif
         1192  +  
         1193  +void Xtmpl_Step_Down(YO_BUFFER *bf, YO_XNODE *tmpl, YO_XDATA *model, YO_DICTO *glob)
  1148   1194   #ifdef _YO_XTMPL_BUILTIN 
  1149   1195     {
  1150   1196       YO_DICTO *global = Dicto_Refs();
  1151   1197       YO_XTMPL_UP upstep_q[32] = { {tmpl, 0}, };
  1152   1198       YO_XNODE *down; 
  1153   1199       YO_XTMPL_UP *upstep = upstep_q;
         1200  +    
         1201  +    Dicto_Apply(glob,Xtmpl_Glob_Set,global);
  1154   1202       
  1155   1203       for ( down = Xnode_Down_If(tmpl,"extends"); down; )
  1156   1204         {
  1157   1205           Xtmpl_Step_Down_Global_Set(upstep->tmpl,down,global,model);
  1158   1206           upstep[1].up = upstep;
  1159   1207           ++upstep;
  1160   1208           upstep->tmpl = down;
................................................................................
  1172   1220           ctx.tmpl   = tmpl;
  1173   1221           Xtmpl_Step_Up(bf,upstep,"content",&ctx);
  1174   1222         }
  1175   1223     }
  1176   1224   #endif
  1177   1225     ;
  1178   1226   
  1179         -char *Xtmpl_Produce_Out(YO_BUFFER *bf, YO_XDATA *tmpl, YO_XDATA *model)
         1227  +char *Xtmpl_Produce_Out(YO_BUFFER *bf, YO_XDATA *tmpl, YO_XDATA *model, YO_DICTO *glob)
  1180   1228   #ifdef _YO_XTMPL_BUILTIN 
  1181   1229     {
  1182   1230       YO_BUFFER *xbf = bf;
  1183   1231       if ( !xbf ) xbf = Buffer_Init(0);
  1184   1232       Buffer_Append(bf,"\n",1);
  1185         -    Xtmpl_Step_Down(bf,&tmpl->root,model);
         1233  +    Xtmpl_Step_Down(bf,&tmpl->root,model,glob);
  1186   1234       return bf?xbf->at:Buffer_Take_Data(xbf);
  1187   1235     }
  1188   1236   #endif
  1189   1237     ;
  1190   1238   
  1191   1239   #ifdef _YO_XTMPL_BUILTIN 
  1192   1240   
................................................................................
  1233   1281           Dicto_Put(dt,S,__Refe(doc)); /* doc can be NULL */
  1234   1282         }
  1235   1283       return doc;
  1236   1284     }
  1237   1285   
  1238   1286   #endif
  1239   1287   
         1288  +void Xtmpl_Drop_Cache()
         1289  +#ifdef _YO_XTMPL_BUILTIN 
         1290  +  {
         1291  +    if ( Xtmpl_Cache_Dicto )
         1292  +      {
         1293  +        __Unrefe(Xtmpl_Cache_Dicto);
         1294  +        Xtmpl_Cache_Dicto = __Refe(Dicto_Refs());
         1295  +      }
         1296  +  }
         1297  +#endif
         1298  +  ;
         1299  +  
  1240   1300   YO_XDATA *Xtmpl_Autoload(char *root,  char *name, char **langlist /*zero terminated langiages list*/)
  1241   1301   #ifdef _YO_XTMPL_BUILTIN 
  1242   1302     {
  1243   1303       YO_XDATA *doc = 0;
  1244   1304       __Auto_Release /* document is retaining by template cache */
  1245   1305         {
  1246   1306           if (langlist) for ( ; !doc && *langlist; ++langlist )