first cut of Object Notification API and tests
[cilux] / src / include / ni.h
1
2 #ifndef ni_H
3 #define ni_H
4
5 /* -------------------------------------------------------------------------- */
6
7 typedef struct n_object{
8         k_hashtable* headers;
9         k_hashtable* content;
10 } n_object;
11
12 PUBLIC n_object*    n_object_new(char* s);
13 PUBLIC void         n_commit(n_object* o);
14 PUBLIC n_object*    n_see(n_object* o, char* uid);
15 PUBLIC char*        n_to_string(n_object* o);
16 PUBLIC char*        n_uid(n_object* o);
17 PUBLIC char*        n_header(n_object* o, char* name);
18 PUBLIC k_hashtable* n_headers(n_object* o);
19 PUBLIC k_hashtable* n_content(n_object* o);
20
21 /* -------------------------------------------------------------------------- */
22
23 PUBLIC char* ni_hostname(void);
24 PUBLIC void  ni_hostname_set(char* name);
25
26 /* -------------------------------------------------------------------------- */
27
28 typedef struct ni_resource{
29         char*        uri;
30         k_hashtable* ent_head;
31         void*        entity;
32 } ni_resource;
33
34 PUBLIC ni_resource* ni_resource_new(char*        uri,
35                                     k_hashtable* ent_head,
36                                     char*        entity);
37 PUBLIC ni_resource* ni_resource_dup(   ni_resource* res);
38 PUBLIC void         ni_resource_delete(ni_resource* res);
39 PUBLIC void         ni_resource_show(  ni_resource* res, char* text);
40 PUBLIC ni_resource* ni_resource_get(char* uri);
41
42 /* -------------------------------------------------------------------------- */
43
44 typedef struct ni_event{
45         char*        uri;
46         k_hashtable* evt_head;
47         k_hashtable* ent_head;
48         void*        entity;
49 } ni_event;
50
51 PUBLIC ni_event* ni_event_new(char*        uri,
52                               k_hashtable* evt_head,
53                               k_hashtable* ent_head,
54                               char*        entity);
55 PUBLIC ni_event* ni_event_dup(   ni_event* res);
56 PUBLIC void      ni_event_delete(ni_event* res);
57 PUBLIC void      ni_event_show(  ni_event* res, char* text);
58
59 /* -------------------------------------------------------------------------- */
60
61 PUBLIC ni_event* ni_res_to_evt(ni_resource* res);
62
63 /* -------------------------------------------------------------------------- */
64
65 typedef int  (*ni_handles_resource)(char*);
66 typedef void (*ni_sync_resource   )(ni_resource*);
67
68 PUBLIC void ni_register_driver(char*               name,
69                                ni_handles_resource handles_resource,
70                                ni_sync_resource    sync_resource);
71
72 /* -------------------------------------------------------------------------- */
73
74 PUBLIC ni_event* ni_get_request_headers( char* header);
75 PUBLIC ni_event* ni_get_response_headers(char* header);
76 PUBLIC char*     ni_get_headers( char* header, k_hashtable*, k_hashtable*);
77 PUBLIC void      ni_fix_http_headers(k_hashtable* ent_head);
78 PUBLIC void      ni_fix_ni_headers(k_hashtable* ent_head, int methead);
79 PUBLIC void      ni_response(ni_event* evt,
80                              char*      to,
81                              char*      method,
82                              char*      protocol,
83                              char*      connection,
84                              k_channel* chan);
85 PUBLIC void      ni_request(ni_event* evt,
86                             char*      to,
87                             char*      method,
88                             k_channel* chan);
89
90 /* -------------------------------------------------------------------------- */
91
92 #endif
93