-
Notifications
You must be signed in to change notification settings - Fork 3
/
xep136_misc.c
150 lines (112 loc) · 3.21 KB
/
xep136_misc.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
139
140
141
142
143
144
145
146
147
148
/*
* xep136_misc.c
*/
#include "xep136_plugin.h"
#ifdef _WIN32
#include "libpurple/win32/libc_interface.h"
#endif
/*--------------------------------------------------------------------------------
* misc functions: increase_start_time, get_server_name, find_recipient, ...
*--------------------------------------------------------------------------------*/
/* increase start time by one second */
gchar *
increase_start_time(gchar *start)
{
gchar *new = NULL;
int i, c = 0;
new = (gchar *) g_malloc0( strlen(start) * sizeof(gchar) );
if (!new) {
purple_debug_error(PLUGIN_ID, "ERROR: g_malloc0 new increase_start_time\n");
return start;
}
for (i = 0; i < strlen(start); i++) {
if (i == 18) {
c = (int) start[i];
c++;
new[i] = (char) c;
} else {
new[i] = start[i];
}
}
return new;
}
/* return friend's username (jid) from conversation */
gchar *
get_friend_username(PidginConversation *gtkconv)
{
PurpleConversation *conv = gtkconv->active_conv;
if (!conv)
return NULL;
return conv->name;
}
/* return user's username (jid) from PurpleAccount */
gchar *
get_my_username(PidginConversation *gtkconv)
{
PurpleConversation *purple_conv = gtkconv->active_conv;
PurpleAccount *acc = purple_conv->account;
char *username= acc->username;
gchar *my_username = NULL;;
gchar *lom = NULL; //pointer to '/'
glong dlzka = 0;
if (!acc)
return NULL;
dlzka = g_utf8_strlen(username, -1);
lom = g_strstr_len(username, dlzka, "/");
if (lom != NULL) {
dlzka = dlzka - g_utf8_strlen(lom, -1);
}
my_username = (gchar *) g_malloc0( (dlzka + 1) * sizeof(gchar) );
g_strlcat (my_username, username, dlzka + 1);
return my_username;
}
/* return server name from users's jid from PurpleAccount */
gchar *
get_server_name(PidginConversation *gtkconv)
{
PurpleConversation *purple_conv = gtkconv->active_conv;
PurpleAccount *acc = purple_conv->account;
char *username= acc->username;
gchar *server = NULL;
gchar *zav = NULL; //pointer to '@'
gchar *lom = NULL; //pointer to '/'
glong dlzka = g_utf8_strlen(username, -1);
zav = g_strstr_len(username, dlzka, "@");
lom = g_strstr_len(username, dlzka, "/");
zav++;
if (lom == NULL)
{
dlzka = g_utf8_strlen(zav, -1);
} else {
dlzka = g_utf8_strlen(zav, -1) - g_utf8_strlen(lom, -1);
}
server = (gchar *) g_malloc0( (dlzka + 1) * sizeof(gchar) );
g_strlcat (server, zav, dlzka + 1);
return server;
}
/* find users match from xmpp message id */
void
find_recipient(WindowStruct *curr, Recipient_info *recipient)
{
/* end if already matched */
if (recipient->match == TRUE)
return;
//purple_debug_misc(PLUGIN_ID, "find_recipient :: curr->id=%s recipient->id=%s\n", curr->id, recipient->id);
if (strcmp(curr->id, recipient->id) == 0) {
recipient->match = TRUE;
explore_xml(curr, recipient->xml);
}
}
/* return current year as int */
int
get_curr_year(void)
{
struct tm curr_time;
time_t raw;
int year;
time(&raw);
localtime_r(&raw, &curr_time);
year = (int) (1900 + (int) curr_time.tm_year);
//purple_debug_misc(PLUGIN_ID, "get_curr_year :: %d\n", year);
return year;
}