Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing methods

Status
Not open for further replies.

mojaffa

Programmer
Oct 23, 2003
8
SE
Hi
Im working with the Zilog ez80 embedded webserver and have a problem.
The following is an extract from theez80 programmers reference manual:

-----------------------------------------------------------------------
The first parameter of the http_init function is http_defmethods, which is externally defined by eZ80 Webserver software. This parameter is a structure of the type http_method, which is found in the htp.h include file and shown as follows:
typedef struct http_method {
int key;
char *name;
void (*method)(Http_Request *);
} Http_Method;
The parameter is a set of structure entries that maps a request method to the requested method function. The user must, however, ensure that this parameter is included in the http_init call and that the htp.h include file (which contains a reference to the external definition http_defmethods) is included. This parameter contains a table of operations, or request methods, to be performed by Metro IPWorks™ on the document requested by the client browser.
The current default operations include the following:
• POST
• GET
• HEAD
These methods can be overridden by replacing a default with another entry, or more meth-ods
can be added by adding entries to this structure.
The default methods are shown as follows:
const Http_Method http_defmethods[] =
{
{HTTP_GET, "GET", http_get },
{HTTP_HEAD, "HEAD", http_get },
{HTTP_POST, "POST", http_post },
{0, NULL, NULL },
};
For example, the user could replace the http_get function with a user function called http_myget by changing the HTTP_GET entry as follows:
HTTP_GET, “GET”, http_myget
-----------------------------------------------------------------------

And what I want to do is to repplace the http_get function with another function. Should be no problem according to the text above.
But in the htp.h file it looks like this:

...
typedef struct http_method {
int key;
char *name;
void (*method)(Http_Request *);
} Http_Method;

extern const Http_Method http_defmethods[];

How can I replace the {HTTP_GET, "GET", http_get} line?
Have tried with exhanging the 'extern const Http_Method http_defmethods[];' line with:
const Http_Method http_defmethods[] =
{
{HTTP_GET, "GET", otherfunc },
{HTTP_HEAD, "HEAD", http_get },
{HTTP_POST, "POST", http_post },
{0, NULL, NULL },
};
Without sucess. Probably because the functions otherfunc, http_get ... are declared in another headerfile that includes htp.h it really confusing.
If u managed to get through all this text please help me out.
 
> extern const Http_Method http_defmethods[];
This (as you know) tells you that it is declared elsewhere.

> const Http_Method http_defmethods[] =
Unless you can actually find and modify this array, simply defining it again probably wont work - multiple definition errors would probably be the result (though a well designed library would allow this).

If all you want is to override a single function, then doing this before calling the main http handler should suffice.
Code:
int i;
for ( i = 0 ; http_defmethods[i].key != 0 ; i++ ) {
  if ( http_defmethods[i].key == HTTP_GET ) {
    http_defmethods[i].method = other_func;
    break;
  }
}
if ( http_defmethods[i].key == 0 ) {
  // error - unable to find/replace GET handler
}

--
 
Yes offcourse, I solved it this morning, believe I was low on coffeine yesterday afternoon :)
 
Hi
I don't exactly need to reply to mojaffa but to ask him something about eZ80 and C Programming.

I was about to buy the eZ80L92 Zilog Kit, for a project.
As I had a look around towards Rabbit and PIC microncontrollers,
I thought that there was the "same" sort of O.S. included in the IDE
to make programming easier by implementing multitasking methods
(such as "costate" in rabbit within Dynamic C). At first sight this doesn't happen with eZ80 C-Programming Kit. (I don't know whether
the TCPIP libraries available for eZ80L9 Kit do use some multitasking
capabilities to exploit for no network projects because I haven't bought
the suite yet).

Then I run into this OpenEZ, which could be an even more valid alternative
(as I was looking at the documentation and the code I noticed the
familiar concepts like in VC regarding to the multithreading) but there were some troubles in implementing it within Zilog IDE.

Honestly I don't need the TCP capabilities at the moment for my
application but there could be the need in the future, and anyway
exploiting the benefits of this O.S., such cooperative taks would be
quite useful at any time.

Could you please me tell me about your experience with
C eZ80 and multitasking? Or any other links to something useful?

Thanks in advance.
------------------
Mr Michele Solazzi
m.solazzi@libero.it
ITALY

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top