1 #ifndef __PERL_COMMON_H
2 #define __PERL_COMMON_H
3 
4 /* helper defines */
5 #define new_pv(a) \
6 	(newSVpv((a) == NULL ? "" : (a), (a) == NULL ? 0 : strlen(a)))
7 
8 #define is_hvref(o) \
9 	((o) && SvROK(o) && SvRV(o) && (SvTYPE(SvRV(o)) == SVt_PVHV))
10 
11 #define hvref(o) \
12 	(is_hvref(o) ? (HV *)SvRV(o) : NULL)
13 
14 typedef void (*PERL_OBJECT_FUNC) (HV *hv, void *object);
15 
16 typedef struct {
17 	char *name;
18         PERL_OBJECT_FUNC fill_func;
19 } PLAIN_OBJECT_INIT_REC;
20 
21 /* Returns the package who called us */
22 const char *perl_get_package(void);
23 /* Parses the package part from function name */
24 char *perl_function_get_package(const char *function);
25 /* If SV is a string, prefix it with given package.
26    Increases the reference counter for the return value. */
27 SV *perl_func_sv_inc(SV *func, const char *package);
28 
29 #ifndef pTHX_
30 #  define pTHX_
31 #endif
32 
33 #ifndef aTHX_
34 #  define aTHX_
35 #endif
36 
37 #define iobject_bless(object) \
38 	((object) == NULL ? &PL_sv_undef : \
39 	irssi_bless_iobject((object)->type, (object)->chat_type, object))
40 
41 #define simple_iobject_bless(object) \
42 	((object) == NULL ? &PL_sv_undef : \
43 	irssi_bless_iobject((object)->type, 0, object))
44 
45 #define plain_bless(object, stash) \
46 	((object) == NULL ? &PL_sv_undef : \
47 	irssi_bless_plain(stash, object))
48 
49 SV *irssi_bless_iobject(int type, int chat_type, void *object);
50 SV *irssi_bless_plain(const char *stash, void *object);
51 int irssi_is_ref_object(SV *o);
52 void *irssi_ref_object(SV *o);
53 
54 void irssi_add_object(int type, int chat_type, const char *stash,
55 		      PERL_OBJECT_FUNC func);
56 void irssi_add_plain(const char *stash, PERL_OBJECT_FUNC func);
57 void irssi_add_plains(PLAIN_OBJECT_INIT_REC *objects);
58 
59 char *perl_get_use_list(void);
60 
61 void perl_command(const char *cmd, SERVER_REC *server, WI_ITEM_REC *item);
62 
63 void perl_chatnet_fill_hash(HV *hv, CHATNET_REC *chatnet);
64 void perl_connect_fill_hash(HV *hv, SERVER_CONNECT_REC *conn);
65 void perl_server_fill_hash(HV *hv, SERVER_REC *server);
66 void perl_window_item_fill_hash(HV *hv, WI_ITEM_REC *item);
67 void perl_channel_fill_hash(HV *hv, CHANNEL_REC *channel);
68 void perl_query_fill_hash(HV *hv, QUERY_REC *query);
69 void perl_nick_fill_hash(HV *hv, NICK_REC *nick);
70 
71 #define irssi_boot(x) { \
72 	extern void boot_Irssi__##x(pTHX_ CV *cv); \
73 	irssi_callXS(boot_Irssi__##x, cv, mark); \
74 	}
75 void irssi_callXS(void (*subaddr)(pTHX_ CV* cv), CV *cv, SV **mark);
76 
77 void perl_common_start(void);
78 void perl_common_stop(void);
79 
80 #endif
81