Pointers are writing a messaging proxy in C

Y

Yan

I want to begin a project to write a proxy for instant messaging
protocols in C and make it posix compliant. I originally wanted to write
the proxy for one protocol, but not im thinking if i was to write one i
want to make it modular to handle a few. The platform of development
will be FreeBSD, but that's really neither here nor there. My question
is as follows:

- What packages/language features can I use to add this modularity?
- Make each protocol a dynamically linked library? (preferred i guess)
use libtool?
- What is the preferred (proper) way to parse data, exctract protocol
information (maybe assign each session a protocol based on
port/initialization packets) and then pass each packet to a handler?
Basically, how do i properly interface with each protocol handler?


Ive been a UNIX user for a few years, and a C rookie for a few as well,
and want to actually write something to progress my knowledge and gain
experience. Any help would be appreciated. I understand that the fact
that I will be writing this for unix or making it conform to posix is
irrelevant for this group, but i thought it might narrow down to what i
actually want to do.

thanks in advance
 
L

Lawrence Kirby

I want to begin a project to write a proxy for instant messaging
protocols in C and make it posix compliant. I originally wanted to write
the proxy for one protocol, but not im thinking if i was to write one i
want to make it modular to handle a few. The platform of development
will be FreeBSD, but that's really neither here nor there. My question
is as follows:

- What packages/language features can I use to add this modularity?

At the C language level you have things like functions, internal/external
linkage, separately compiled source files and headers.
- Make each protocol a dynamically linked library? (preferred i guess)
use libtool?

Possibly but that is an implementation detail, not something that the C
language itself covers. Since you mention POSIX and FreeBSD
comp.unix.programmer or a FreeBSD related newsgroup would be a good place
to discuss this.
- What is the preferred (proper) way to parse data, exctract protocol
information (maybe assign each session a protocol based on
port/initialization packets) and then pass each packet to a handler?

Sounds reasonable.
Basically, how do i properly interface with each protocol handler?

All you get in standard C is effectively a statically linked program. If
you want any more than that you have to use platform-specific extensions.
Ive been a UNIX user for a few years, and a C rookie for a few as well,
and want to actually write something to progress my knowledge and gain
experience. Any help would be appreciated. I understand that the fact
that I will be writing this for unix or making it conform to posix is
irrelevant for this group, but i thought it might narrow down to what i
actually want to do.

A good design approach is to hide the implementation details behind a
standardised interface. For example

struct {
int (*protofunc1)(int arg);
...
} Msgproto;


Msgproto *msgproto_open(const char *protoname);
void msgproto_close(Msgproto *proto);

I.e. msgproto_open() deals with the details of "opening" a protocol
whether that is implemented as a set of statically linked functions, open
a dynamic library or whatever. It returns a pointer to a Msgproto
structure which contains pointers to functions that implement the
protocol, and anything else relevant to a general protocol.
msgproto_close() cleans up when you have finished using the protocol. For
some implementations it may not need to do anything but it should still
be there for cases wher cleanup is necessary.

Lawrence
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top