Thread: HTTP Get request to C Program

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    116

    HTTP Get request to C Program

    I am trying to modify code from the Olimex EasyWeb3 board. It uses an MSP430F149 and a crystal lan cs8900a ethernet controller. There is a sample code for a simple web server. I am interested in modifying the code to use Javascript to request information from the c program.

    The problem right now is that the way the code is written it basically has a constant array Webside [ ] that has the code directly written in it. essentially the main code transmits a certain data size of that webside variable. Before it is transmitted, a subroutine searches for specific keys in the data and replaces it with a certain value (AD7% is the specific key, searches for that, and replaces an actual ADC value from one of the ports of the microcontroller). Then it finishes transmitting the rest of the data.

    By doing it this way, there is no way I can have user interaction from the web browser. I am trying to make it so that the user can read or write values to specific locations in the microcontroller memory. I know the Javascript to use, but I do not know how those HTTP request interact with the sample code, or how it gets transfered or keeps track of it...

    Any suggestions would be helpful.

    Attached are the code

    Thanks!!!

  2. #2
    Registered User
    Join Date
    Feb 2008
    Posts
    116
    here are the rest of the attachments

    cs8900.c/.h --> contain the ethernet driver information
    webside.c --> webpage
    tcpip.h/.c --> the TCP/IP stack
    easyweb.c/.h --> contain the main program and function HTTPserver() to transmit the webpage


    I have looked on the internet about how solve my problem but there isn't much detailed information about it

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    4
    um, from what i understood without reading the source is that you transmit on the http protocol layer a content-length variable for the browser to understand how much code it should read from you, and you can't compute it using dynamic user-submitted variables.
    You can try splitting the array that has the code of the page and use http fragmentation to send it dynamically computing on the fly the content-length for each part.
    i haven't really dabbled in that, so i'd suggest you google.
    Sorry if i misunderstood your problem.
    Or if you're tring to parse user data, you need to parse the incoming http header: the url for get requests and another line for the post requests.
    Then, depending on whether they exist or not, call a subroutine that does w/e (write to file, execute command), and possibly another subroutine to alter the cookies for the current user so the session information changes.
    Last edited by tty0; 11-10-2010 at 06:53 PM.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    116
    well, I suppose that if a GET request from the web browser occurs, how is it received by the ethernet controller? Does it automatically get transfer to the RXdatabuffer of the ethernet controller?

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Since HTTP is a TCP protocal, there is a connect procedure that must take place, then a GET is sent. It then sits in the RX buffer at the network level waiting for a call to recv() to transfer it to the application level where you can process it. It doesn't just magically appear anywhere you can get at. The network level is oblivious to protocals other than those used to transfer data (UDP / TCP etc.) awareness of HTTP FTP etc. occurs at the application level.

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    116
    So I read that tutorial and other articles about HTTP protocols....In my case, in the main program (easyweb.c), it essentially setups the ethernet controller, etc... Then it hits the main while loop in which is listens for an incoming TCP-connection, function TCPPassive_Open().

    It then hits the DoNetworkStuff() function in tcpip.c , which takes care of the TCP/IP stack. It then jumps to HTTPserver() function which determines if there is a connection and sets everything up to transfer the webpage.

    The thing is that it says that "During the first jump to HTTPServer() after connecting, the flag HTTP_SEND_PAGE in register HTTPStatus is clear. It is used to process some special code sections during this first execution of HTTPServer(). The web server checks for any incoming TCP data and discards it. It is assumed that the received data contains a GET request from an Internet browser. Since our server supports only one web page, this request is not evaluated. The server starts just after client connection by sending the web page stored in MCU memory"


    So I can trying to determine if I have Javascript in my code that contains a "GET" request, what function is used to acknowledge that there is a request?? I know I'll have to create a function that checks what URI the "GET" request is for, then from there process is to grab whatever values I need.

    Can someone help me in the right direction?

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    My best advice is : follow the protocal... It is unlikely a web browser is going to know what to do with non-standard behaviours.
    Last edited by CommonTater; 11-16-2010 at 06:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sending http get request
    By LeeVerr in forum C Programming
    Replies: 4
    Last Post: 09-07-2010, 09:02 PM
  2. Free program I'm sharing: ConvertEnumToStrings
    By Programmer_P in forum Projects and Job Recruitment
    Replies: 101
    Last Post: 07-18-2010, 12:55 AM
  3. im a noob at c++, do you think so?
    By belRasho in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2010, 11:02 PM
  4. Function call from another .c module
    By Ali.B in forum C Programming
    Replies: 14
    Last Post: 08-03-2009, 11:45 AM
  5. serial port to poll on request
    By infineonintern in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 06:52 AM