< Back

Server code organization and build system

Build system

This program could be build in two ways :

  1. As a linux executable, using some ported to linux lwip routines.
    • If the program is build as a linux executable then, data sent to it, is stored in pbufs, netconn functions and friends are implemented with UNIX sockets. All data processing is done with lwip functions for pbuf processing. The ported lwip stack is located at pseudo-lwip/. The building process is handled by the makefile (make noos [-B]).
  2. As a freertos task using lwip.
    • If the program is build as a freertos task then, the building process is handled by the programmer's copy and paste skills and the programming environment witch he is using.

Code organization

File Description
generic-json-zero-copy.c, generic-json-zero-copy.h Callback based json parser.
http_server.c http_server.h Server main function.
http-utils.c http-utils.h HTTP utilities used by the project
json_decode.c Test program for json parser, might be broken. (Not used by the server)
low-level-api.c, low-level-api.h Low level API used by the server for memory and register i/o.
macros.h Macroses used by the HTTP server.
makefile Makefile.
network-stack.h Header made to allow smooth pseudo-lwip to lwip transition.
noOS.c Linux port of the server.
post_methods.c, post_methods.h Methods called by the server on POST requests.
pseudo-lwip/ Pseudo-lwip (linux port).
wp.h The web page

JSON parser

HTTP server

HTTP Utils

Low Level API

Post methods

---[POST request to /api/2]---------------------\
                                                |
           +---------------------------+        |
           | post request lookup table |        |
           |                           |        |
           |     (method_index: 1)[]   |        |
        /--|---<-(method_index: 2)[]<--|--------/
        |  |     (method_index: 3)[]   |
        |  |          .....            |
        |  |                           | 
        |  +---------------------------+
        |
        V
   [API->take()] ----------(if error)----------> [return error to client]
        |                                                ^ 
        |                                                |
        V                                                |
   method([request body])                                |
 { send data to the user }  -----------------------------/
        |
        |
        |
        V
  [API->release()]

A POST request is done to /api/2, the second method is looked up in the request lookup table. Then API->take() it is run, then the needed method is run passing it the POST body. In the end API->release() is run. More in API->release() and API->take() could be found here

Web Page

Makefile

Debugging

Smooth lwip porting

File
api.h
api_lib.c
netbuf.c
netbuf.h
pbuf.c
pbuf.h