CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

HTTP2 and HTTP_USE_DOUBLE_ESCAPE

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

HTTP2 and HTTP_USE_DOUBLE_ESCAPE
PostPosted: Tue May 29, 2012 10:21 pm     Reply with quote

Hi All.

I am working on a web app using the ccs webserver2 example code and have ran out of escape chars.
I then tried to define HTTP_USE_DOUBLE_ESCAPE as true, which should allow me to use 2 chars as the id, eg %A1

When I try to use a case with 2 chars, I get a error saying "Character constant constructed incorrectly"

Here is part of the ccs code (I hope I can post this much)

Code:

int8 http_format_char(char* file, char id, char *str, int8 max_ret)                                  
   {
         char new_str[25];
         int8 len=0;

      switch(id)                                                                      
         {
            case '11':                                                            
              sprintf(new_str,"%u",HTMLTestData);
              len=strlen(new_str);
              break;
         }


So when I have '1' as my case all works fine, but I can't seem to find out how to use 'A1'. I am guessing is has something to do with the fact that a char id in the function can only hold 1 char, but I have no idea how to fix this.

Has anyone used the HTTP_USE_DOUBLE_ESCAPE before?

Thanks
jeremiah



Joined: 20 Jul 2010
Posts: 1322

View user's profile Send private message

PostPosted: Wed May 30, 2012 6:37 am     Reply with quote

The reason for the error is that single quotes are used for single characters, not double. You can't do 'A1', as that is illegal in C. You're gonna have to rethink how you want to handle double character escapes. Your current switch statement format isn't going to work. Some options include: state machine, switch statements inside switch statements, if/else if/else constructs, among others.
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Wed May 30, 2012 5:35 pm     Reply with quote

Thanks jeremiah, that what I was thinking.
I was just wondering if anyone else has already done something to save me re-inventing the wheel.

Thanks
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Thu May 31, 2012 12:17 am     Reply with quote

Hi Again,

I have now fixed the switch. However now when I view the webpage, the last char of the escape string gets shown at the end of the data string. Eg, if the data that is going to be shown for %AB is 123, the output on the webpage is 123B.

If I don't use HTTP_USE_DOUBLE_ESCAPE, everything works perfect.

I have searched for all references to HTTP_USE_DOUBLE_ESCAPE in https.c to try to work out what is going on, but I just can't work out where it would be inserting a extra char.

Can anyone shed any light on this one for me?

Thanks
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Fri Jun 01, 2012 3:51 am     Reply with quote

OK, problem been fixed by trial and error. This is what I changed in http2.c;

Code:

int TCPPutFileConstGetEscape(FILE* fstream)
{
#if HTTP_USE_DOUBLE_ESCAPE
   char str[3];
   int ret;
   MPFSGetBegin(*fstream);
   str[0]=fatgetc(fstream);
   str[1]=fatgetc(fstream);
   myfatseek(fstream, 0);      //<<<this was myfatseek(fstream, -2);

   str[2] = 0;
   ret = strtol(str, 0, 16);
#else
   char ret;
   MPFSGetBegin(*fstream);
   ret=fatgetc(fstream);
   MPFSGetEnd(fstream);
   myfatseek(fstream, -1);
#endif
   MPFSGetEnd(fstream);
   return(ret);
}


The question now is, why has this fixed it? I would of thought i needed to have the -2 offset so the next read from the eeprom starts after the 2 chars in the escape string.

Anyway, it works like a charm now. Hope this helps someone.

Thanks
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group