forked from gitpan/CORBA-ORBit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extras.c
138 lines (115 loc) · 2.89 KB
/
extras.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* -*- mode: C; c-file-style: "bsd" -*- */
#include "extras.h"
static CORBA_Principal porbit_cookie = { 0, 0, NULL, CORBA_FALSE };
static gboolean
porbit_handle_connection(GIOChannel *source, GIOCondition cond,
GIOPConnection *cnx)
{
/* The best way to know about an fd exception is if select()/poll()
* tells you about it, so we just relay that information on to ORBit
* if possible
*/
if(cond & (G_IO_HUP|G_IO_NVAL|G_IO_ERR))
giop_main_handle_connection_exception(cnx);
else
giop_main_handle_connection(cnx);
return TRUE;
}
static void
porbit_add_connection(GIOPConnection *cnx)
{
int tag;
GIOChannel *channel;
channel = g_io_channel_unix_new(GIOP_CONNECTION_GET_FD(cnx));
tag = g_io_add_watch_full (channel, G_PRIORITY_DEFAULT,
G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
(GIOFunc)porbit_handle_connection,
cnx, NULL);
g_io_channel_unref (channel);
cnx->user_data = GUINT_TO_POINTER (tag);
}
static void
porbit_remove_connection(GIOPConnection *cnx)
{
g_source_remove(GPOINTER_TO_UINT (cnx->user_data));
cnx->user_data = GINT_TO_POINTER (-1);
}
void
porbit_set_use_gmain (gboolean set)
{
if (set)
{
IIOPAddConnectionHandler = porbit_add_connection;
IIOPRemoveConnectionHandler = porbit_remove_connection;
}
else
{
IIOPAddConnectionHandler = NULL;
IIOPRemoveConnectionHandler = NULL;
}
}
void
porbit_set_cookie (const char *cookie)
{
if (porbit_cookie._buffer)
g_free (porbit_cookie._buffer);
porbit_cookie._buffer = g_strdup (cookie);
porbit_cookie._length = strlen(cookie) + 1;
ORBit_set_default_principal(&porbit_cookie);
}
static ORBit_MessageValidationResult
porbit_request_validate(CORBA_unsigned_long request_id,
CORBA_Principal *principal,
CORBA_char *operation)
{
if (principal->_length == porbit_cookie._length &&
principal->_buffer[principal->_length - 1] == '\0' &&
strcmp(principal->_buffer, porbit_cookie._buffer) == 0)
return ORBIT_MESSAGE_ALLOW_ALL;
else
return ORBIT_MESSAGE_BAD;
}
void
porbit_set_check_cookies (gboolean set)
{
if (set)
ORBit_set_request_validation_handler (porbit_request_validate);
else
ORBit_set_request_validation_handler (NULL);
}
PORBitSource *
porbit_source_new (void)
{
PORBitSource *source = g_new (PORBitSource, 1);
source->ref_count = 1;
source->id = 0;
source->args = NULL;
return source;
}
PORBitSource *
porbit_source_ref (PORBitSource *source)
{
source->ref_count++;
return source;
}
void
porbit_source_unref (PORBitSource *source)
{
source->ref_count--;
if (source->ref_count == 0) {
if (source->id) {
warn ("0 refcount on an activate source!");
source->ref_count++;
} else {
g_free (source);
}
}
}
void
porbit_source_destroyed (PORBitSource *source)
{
source->id = 0;
SvREFCNT_dec ((SV *)source->args);
source->args = NULL;
porbit_source_unref (source);
}