This repository has been archived by the owner on Jan 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
msglog.c
172 lines (155 loc) · 3.83 KB
/
msglog.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
This file is part of telegram-purple
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
Copyright Matthias Jentsch 2014-2015
*/
#include <stdio.h>
#include <stdarg.h>
#include "telegram-purple.h"
/*
msglog.c: Convenience methods for logging to libpurple log
*/
void log_level_printf (const char* format, va_list ap, int level) {
char buffer[256];
vsnprintf (buffer, sizeof(buffer), format, ap);
int last = (int)strlen (buffer) - 1;
if (last >= 2 && buffer[last] == '\n') {
buffer[last] = '\0';
}
purple_debug (level, PLUGIN_ID, "%s\n", buffer);
}
void debug(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_MISC);
va_end (ap);
}
void info(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_INFO);
va_end (ap);
}
void warning(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_WARNING);
va_end (ap);
}
void failure(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_ERROR);
va_end (ap);
}
void fatal(const char* format, ...) {
va_list ap;
va_start (ap, format);
log_level_printf (format, ap, PURPLE_DEBUG_FATAL);
va_end (ap);
info ("\n");
}
const char *print_flags (const char **names, int len, unsigned flags) {
static char *text = NULL;
if (text) {
g_free (text);
text = NULL;
}
int i;
for (i = 0; i < len; i ++) {
if (flags & 1) {
char *new;
if (text) {
new = g_strconcat (text, " ", names[i], NULL);
g_free (text);
} else {
new = g_strdup (names[i]);
}
text = new;
}
flags >>= 1;
}
return (const char*)text;
}
const char *print_flags_peer (unsigned flags) {
const char *names[] = {
"CREATED",
"HAS_PHOTO",
"DELETED",
"OFFICIAL",
"KICKED",
"ADMIN",
"CREATOR",
"LEFT",
"DEACTIVATED"
};
return print_flags (names, 9, flags);
}
const char *print_flags_channel (unsigned flags) {
static char *text;
if (text) {
g_free (text);
text = NULL;
}
const char *names[] = {
"BROADCAST",
"EDITOR",
"MODERATOR",
"MEGAGROUP"
};
text = g_strdup (print_flags_peer (flags));
char *old = text;
text = g_strconcat (text, " ", print_flags (names, 4, flags >> 16), NULL);
g_free (old);
return text;
}
const char *print_flags_user (unsigned flags) {
static char *text;
if (text) {
g_free (text);
text = NULL;
}
const char *names[] = {
"CONTACT",
"MUTUAL_CONTACT",
"BLOCKED",
"SELF",
"BOT"
};
text = g_strdup (print_flags_peer (flags));
char *old = text;
text = g_strconcat (text, " ", print_flags (names, 5, flags >> 16), NULL);
g_free (old);
return text;
}
const char *print_flags_update (unsigned flags) {
const char *names[] = {
"CREATED",
"DELETED",
"PHONE",
"CONTACT",
"PHOTO",
"BLOCKED",
"REAL_NAME",
"NAME",
"REQUESTED",
"WORKING",
"FLAGS",
"TITLE",
"ADMIN",
"MEMBERS",
"ACCESS_HASH",
"USERNAME"
};
return print_flags (names, 16, flags);
}