string - Removing single dot path names in URL in C -


i'm making function in apache module supposed fix urls thrown @ it. i'm trying remove single dot path names.

for example, if url is:

http://example.com/1/./2/./3/./4.php 

then want url be:

http://example.com/1/2/3/4.php 

however i'm stuck logic. i'm using pointers in effort make function run fast possible. i'm confused @ logic should apply @ lines //? added end of them.

can give me advice on how proceed? if hidden manual online? searched bing , google answers no success.

static long fixurl(char *u){   char u1[10000];   char *u11=u1,*uu1=u;   long ct=0,fx=0;   while (*uu1){     *u11=*uu1;     if (*uu1=='/'){       ct++;       if (ct >=2){         uu1++;         break;       }     } else {       ct=0;     }   }    while (*uu1){      if (*uu1!='/') { //?       if (*uu1!='.') {         *u11=*uu1;          u11++;       } //?     } //?     uu1++;   }    *u11='\0';   strcpy(u,u1);   return fx; } 

you forget ahead 1 character here:

if (*uu1!='/') { //?   if (*uu1!='.') { 

– checking same character twice (against 'not', have use, question marks indicate not sure there , further on).

note need ahead two characters. if encounter slash, test next character . and 1 after /.

rather trying fix code (what fx, returned value, supposed be?), i'd rewrite scratch copy source dest , skip offending sections. continue makes sure sequence /1/././2 gets cleansed correctly /1/2 – needs chance check second slash again, throw loop.

void fixurl (char *theurl) {     char *source, *dest;      source = dest = theurl;     while (*source)     {         if (source[0] == '/' && source[1] == '.' && source[2] == '/')         {             source += 2;  /* effectively, 'try again on next slash' */         } else         {             *dest = *source;             source++;             dest++;         }     }     *dest = 0; } 

(afterthought:)

interestingly, adding proper support removal of /../ trivial. if test sequence, should search backwards last / before , reset dest position. you'll want make sure path still valid, though.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -