Thread: Please Help - C code creates dynamic HTML

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    7

    Please Help - C code creates dynamic HTML

    I have inherited a very old web based application that is written in C (not C++) with embedded SQL statements. This application runs on Unix (Solarix) and uses Oracle Gateway (CGI) to access DB2 tables on the Host (mainframe). It's considered Pro*C.

    Problem:
    There are 4 major programs that are compiled and linked together to create 1 executable, which resides in the /cgi-bin/appname/ file. These programs are called by a html page, that passes what I assume is a variable parameter to the executable. This parameter is to be read in by the executable, and based on the parameter, will dynamically create a new HTML page that includes additional variables passed from the previous HTML page.

    The problem is that the code is looking for an existing html page, instead of passing the parameter to the executable for processing. The processing includes data validation from previous html page and database table updates to the Host DB2 tables.

    This is one of the statements from the C executable that I believe works with another statement to send the parameter to the executable. It is coming from what is supposed to be a dynamically created HTML page, asking for confirmation of screen data. On confirming, the program is supposed to add the data to the tables and return to the home page:

    (From C exe code)
    if (mode == ASK_CONF) {
    printf("<form name=\"addConfirm\" method=post action=\"%s/add\">\n", CGINAME);

    (From dynamically created HTML code)
    <form name="addConfirm" method=post action="/cgi-bin/exeName/add">

    I hope this makes sense. I would appreciate any help with this that I can get. I am on an extremely short deadline/end-date to get this application up and running for testing.

    Thank you!
    Christie

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I'm not sure what the question / problem is.

    The code you posted (C code) builds an html form, and the html code you posted, proves the form was build with what the C code said it should be built with.

    If the code is supposed to be doing something else, then we don't have enough information to present you with any options.

    (BTW, I work with DB2 on the mainframe every day, and I can write C CGI apps too. Lucky me!)

    Toddd
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    7
    The html code that I posted is actually from a form page that was created last year by my predecessor. His notes only said to "copy a previous html page into the directory". I assume it to be used as a placeholder, to be replaced by the new form. When I run my application, the old form displays, with the hard-coded statement. If I delete the old html page, I get a file not found error.

    Truthfully, I don't understand how this process works, and unfortunately, my predessesor passed away last summer... I am assuming (hate that word...) that the exe is wanting to create the dynamic htlm forms, based on the C code that creates the exe. I can't find any other existing html files from the 10 years of previous code.

    I'd appreciate any help that you can give... (I too am a "dinosaur programmer")
    Thanks,
    Christie

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Is this on an intranet or is it available from the www? PM me if you want. I'm happy to help.

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    One thing that is strange to me is the "/add" suffix on the path after the CGINAME. I recreated this with a couple small CGI programs, and while it doesn't seem to affect anything and works (on Unix), I question why it is there.

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    7
    This is an intranet application that has been in production for over 12 years. I believe the "/add" is being used as a parameter/variable to be read by the html.c code to determine how to process the data. I'll paste some code from the main.c and htmls.c code, so that you can see how it's being used.

    From main.c
    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);
    		} 
    		else if (strcmp(cgiPathInfo(), "/confirmAdd") == 0) {		/* asking confirmation from user */
    			pRegData = DB_createDataStructure(1);
    			cgiGetFormData();
    			if (cgiNumFormFields() == 0)
    				html_redirect(homePage);
    			getDataInStruct(pRegData);
    			html_initPage();
    From htmls.c

    Code:
    if (mode == CHG_CONF) {
    				printf("<form name=\"addConfirm\" method=post action=\"%s/change\">\n", CGINAME);
    				printf("<input type=hidden name=\"tracking\" value=\"%s\">\n", pData->tracking);
    				printf("<input type=hidden name=\"reason\" value=\"%s\">\n", pData->reason);
    			}
    			else {
    				printf("<form name=\"addConfirm\" method=post action=\"%s/add\">\n", CGINAME);
    			}
    		/*	printf("<input type=hidden name=\"session\" value=\"%s\">\n", pData->meeting);	*/
    			generateHiddenSession(pData->meeting);
    			printf("<input type=hidden name=\"a_ar_ht\" value=\"%s\">\n", pData->a_ar_ht);
    			printf("<input type=hidden name=\"a_dp_ht\" value=\"%s\">\n", pData->a_dp_ht);
    Does this help?
    Last edited by Dave_Sinkula; 04-02-2008 at 10:11 AM. Reason: Fixed code tags.

  7. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    What is the flow of page names? Which page name(s) works, and which page(s) does not display? What server are you running? Any errors in the server log? What's the full text of the error?

    (PS: The tags for code are [code] and [/code])
    Mainframe assembler programmer by trade. C coder when I can.

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    7
    Thank you for the code tag help. I typed it incorrectly at first, and thought that I had fixed everything... sorry...

    Good question. I think the flow is in the order that I copied, as the main.c has a comment that it's generating the form, and htmls.c is processing the data. For example, if the user clicks to yes, the entry is correct, then htmls.c will update the table with the entered data. To be honesst, I'm unsure, as there are 4 C programs that create the executable, and 3 of them are between 100 and 150 pages long. I've read them all and made notes, but the interact so much that I should probably create a flow chart, to better understand what's happening... However, since these programs have been running happily for so many years, I should be able to copy them to the correct directory or subdirectory and have them work... Life should never be this difficult

  9. #9
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Life should never be this difficult
    I agree. I'm feeling a bit like a dentist this morning... pulling teeth to get some answers.
    Mainframe assembler programmer by trade. C coder when I can.

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    7
    Dr., I would give you my wisdom teeth if I had any... but, you're correct. I forgot to answer some questions...

    None of the dynamically created code is working. There are several new html pages that should be created using similar syntax, but none of them display. I always get "file not found" errors. Also, the "add" parameter is supposed to trigger the code to update the DB2 files, which it is not.

    I'll search the code to see if I can more accurately piece together the flow. In the meantime, if you have any suggestions, I'd very much like to hear them...

    Thanks again for your help.

  11. #11
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    To pass a parameter to a CGI program, you typically add a "?parm" or "?parm=value". This would in turn be passed in environment variables CONTENT_TYPE, and the length of the parm string being reported in CONTENT_LENGTH.

    So, in this case, I would expect it to read:

    Code:
    <form name="addConfirm" method=post action="CGINAME?change">
    and not
    Code:
    <form name="addConfirm" method=post action="CGINAME/change">
    Now, back to change control... This has been working for 12 years. Now it doesn't. What changed? Did you recently go to a new server? Is there anywhere in your code where CONTENT_LENGTH and CONTENT_TYPE are being interrogated, looking for passed parms?

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

  12. #12
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I misspoke. Environment variable QUERY_STRING gets all the query ("?....") parameters.

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

  13. #13
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    OK, I ran a test case.

    When this is coded:
    Code:
    <form name="addConfirm" method=post action="CGINAME/change">
    The /change is reported in environment variable PATH_INFO, therefore it is a valid syntax / protocol.

    So, what changed? Out of curiosity, does a /change directory even exist?

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

  14. #14
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    The Bible on CGI environment variables: http://hoohoo.ncsa.uiuc.edu/cgi/env.html
    Mainframe assembler programmer by trade. C coder when I can.

  15. #15
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Read this if you just upgraded from Apache 1.1.1 (or earlier) to 1.2 or later: http://www.auburn.edu/docs/apache/cgi_path.html

    Todd
    Mainframe assembler programmer by trade. C coder when I can.

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, 03: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, 12:51 PM
  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