diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2014-01-10 21:07:58 +0100 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@intersec.com> | 2014-01-18 13:46:58 +0100 |
commit | ff98ee6f9e66ba850274463ca7f125c01a02d73e (patch) | |
tree | 56b4075f92cd90d855ae05c4a92d193d03297c7e /callbacks.c | |
parent | c5b339e3964009d7eb917ff52e60ba69ff170c3c (diff) |
we need to access the opcode of the callbacks from outside of the server
(i.e. in the future clients).
the type callback_t is now a pointer to function and can be accessed
using callbacks_g[opcode] where the opcodes are enumerated in request.h
a new file named pub_callbacks.h has been added.
it will be used later by the client and must not be server dependant
closes #1
Diffstat (limited to 'callbacks.c')
-rw-r--r-- | callbacks.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/callbacks.c b/callbacks.c index e41fe8b..c0b6dce 100644 --- a/callbacks.c +++ b/callbacks.c @@ -16,20 +16,20 @@ CB(mute); extern FILE *stream_g; -typedef struct { - int opcode; - int (*cb)(const byte *, int); -} callback_t; - -static callback_t callbacks_g[] = { - {0, callback_load_url}, - {1, callback_pause}, - {2, callback_quit}, - {3, callback_snd_up}, - {4, callback_snd_down}, - {5, callback_fullscreen}, - {6, callback_mute}, -}; +static callback_t callbacks_g[CALLBACK_COUNT] = {NULL}; + +int callbacks_init(void) +{ + callbacks_g[CALLBACK_LOAD_URL] = callback_load_url; + callbacks_g[CALLBACK_PAUSE] = callback_pause; + callbacks_g[CALLBACK_QUIT] = callback_quit; + callbacks_g[CALLBACK_SND_DOWN] = callback_snd_down; + callbacks_g[CALLBACK_SND_UP] = callback_snd_up; + callbacks_g[CALLBACK_FULLSCREEN] = callback_fullscreen; + callbacks_g[CALLBACK_MUTE] = callback_mute; + + return 0; +} /* * returns a new malloced() null terminated escaped string @@ -40,10 +40,8 @@ char *real_escape_string(const byte *buf, int size); void *get_assoc_cb(int opcode) { - for (size_t i = 0; i < sizeof(callbacks_g) / sizeof(callbacks_g[0]); ++i) { - if (callbacks_g[i].opcode == opcode) { - return callbacks_g[i].cb; - } + if (opcode >= 0 && opcode < CALLBACK_COUNT) { + return callbacks_g[opcode]; } return NULL; |