howto create dynamic web pages

閲覧: 2 回
最初の未読メッセージにスキップ

cyberstorm

未読、
2007/03/12 9:43:262007/03/12
To: neptune354-dev
Ok, lets start with the first post. I will tell u how to "easily"
execute c functions in web pages.
Functions in web pages can be used for printing dynamic infos like the
uptime, or to execute a command.

All stuffs realted to web interface (except of httpd and www pages)
are in the router/shared/ folder. The file broadcom.c hadles all the
interactions between user interface and router, but I will not
explain how it is structured here.

Ok suppose you need a function that prints the current uptime in a web
page. We call this command get_uptime().
First of all put the command name in a web page in this way:

Current uptime: <% get_uptime(); %>

Then search in the router/shared/broadcom.c for the struct ej_handlers
( at the end of the file)
You have to add to this structure one element:

{"get_uptime", ej_get_uptime}, (add it before the last {NULL,NULL} )

The first field is the command name, the second field is the function
name that execute it.
BTW, I still does not know the meaning of "ej".
Next, add the the function name in broadcom.h:

extern void ej_get_uptime (webs_t wp, int argc, char_t ** argv);

Now you have 2 choices:
1) Add the function to one of the .c files in the shared/ folder.
2) Create a new c file, and add cfilename.o to the list of objects in
the "httpd:" rule in httpd/Makefile

Finally, write your function:

void ej_get_uptime (webs_t wp, int argc, char_t ** argv)
{
int foo;
....
bar();
...
}

Useful function:
websWrite(wp,...);
use it like sprintf(...);

cheers

marco

全員に返信
投稿者に返信
転送
新着メール 0 件