Please Help - C code creates dynamic HTML

This is a discussion on Please Help - C code creates dynamic HTML within the C Programming forums, part of the General Programming Boards category; I'm back. My understanding is that nothing has changed in the environment except some "patches". We use Oracle on Solaris ...

  1. #16
    Registered User
    Join Date
    Apr 2008
    Posts
    7
    I'm back. My understanding is that nothing has changed in the environment except some "patches". We use Oracle on Solaris Unix server.

    I did some more reading and charting of the code. It creates many and calls many functions. By piecing these functions and calls together, I believe the code is creating html that states:

    If type=ADD_NEW print HTML as follows:
    Code:
    formname="addRegForm" method=post action="text/html1010confirmAdd"
    /cgi-bin/eventName
    Note: eventName in above cgi-bin can be either a directory or the executable name, as Unix doesn't use extenstions. There's no documentation on paths for this, so I can try putting exe in both directory of eventName and in the directory cgi-bin.

    Question: What does the 1010 mean after action="text/html1010

    In ascii, 10 is character for new line. The 1010 is fed in from a function call that uses a variable that states s=10. The calling code is html%s%s which makes me think the code is to separate the text/html from the confirmAdd.

    I'm going to try using a blank file as the place holder for the form addRegForm and see if that will work, as I don't see anything wrong with the code itself.

    What are your thoughts?

    As always, thank you so much for your help.
    Last edited by Christie2008; 04-02-2008 at 10:55 AM. Reason: fix code tag

  2. #17
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Not sure.

    The content of the action= should be a URL encoded string. If the intent was to put newlines in the URL string, that might be OK, but is seems strange to me that newlines would be part of the path name. In the query string portion, fine, but not in the path name. ??

    A properly encoded value, if that was the intent, would be "%10%10" with the percent signs to designate/indicate the next two bytes were hex. Therefore, the source printf would have to be "html%%%s%%%s". (A double % gives you one percent sign in the built string)

    Also, by setting s=10, that tells me its probably an int, and later on, using variable s for the %s string substitution for variable s would give a compile error (or warning). Perhaps it's translated to a string somewhere else.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #18
    Registered User
    Join Date
    Apr 2008
    Posts
    7
    Well, my idea of putting in a blank file as a place holder didn't work.

    I'm sorry, but I got 2 of the function calls mixed up. The actual code for the html form is

    Code:
    printf("<form name=\"addRegForm\" method=post action=\"&#37;s/confirmAdd\">\n", CGINAME);
    CGINAME is:
    Code:
    CGINAME=/cgi-bin/eventName
    So, what the html code that is being created is actually:
    Code:
    action=/cgi-bin/eventName/confirmAdd
    The 1010 came from a function that is initializing the html page to be created, by setting content type to "text/html%c%c, 10, 10"

    Code:
    void html_initPage()
    {
    	printf("Content-type: text/html%c%c", 10, 10);
    }
    It's being called from:
    Code:
    	if (strcmp(cgiPathInfo(), "/addForm") == 0) {			/* Generating form for new registration */
    			pRegData = DB_createDataStructure(1);
    			cgiGetFormData();
    			getParamData();
    			html_initPage();
    			html_regForm(ADD_NEW, pRegData, NULL);
    			free(pRegData);
    		}
    I interpret content type to be text/html1010
    Do you know what that means?
    Last edited by Christie2008; 04-02-2008 at 12:19 PM. Reason: typo

  4. #19
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I know what that is. The first line of the "document" that is served up by any CGI app has to be a header. The header is

    content-type: some_mime_type

    followed by 2 newline characters. (It can be more, but that is the basic, minimally required, header)

    In most cases, some_mime_type is text/html. You would typically see
    Code:
    printf("Content-type: text/html\n\n") ;
    but doing it with 0x10 twice is valid as well. The header should not be externalized as text/html1010 though.

    Here's an example of the output of my CGI app, when I execute it from my IDE: (essentially, as it would look running it from the command line in a shell)
    Code:
    Content-Type: text/html
    
    <html><body><table><tr><td>
    	SHELL                         
    </td><td>
    	9
    </td><td>
    	/bin/bash
    </td></tr>
    <tr><td>
    	DYLD_LIBRARY_PATH             
    </td><td>
    	46
    </td><td>
    	/Users/toddburch/Xcode/scriptstats/build/Debug
    </td></tr>
    <tr><td>
    	NSUnbufferedIO                
    </td><td>
    ...
    It's a pretty simple protocol overall - just the header, followed by a blank line (which is created by 2 newline characters), followed by the html, just as if it were hand coded.

    Todd
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  5. #20
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I just called my buddy who is more web savvy than I. I explained the situation and I think he determined what is going on the with your URL strings.

    Apparently, you are using mod_rewrite, or some home grown version thereof, to allow "friendly" URLs, thus the "/change" and "/add" suffixes on the URL paths instead of the query strings.

    See here: http://en.wikipedia.org/wiki/Mod_rewrite and also this easy to understand explanation: http://www.workingwith.me.uk/article...ng/mod_rewrite

    Todd
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code to HTML
    By IfYouSaySo in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-15-2005, 02:00 AM
  2. Check out my code
    By joshdick in forum C++ Programming
    Replies: 9
    Last Post: 09-17-2003, 07:41 PM
  3. Dynamic HTML
    By netboy in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 04-16-2002, 01:30 PM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM
  5. Shouldn't either HTML or vB code be enabled in the C++ Board?
    By SilentStrike in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-13-2001, 07:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21