4 * (C) Copyright 2009 Jakub Zawadzki <darkjames@darkjames.ath.cx>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License Version
8 * 2.1 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
21 #ifndef LIBGADU_INTERNAL_H
22 #define LIBGADU_INTERNAL_H
26 #define GG_DEFAULT_CLIENT_VERSION_100 "10.1.0.11070"
27 #define GG_DEFAULT_CLIENT_VERSION_110 "11.3.45.10771"
31 # define GG_SIZE_FMT "lu"
32 # define _GG_INT64_MODIFIER "ll"
37 # define GG_SIZE_FMT "Iu"
38 # define _GG_INT64_MODIFIER "I64"
41 # define GG_SIZE_FMT "zu"
42 # define _GG_INT64_MODIFIER "l"
44 # define GG_SIZE_FMT "zu"
45 # define _GG_INT64_MODIFIER "ll"
49 # define PRIu64 _GG_INT64_MODIFIER "u"
52 # define PRIx64 _GG_INT64_MODIFIER "x"
55 # define PRId64 _GG_INT64_MODIFIER "d"
58 #define GG_LOGIN_PARAMS_HAS_FIELD(glp, member) \
59 (offsetof(struct gg_login_params, member) < (glp)->struct_size || \
60 offsetof(struct gg_login_params, member) <= offsetof(struct gg_login_params, struct_size))
63 # define GG_UNUSED __attribute__ ((unused))
64 # define GG_NORETURN __attribute__ ((noreturn))
65 # define GG_CDECL __attribute__ ((__cdecl__))
72 #define GG_STATIC_ASSERT(condition, message) \
73 { typedef char static_assertion_failed_ ## message \
74 [(condition) ? 1 : -1]; static_assertion_failed_ ## message dummy; \
77 #define GG_IMGOUT_WAITING_MAX 4
79 struct gg_dcc7_relay
{
85 typedef struct _gg_chat_list gg_chat_list_t
;
86 struct _gg_chat_list
{
89 uint32_t participants_count
;
95 typedef struct _gg_msg_list gg_msg_list_t
;
99 size_t recipients_count
;
104 typedef struct _gg_eventqueue gg_eventqueue_t
;
105 struct _gg_eventqueue
{
106 struct gg_event
*event
;
108 gg_eventqueue_t
*next
;
111 typedef struct _gg_imgout_queue_t gg_imgout_queue_t
;
112 struct _gg_imgout_queue_t
{
113 struct gg_send_msg msg_hdr
;
117 gg_imgout_queue_t
*next
;
120 struct gg_session_private
{
121 gg_compat_t compatibility
;
123 gg_chat_list_t
*chat_list
;
124 gg_msg_list_t
*sent_messages
;
126 gg_eventqueue_t
*event_queue
;
127 int check_after_queue
;
130 gg_imgout_queue_t
*imgout_queue
;
131 int imgout_waiting_ack
;
133 gg_socket_manager_type_t socket_manager_type
;
134 gg_socket_manager_t socket_manager
;
136 int socket_next_state
;
137 int socket_is_external
;
138 enum gg_failure_t socket_failure
;
142 int dummyfds_created
;
145 char **host_white_list
;
150 GG_COMPAT_FEATURE_ACK_EVENT
,
151 GG_COMPAT_FEATURE_LEGACY_CONFER
152 } gg_compat_feature_t
;
154 typedef struct gg_dcc7_relay gg_dcc7_relay_t
;
156 void * gg_new0(size_t size
);
157 int gg_required_proto(struct gg_session
*gs
, int protocol_version
);
158 int gg_get_dummy_fd(struct gg_session
*sess
);
160 int gg_compat_feature_is_enabled(struct gg_session
*sess
, gg_compat_feature_t feature
);
162 int gg_pubdir50_handle_reply_sess(struct gg_session
*sess
, struct gg_event
*e
, const char *packet
, int length
);
164 int gg_resolve(int *fd
, int *pid
, const char *hostname
);
165 int gg_resolve_pthread(int *fd
, void **resolver
, const char *hostname
);
166 void gg_resolve_pthread_cleanup(void *resolver
, int kill
);
168 int gg_login_hash_sha1_2(const char *password
, uint32_t seed
, uint8_t *result
);
170 int gg_chat_update(struct gg_session
*sess
, uint64_t id
, uint32_t version
,
171 const uin_t
*participants
, unsigned int participants_count
);
172 gg_chat_list_t
*gg_chat_find(struct gg_session
*sess
, uint64_t id
);
174 uin_t
gg_str_to_uin(const char *str
, int len
);
176 uint64_t gg_fix64(uint64_t x
);
177 void gg_connection_failure(struct gg_session
*gs
, struct gg_event
*ge
,
178 enum gg_failure_t failure
);
180 time_t gg_server_time(struct gg_session
*gs
);
182 int gg_session_init_ssl(struct gg_session
*gs
);
183 void gg_close(struct gg_session
*gs
);
185 struct gg_event
*gg_eventqueue_add(struct gg_session
*sess
);
187 void gg_compat_message_ack(struct gg_session
*sess
, int seq
);
189 void gg_image_sendout(struct gg_session
*sess
);
191 void gg_strarr_free(char **strarr
);
192 char ** gg_strarr_dup(char **strarr
);
202 uint8_t original
[12];
207 } gg_win32_hook_data_t
;
209 #define gg_win32_hook(orig_func, hook_func, data) \
210 gg_win32_hook_f((void (*)())(orig_func), (void (*)())(hook_func), (data))
213 gg_win32_hook_f(void (*orig_func
)(), void (*hook_func
)(), gg_win32_hook_data_t
*data
)
218 0x48, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, /* mov rax, uint64_t */
219 0xff, 0xe0 /* jmp rax */
221 0xB8, 0, 0, 0, 0, /* mov eax, uint32_t */
222 0xff, 0xe0 /* jmp eax */
227 uint64_t addr
= (uint64_t)hook_func
;
228 memcpy(&trap
[2], &addr
, sizeof(addr
));
230 uint32_t addr
= (uint32_t)hook_func
;
231 memcpy(&trap
[1], &addr
, sizeof(addr
));
234 VirtualProtect(orig_func
, sizeof(trap
),
235 PAGE_EXECUTE_READWRITE
, &dPermission
);
237 data
->fnc
= orig_func
;
238 memcpy(data
->trap
, trap
, sizeof(trap
));
239 memcpy(data
->original
, orig_func
, sizeof(trap
));
241 memcpy(orig_func
, trap
, sizeof(trap
));
242 VirtualProtect(orig_func
, sizeof(trap
),
243 dPermission
, &dPermission
);
247 gg_win32_hook_set_enabled(gg_win32_hook_data_t
*data
, int enabled
)
255 src
= data
->original
;
257 VirtualProtect(data
->fnc
, sizeof(data
->trap
),
258 PAGE_EXECUTE_READWRITE
, &dPermission
);
259 memcpy(data
->fnc
, src
, sizeof(data
->trap
));
260 VirtualProtect(data
->fnc
, sizeof(data
->trap
),
261 dPermission
, &dPermission
);
266 #endif /* LIBGADU_INTERNAL_H */