1 /*
2  * interface.c
3  *
4  * by Nadeem Riaz (nads@bleh.org)
5  *
6  * Probably should be renamed misc.c (oh well)
7  */
8 
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <time.h>
12 #include "toc.h"
13 
14 int (*TOC_RAW_HANDLERS[30])(int, char *);
15 int (*TOC_HANDLERS[30])(int, char **);
16 
init_toc()17 void init_toc() {
18 	int x;
19 	groups = NULL;
20 	permit = NULL;
21 	deny = NULL;
22 	buddy_chats = NULL;
23 	invited_chats = NULL;
24 	strcpy(aim_host,TOC_HOST);
25 	aim_port = TOC_PORT;
26 	strcpy(login_host,AUTH_HOST);
27 	login_port = AUTH_PORT;
28 
29 	/* Init Handlers */
30 	for (x=0;x<30;x++)
31 		TOC_HANDLERS[x] = NULL;
32 	for (x=0;x<30;x++)
33 		TOC_RAW_HANDLERS[x] = NULL;
34 
35 }
36 
init_lists()37 void init_lists() {
38 	if ( groups == NULL ) {
39 		groups = (LL) CreateLL();
40 		SetFreeLLE(groups,&misc_free_group);
41 	}
42 	if ( permit == NULL )
43 		permit = (LL) CreateLL();
44 	if ( deny == NULL )
45 		deny = (LL) CreateLL();
46 	if ( buddy_chats == NULL ) {
47 		buddy_chats = CreateLL();
48 		SetFreeLLE(buddy_chats,&misc_free_buddy_chat);
49 	}
50 	if ( invited_chats == NULL ) {
51 		invited_chats = CreateLL();
52 		SetFreeLLE(invited_chats,&misc_free_invited_chats);
53 	}
54 }
55 
56 
install_handler(int type,int (* func)(int,char **))57 int install_handler(int type, int (*func)(int, char **)) {
58 	TOC_HANDLERS[type] = func;
59 	return 1;
60 }
61 
install_raw_handler(int type,int (* func)(int,char *))62 int install_raw_handler(int type, int (*func)(int, char *)) {
63 	TOC_RAW_HANDLERS[type] = func;
64 	return 1;
65 }
66 
67 
use_handler(int mode,int type,void * args)68 int use_handler(int mode,int type, void *args) {
69 	int ret = 0;
70 	toc_debug_printf("use_handler: mode = %d type = %d",mode,type);
71 	if ( mode == TOC_HANDLE ) {
72 		if ( TOC_HANDLERS[type] == NULL )
73 			toc_debug_printf("Error, no handler installed for %d type",type);
74 		else
75 			ret = TOC_HANDLERS[type](type, (char **) args);
76 	} else if ( mode == TOC_RAW_HANDLE ) {
77 		if ( TOC_RAW_HANDLERS[type] == NULL )
78 			toc_debug_printf("Error, no raw handler installed for %d type",type);
79 		else
80 			ret = TOC_RAW_HANDLERS[type](type, (char *) args);
81 	} else {
82 		toc_debug_printf("Error: %d : unkown handle mode!",mode);
83 		ret = -1;
84 	}
85 	return ret;
86 }
87