[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] ASCII



At oversætte cgi-kodede strenge til alm. ASCII. Ikke fordi jeg normalt
forærer kode væk, men her kommer en stump c jeg bruger til det:

void toextern( unsigned char *str )
/*                                                                       
*/
/* Note that the external string will always be shorter than the
internal,*/
/* so the same buffer can be used to make and return the
result.          */
/*                                                                       
*/
   {
   unsigned char *ipnt, *opnt,newmade;
   int maxcount,count, terminate;

   maxcount=strlen( str );
   ipnt=str;
   opnt=str;
   terminate=0;
   while ( !terminate )
      {
      switch ( *ipnt )
         {
         case '%': {  ipnt++;
                      if ( *ipnt >= 0x41 )
                         newmade=(*ipnt-0x37)*16;
                      else
                         newmade=(*ipnt-0x30)*16;
                      ipnt++;
                      if ( *ipnt >= 0x41 )
                         newmade+=(*ipnt-0x37);
                      else
                         newmade+=(*ipnt-0x30);
                      *opnt=newmade;
                      opnt++;
                      ipnt++;
                      } break;

         case '+': {  ipnt++;
                      *opnt=' ';
                      opnt++;
                      } break;

         case 0x00:{  *opnt=0x00;
                      terminate=1;
                      break;
                   }

         default:  {  *opnt=*ipnt;
                      opnt++;
                      ipnt++;
                      }
          } /* switch */
      } /* while */
   }

Den kunne måske have været lavet "smartere", men den virker i hvert
fald.

M.v.h.
S%F8ren


Jan Arentoft wrote:
> 
> "Søren H. Sørensen" <sslug@sslug> skrev i en meddelelse
> news:sslug@sslug
> problemerne med
> > ASCII er at de er urlencodede, eller cgi-kodede (plejer jeg at kalde
> > det). I cgi er alle blanktegn konverteret til +'er og alle specialtegn
> > er hex-koder. Et + vil således hedde %2B. Der er undtagelser fra den
> > kodning fx . og -, men generelt er alt du får fra serveren kodet og bør
> > scannes for %<hexkode>. Det er nemt at oversætte dem til ASCII igen.
> > S%F8ren (det hedder jeg i cgi)
> Tak for de andre svar det virker...
> Men hvordan oversætter jeg dem til ASCII igen ???
> Skal jeg programmere mig ud af det med noget if % then osv ?
> Jan Arentoft


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *