ts-7000
[Top] [All Lists]

[ts-7000] RE: apache, and a cgi program on the debian linux ts-7500

To: <>
Subject: [ts-7000] RE: apache, and a cgi program on the debian linux ts-7500
From: <>
Date: 24 Sep 2013 20:56:39 -0700


Larry, 


Thanks, for your quick reply.   I'll consider PHP in the future, but right now, I've got dozens of programs I've written in C for cgi on an apache server that is runing on a windoze environment and I'm trying to convince my boss to switch to hosting on a ts-7500.  His answer is "well will it run our current software?"  and he is not interested in re-writing stuff in PHP.  I might be able to run new stuff in PHP, but for now I have to demonstrate that his old C programs will run lock stock and barrel using gcc on the deby linux ts-7500.   the old windows environment ran straight C programs that were compiled with the borland 5.5 C compiler.   Here is a snippet: 



/***********************************************************************\

    lostproduct.c

#NAME?

"starting point.  It will accept a product number, case count,"

"area, and description and make a time stamped entry into a log"

file. 


010622 JL   First creation.

050710 JL   had to change the file locations to new apache setup.  added

            loads of TRACE_ON statements.  above 10 is all over the program.


\***********************************************************************/


#include <stdio.h>

#include <string.h>

#include <ctype.h>

#include <time.h>

#include <stdlib.h>

#include <Sys/stat.h>


#define  OUTPUT_FILE_SIZE  65536

"#define  JL_DELIMITER_TAG  ""::"""

#define  JL_DELIMITER_TAG_LEN  2 

"#define  JL_START_TAG      ""<!--JL::"""

#define  JL_START_TAG_LEN  8 

"#define  JL_END_TAG        ""::JL-->"""

#define  JL_END_TAG_LEN    7


#if JMCHOST == 1

"#define  ANSWER_FILE       ""C:\\Inetpub\\iissam~1\\default\\lp\\lostpr~2.htm"" "

"#define  HTML_LOCATION     ""http://johncerritelli/lp/"""

#else

"#define  ANSWER_FILE       ""C:\\PROGRA~1\\APACHE~1\\Apache2\\htdocs\\lp\\LOSTPR~2.HTM"" "

"#define  HTML_LOCATION     ""http://localhost/lp/"" "

#endif


typedef struct {

    char **cgivars;

    char   request_method[22];

    char   status1[512];

    char   status2[512];

    int    bposting;

} global_type; 



char x2c(char *what) ;

void unescape_url(char *url) ;

char ** getcgivars          ( global_type *globals); 

"int mallocmakeFileToBuffer  ( char *szFile, char **szBuffer, global_type *globals); "

"int mallocmakeFileToBuffer2 ( char *szFile, char **szBuffer, global_type *globals); "

int getvaluecgivar "    ( char *szAnsbuffer, char *szCgivarname, global_type *globals );"

"int outputfreebuffer        ( char *szBuffer, global_type *globals); "

int process_tag "    ( char *szBuffer, char *szTag, global_type *globals); "

int removedoublereturns    ( char *szCgivalue);

"int hide_old_data           ( char *szBuffer, global_type *globals); "

int make_display_data_from_arrayfield

"    ( char *szBuffer, char *szArraytagname, global_type *globals); "



extern char **environ;


void main()

{

    char **cgivars ;

    char *outputbuffer; 

    int  i ;

    global_type  *globals;

    char  szPosting[11]; 


#if TRACE_ON > 0

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""w"");"

"    fprintf(fileFile, ""hello trace file 050712_4 !!\n""); "

    fclose(fileFile);

}

#endif

    globals = malloc( sizeof(global_type) );      

   

#if TRACE_ON >= 50

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): past malloc\n""); "

    fclose(fileFile); 

}

#endif 

"    /** First, get the CGI variables into a list of strings         **/"

    globals->cgivars =getcgivars(globals);

    

#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): past getcgivars!\n""); "

    fclose(fileFile); 

}

#endif 

    globals->bposting = 0; 

"    strcpy (globals->status1, ""Your data is ready for posting!  Use the [post data!] \n""); "

"    strcat (globals->status1, ""button just below to complete this process, or to  \n""); "

"    strcat (globals->status1, ""change some of the data, use the [re-edit] button. \n ""); "

"    strcat (globals->status1, ""To start over, use the [reset] button. \n ""); "


"    strcpy (globals->status2, ""Data to post: \n""); "


"    getvaluecgivar(szPosting, ""posting"", globals); "

#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): past getvaluecgivar !! \n"" ); "

    fclose(fileFile);

}

#endif

    if (szPosting[0]=='1') {

        FILE           *fileFile;

char szBuffer[16536];


globals->bposting = 1;

"        strcpy (globals->status1, ""Your data has been posted! You are now done. \n""); "

"        strcat (globals->status1, ""Please press: the [reset] button for the next person, \n""); "

"        strcat (globals->status1, ""the [re-edit] button to continue with more products, or\n"");"

"        strcat (globals->status1, ""the [done] button to close this window.  \n""); "


"        strcpy (globals->status2, ""Data posted: \n""); "


#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): before open of lostproduct.log  \n"" ); "

    fclose(fileFile); 

}

#endif 

"        fileFile = fopen(""..\\logs\\lostproduct.log"", ""a"");"

#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): after open about tocall make_display...\n"" ); "

    fclose(fileFile); 

}

#endif 

"        make_display_data_from_arrayfield(szBuffer, ""prod"", globals); "

#if TRACE_ON >= 2

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): szBuffer =>%s<.\n"",szBuffer); "

    fclose(fileFile); 

}

#endif 

"        fprintf(fileFile, ""%s"", szBuffer); "

        fclose(fileFile); 


    }


#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): just before mallocmakefiletobuffer2 \n"" ); "

    fclose(fileFile);

}

#endif

    mallocmakeFileToBuffer2(

"        ANSWER_FILE,"

"&outputbuffer,"

globals

        );


#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): past mallocmake..., before outputfreebuffer!! \n"" ); "

    fclose(fileFile); 

}

#endif 

"    outputfreebuffer(outputbuffer, globals);"


#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): past outputfreebuffer \n"" ); "

    fclose(fileFile); 

}

#endif 

    

    /** Print the CGI variables sent by the user.  Note the list of **/

"    /**   variables alternates names and values, and ends in NULL.  **/"


    /** Free anything that needs to be freed **/

    for (i=0; globals->cgivars[i]; i++) free(globals->cgivars[i]);

    free(globals->cgivars);

    free(globals);


#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): exitting.  \n"" ); "

    fclose(fileFile); 

}

#endif 

    exit(0) ;

}  /* main */ 



/*---------------------------------------------------------------------*\

    function outputfreebuffer()

\*---------------------------------------------------------------------*/

int outputfreebuffer ( 

"    char *szBuffer,"

    global_type *globals

    )

{

    

#if TRACE_ON >= 50

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""outputfreebuffer(): in outputfreebuffer \n"" ); "

    fclose(fileFile); 

}

#endif 

"    /** Print the CGI response header, required for all HTML output. **/"

"    /** Note the extra \n, to send the blank line.                  **/"

"    printf(""Content-type: text/html\n\n"") ;"


#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, ""main(): past firstprintline! \n"" ); "

    fclose(fileFile); 

}

#endif 

#if TRACE_ON >= 10

{

    FILE           *fileFile;

"    fileFile = fopen(""lostproduct.trace"", ""a"");"

"    fprintf(fileFile, "

"     ""main(): past firstprintline, heres the next 100 chars :\n%100.100s\n:\n"""

"     ,szBuffer ); "

    fclose(fileFile); 

}

#endif 

"    printf(""%s\n<!--JL 7/12/01 11:00am -->\n"",szBuffer); "

    free ( szBuffer); 


    return 1;


} /* END outputfreebuffer */



//**************************************************************************************************************


So on the ts-7500 I found index.html in /var/www   ( I think, I don't have the ts-7500 in front of me. right now) 

and the apache has started right out of the box so I can hit the index.html from my browser on my windoze machine.   


Now I need to ??? configure??? Apache  so that cgi executables will run from ??? directory ???  (/usr/lib/cgi-bin ???)   and configure the apache to recognize that the files with the extension .cgi  are allowed to be run???   I read things about httpd.conf, but then I read about default vs virtual ...   its all so confusing. 


I wouldn't mind a hello world php program to get the apache stuff worked out, but I also need to compile and link my lostproduct.c into a a.out that I rename to lostproduct.cgi (or lostproduct.exe as I did  in windoze) and get it to run on the TS-7500.   I realize the #define's to the databases and directories  and such will have to change, but I can live with that.   


Any help in getting this working will be appreciated.   


- jleslie



 



---In <> wrote:

I would suggest a different design. This is exactly what PHP is perfect for.
If it's not already on your board, you can add PHP as a module for Apache,
or compile it in. You will learn to love PHP. You can write scripts that use syntax
very similar to C, but it is actually interpreted, no compile required.
You embed script right into your web pages.

Good luck
Larry
On 9/24/2013 10:47 PM, m("...","jleslie48");"> wrote:
 

ok, so the html pages go into /www.    say I want to compile and link a c program that is called by a <form>  does anybody have an example?   something simple like an html page that has a text box to enter your name, and the c program writes back a html page saying hello xxx.   also with make file????  or at least the gcc compile and link commands???



TIA, 
jleslie




-- 
Larry Eaton
http://www.rnmicrosystems.com/


__._,_.___


Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: =Email Delivery: Digest | m("yahoogroups.com?subject","ts-7000-fullfeatured");=Change Delivery Format: Fully Featured">Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | =Unsubscribe

__,_._,___
<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU