Thu, 08 Jul 2004 17:37:33 +0000
[gaim-migrate @ 10312]
whitespace
| 8849 | 1 | /* |
| 2 | ||
| 3 | silcgaim_util.c | |
| 4 | ||
| 5 | Author: Pekka Riikonen <priikone@silcnet.org> | |
| 6 | ||
| 7 | Copyright (C) 2004 Pekka Riikonen | |
| 8 | ||
| 9 | This program is free software; you can redistribute it and/or modify | |
| 10 | it under the terms of the GNU General Public License as published by | |
| 11 | the Free Software Foundation; version 2 of the License. | |
| 12 | ||
| 13 | This program is distributed in the hope that it will be useful, | |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | GNU General Public License for more details. | |
| 17 | ||
| 18 | */ | |
| 19 | ||
| 20 | #include "silcincludes.h" | |
| 21 | #include "silcclient.h" | |
| 22 | #include "silcgaim.h" | |
| 23 | ||
| 24 | /**************************** Utility Routines *******************************/ | |
| 25 | ||
| 26 | static char str[256], str2[256]; | |
| 27 | ||
| 28 | const char *silcgaim_silcdir(void) | |
| 29 | { | |
| 30 | const char *hd = gaim_home_dir(); | |
| 31 | memset(str, 0, sizeof(str)); | |
| 32 | g_snprintf(str, sizeof(str) - 1, "%s" G_DIR_SEPARATOR_S ".silc", hd ? hd : "/tmp"); | |
| 33 | return (const char *)str; | |
| 34 | } | |
| 35 | ||
| 36 | const char *silcgaim_session_file(const char *account) | |
| 37 | { | |
| 38 | memset(str2, 0, sizeof(str2)); | |
| 39 | g_snprintf(str2, sizeof(str2) - 1, "%s" G_DIR_SEPARATOR_S "%s_session", | |
| 40 | silcgaim_silcdir(), account); | |
| 41 | return (const char *)str2; | |
| 42 | } | |
| 43 | ||
| 44 | gboolean silcgaim_ip_is_private(const char *ip) | |
| 45 | { | |
| 46 | if (silc_net_is_ip4(ip)) { | |
| 47 | if (!strncmp(ip, "10.", 3)) { | |
| 48 | return TRUE; | |
| 49 | } else if (!strncmp(ip, "172.", 4) && strlen(ip) > 6) { | |
| 50 | char tmp[3]; | |
| 8910 | 51 | int s; |
| 8849 | 52 | memset(tmp, 0, sizeof(tmp)); |
| 53 | strncpy(tmp, ip + 4, 2); | |
| 8910 | 54 | s = atoi(tmp); |
| 8849 | 55 | if (s >= 16 && s <= 31) |
| 56 | return TRUE; | |
| 57 | } else if (!strncmp(ip, "192.168.", 8)) { | |
| 58 | return TRUE; | |
| 59 | } | |
| 60 | } | |
| 61 | ||
| 62 | return FALSE; | |
| 63 | } | |
| 64 | ||
| 65 | /* This checks stats for various SILC files and directories. First it | |
| 66 | checks if ~/.silc directory exist and is owned by the correct user. If | |
| 67 | it doesn't exist, it will create the directory. After that it checks if | |
| 68 | user's Public and Private key files exists and creates them if needed. */ | |
| 69 | ||
| 70 | gboolean silcgaim_check_silc_dir(GaimConnection *gc) | |
| 71 | { | |
| 72 | char filename[256], file_public_key[256], file_private_key[256]; | |
| 73 | char servfilename[256], clientfilename[256], friendsfilename[256]; | |
| 74 | struct stat st; | |
| 75 | struct passwd *pw; | |
| 76 | ||
| 77 | pw = getpwuid(getuid()); | |
| 78 | if (!pw) { | |
| 9272 | 79 | gaim_debug_error("silc", "silc: %s\n", strerror(errno)); |
| 8849 | 80 | return FALSE; |
| 81 | } | |
| 82 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
83 | g_snprintf(filename, sizeof(filename) - 1, "%s", silcgaim_silcdir()); |
| 8849 | 84 | g_snprintf(servfilename, sizeof(servfilename) - 1, "%s" G_DIR_SEPARATOR_S "serverkeys", |
| 85 | silcgaim_silcdir()); | |
| 86 | g_snprintf(clientfilename, sizeof(clientfilename) - 1, "%s" G_DIR_SEPARATOR_S "clientkeys", | |
| 87 | silcgaim_silcdir()); | |
| 88 | g_snprintf(friendsfilename, sizeof(friendsfilename) - 1, "%s" G_DIR_SEPARATOR_S "friends", | |
| 89 | silcgaim_silcdir()); | |
| 90 | ||
| 91 | /* | |
| 92 | * Check ~/.silc directory | |
| 93 | */ | |
| 94 | if ((stat(filename, &st)) == -1) { | |
| 95 | /* If dir doesn't exist */ | |
| 96 | if (errno == ENOENT) { | |
| 97 | if (pw->pw_uid == geteuid()) { | |
| 98 | if ((mkdir(filename, 0755)) == -1) { | |
| 9272 | 99 | gaim_debug_error("silc", "Couldn't create '%s' directory\n", filename); |
| 8849 | 100 | return FALSE; |
| 101 | } | |
| 102 | } else { | |
| 9272 | 103 | gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 8849 | 104 | filename); |
| 105 | return FALSE; | |
| 106 | } | |
| 107 | } else { | |
| 9272 | 108 | gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", filename, strerror(errno)); |
| 8849 | 109 | return FALSE; |
| 110 | } | |
| 111 | } else { | |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
112 | #ifndef _WIN32 |
| 8849 | 113 | /* Check the owner of the dir */ |
| 114 | if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
| 9272 | 115 | gaim_debug_error("silc", "You don't seem to own '%s' directory\n", |
| 8849 | 116 | filename); |
| 117 | return FALSE; | |
| 118 | } | |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
119 | #endif |
| 8849 | 120 | } |
| 121 | ||
| 122 | /* | |
| 123 | * Check ~./silc/serverkeys directory | |
| 124 | */ | |
| 125 | if ((stat(servfilename, &st)) == -1) { | |
| 126 | /* If dir doesn't exist */ | |
| 127 | if (errno == ENOENT) { | |
| 128 | if (pw->pw_uid == geteuid()) { | |
| 129 | if ((mkdir(servfilename, 0755)) == -1) { | |
| 9272 | 130 | gaim_debug_error("silc", "Couldn't create '%s' directory\n", servfilename); |
| 8849 | 131 | return FALSE; |
| 132 | } | |
| 133 | } else { | |
| 9272 | 134 | gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 8849 | 135 | servfilename); |
| 136 | return FALSE; | |
| 137 | } | |
| 138 | } else { | |
| 9272 | 139 | gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
| 140 | servfilename, strerror(errno)); | |
| 8849 | 141 | return FALSE; |
| 142 | } | |
| 143 | } | |
| 144 | ||
| 145 | /* | |
| 146 | * Check ~./silc/clientkeys directory | |
| 147 | */ | |
| 148 | if ((stat(clientfilename, &st)) == -1) { | |
| 149 | /* If dir doesn't exist */ | |
| 150 | if (errno == ENOENT) { | |
| 151 | if (pw->pw_uid == geteuid()) { | |
| 152 | if ((mkdir(clientfilename, 0755)) == -1) { | |
| 9272 | 153 | gaim_debug_error("silc", "Couldn't create '%s' directory\n", clientfilename); |
| 8849 | 154 | return FALSE; |
| 155 | } | |
| 156 | } else { | |
| 9272 | 157 | gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 8849 | 158 | clientfilename); |
| 159 | return FALSE; | |
| 160 | } | |
| 161 | } else { | |
| 9272 | 162 | gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
| 163 | clientfilename, strerror(errno)); | |
| 8849 | 164 | return FALSE; |
| 165 | } | |
| 166 | } | |
| 167 | ||
| 168 | /* | |
| 169 | * Check ~./silc/friends directory | |
| 170 | */ | |
| 171 | if ((stat(friendsfilename, &st)) == -1) { | |
| 172 | /* If dir doesn't exist */ | |
| 173 | if (errno == ENOENT) { | |
| 174 | if (pw->pw_uid == geteuid()) { | |
| 175 | if ((mkdir(friendsfilename, 0755)) == -1) { | |
| 9272 | 176 | gaim_debug_error("silc", "Couldn't create '%s' directory\n", friendsfilename); |
| 8849 | 177 | return FALSE; |
| 178 | } | |
| 179 | } else { | |
| 9272 | 180 | gaim_debug_error("silc", "Couldn't create '%s' directory due to a wrong uid!\n", |
| 8849 | 181 | friendsfilename); |
| 182 | return FALSE; | |
| 183 | } | |
| 184 | } else { | |
| 9272 | 185 | gaim_debug_error("silc", "Couldn't stat '%s' directory, error: %s\n", |
| 186 | friendsfilename, strerror(errno)); | |
| 8849 | 187 | return FALSE; |
| 188 | } | |
| 189 | } | |
| 190 | ||
| 191 | /* | |
| 192 | * Check Public and Private keys | |
| 193 | */ | |
| 194 | g_snprintf(file_public_key, sizeof(file_public_key) - 1, "%s", | |
| 195 | gaim_prefs_get_string("/plugins/prpl/silc/pubkey")); | |
| 196 | g_snprintf(file_private_key, sizeof(file_public_key) - 1, "%s", | |
| 197 | gaim_prefs_get_string("/plugins/prpl/silc/privkey")); | |
| 198 | ||
| 199 | if ((stat(file_public_key, &st)) == -1) { | |
| 200 | /* If file doesn't exist */ | |
| 201 | if (errno == ENOENT) { | |
| 202 | gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); | |
| 203 | silc_create_key_pair(SILCGAIM_DEF_PKCS, | |
| 204 | SILCGAIM_DEF_PKCS_LEN, | |
| 205 | file_public_key, file_private_key, NULL, | |
| 9272 | 206 | (gc->account->password == NULL) ? "" : gc->account->password, |
| 207 | NULL, NULL, NULL, FALSE); | |
| 208 | stat(file_public_key, &st); | |
| 8849 | 209 | } else { |
| 9272 | 210 | gaim_debug_error("silc", "Couldn't stat '%s' public key, error: %s\n", |
| 211 | file_public_key, strerror(errno)); | |
| 8849 | 212 | return FALSE; |
| 213 | } | |
| 214 | } | |
| 215 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
216 | #ifndef _WIN32 |
| 8849 | 217 | /* Check the owner of the public key */ |
| 218 | if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
| 9272 | 219 | gaim_debug_error("silc", "You don't seem to own your public key!?\n"); |
| 8849 | 220 | return FALSE; |
| 221 | } | |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
222 | #endif |
| 8849 | 223 | |
| 224 | if ((stat(file_private_key, &st)) == -1) { | |
| 225 | /* If file doesn't exist */ | |
| 226 | if (errno == ENOENT) { | |
| 227 | gaim_connection_update_progress(gc, _("Creating SILC key pair..."), 1, 5); | |
| 228 | silc_create_key_pair(SILCGAIM_DEF_PKCS, | |
| 229 | SILCGAIM_DEF_PKCS_LEN, | |
| 230 | file_public_key, file_private_key, NULL, | |
| 9272 | 231 | (gc->account->password == NULL) ? "" : gc->account->password, |
| 232 | NULL, NULL, NULL, FALSE); | |
| 233 | stat(file_private_key, &st); | |
| 8849 | 234 | } else { |
| 9272 | 235 | gaim_debug_error("silc", "Couldn't stat '%s' private key, error: %s\n", |
| 236 | file_private_key, strerror(errno)); | |
| 8849 | 237 | return FALSE; |
| 238 | } | |
| 239 | } | |
| 240 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
241 | #ifndef _WIN32 |
| 8849 | 242 | /* Check the owner of the private key */ |
| 243 | if (st.st_uid != 0 && st.st_uid != pw->pw_uid) { | |
| 9272 | 244 | gaim_debug_error("silc", "You don't seem to own your private key!?\n"); |
| 8849 | 245 | return FALSE; |
| 246 | } | |
| 247 | ||
| 248 | /* Check the permissions for the private key */ | |
| 249 | if ((st.st_mode & 0777) != 0600) { | |
| 9272 | 250 | gaim_debug_warning("silc", "Wrong permissions in your private key file `%s'!\n" |
| 8849 | 251 | "Trying to change them ... ", file_private_key); |
| 252 | if ((chmod(file_private_key, 0600)) == -1) { | |
| 9272 | 253 | gaim_debug_error("silc", |
| 8849 | 254 | "Failed to change permissions for private key file!\n" |
| 255 | "Permissions for your private key file must be 0600.\n"); | |
| 256 | return FALSE; | |
| 257 | } | |
| 9272 | 258 | gaim_debug_warning("silc", "Done.\n\n"); |
| 8849 | 259 | } |
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
260 | #endif |
| 8849 | 261 | |
| 262 | return TRUE; | |
| 263 | } | |
| 264 | ||
|
9353
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
265 | #ifdef _WIN32 |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
266 | struct passwd *getpwuid(uid_t uid) { |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
267 | struct passwd *pwd = calloc(1, sizeof(struct passwd)); |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
268 | return pwd; |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
269 | } |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
270 | |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
271 | uid_t getuid() { |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
272 | return 0; |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
273 | } |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
274 | |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
275 | uid_t geteuid() { |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
276 | return 0; |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
277 | } |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
278 | #endif |
|
ff6546387358
[gaim-migrate @ 10161]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9274
diff
changeset
|
279 | |
| 8849 | 280 | void silcgaim_show_public_key(SilcGaim sg, |
| 281 | const char *name, SilcPublicKey public_key, | |
| 282 | GCallback callback, void *context) | |
| 283 | { | |
| 284 | SilcPublicKeyIdentifier ident; | |
| 285 | SilcPKCS pkcs; | |
| 286 | char *fingerprint, *babbleprint; | |
| 287 | unsigned char *pk; | |
| 288 | SilcUInt32 pk_len, key_len = 0; | |
| 289 | GString *s; | |
| 290 | char *buf; | |
| 291 | ||
| 292 | ident = silc_pkcs_decode_identifier(public_key->identifier); | |
| 293 | if (!ident) | |
| 294 | return; | |
| 295 | ||
| 296 | pk = silc_pkcs_public_key_encode(public_key, &pk_len); | |
| 297 | fingerprint = silc_hash_fingerprint(NULL, pk, pk_len); | |
| 298 | babbleprint = silc_hash_babbleprint(NULL, pk, pk_len); | |
| 299 | ||
| 300 | if (silc_pkcs_alloc(public_key->name, &pkcs)) { | |
| 301 | key_len = silc_pkcs_public_key_set(pkcs, public_key); | |
| 302 | silc_pkcs_free(pkcs); | |
| 303 | } | |
| 304 | ||
| 305 | s = g_string_new(""); | |
| 306 | if (ident->realname) | |
| 9274 | 307 | /* Hint for translators: Please check the tabulator width here and in |
| 308 | the next strings (short strings: 2 tabs, longer strings 1 tab, | |
| 309 | sum: 3 tabs or 24 characters) */ | |
| 310 | g_string_append_printf(s, _("Real Name: \t%s\n"), ident->realname); | |
| 8849 | 311 | if (ident->username) |
| 9274 | 312 | g_string_append_printf(s, _("User Name: \t%s\n"), ident->username); |
| 8849 | 313 | if (ident->email) |
| 9274 | 314 | g_string_append_printf(s, _("EMail: \t\t%s\n"), ident->email); |
| 8849 | 315 | if (ident->host) |
| 9274 | 316 | g_string_append_printf(s, _("Host Name: \t%s\n"), ident->host); |
| 8849 | 317 | if (ident->org) |
| 9274 | 318 | g_string_append_printf(s, _("Organization: \t%s\n"), ident->org); |
| 8849 | 319 | if (ident->country) |
| 9274 | 320 | g_string_append_printf(s, _("Country: \t%s\n"), ident->country); |
| 321 | g_string_append_printf(s, _("Algorithm: \t\t%s\n"), public_key->name); | |
| 322 | g_string_append_printf(s, _("Key Length: \t%d bits\n"), (int)key_len); | |
| 323 | g_string_append_printf(s, "\n"); | |
| 324 | g_string_append_printf(s, _("Public Key Fingerprint:\n%s\n\n"), fingerprint); | |
| 325 | g_string_append_printf(s, _("Public Key Babbleprint:\n%s"), babbleprint); | |
| 8849 | 326 | |
| 327 | buf = g_string_free(s, FALSE); | |
| 328 | ||
| 329 | gaim_request_action(NULL, _("Public Key Information"), | |
| 330 | _("Public Key Information"), | |
| 331 | buf, 0, context, 1, | |
| 332 | _("Close"), callback); | |
| 333 | ||
| 334 | g_free(buf); | |
| 335 | silc_free(fingerprint); | |
| 336 | silc_free(babbleprint); | |
| 337 | silc_free(pk); | |
| 338 | silc_pkcs_free_identifier(ident); | |
| 339 | } | |
| 340 | ||
| 341 | SilcAttributePayload | |
| 342 | silcgaim_get_attr(SilcDList attrs, SilcAttribute attribute) | |
| 343 | { | |
| 344 | SilcAttributePayload attr = NULL; | |
| 345 | ||
| 346 | if (!attrs) | |
| 347 | return NULL; | |
| 348 | ||
| 349 | silc_dlist_start(attrs); | |
| 350 | while ((attr = silc_dlist_get(attrs)) != SILC_LIST_END) | |
| 351 | if (attribute == silc_attribute_get_attribute(attr)) | |
| 352 | break; | |
| 353 | ||
| 354 | return attr; | |
| 355 | } | |
| 356 | ||
| 357 | void silcgaim_get_umode_string(SilcUInt32 mode, char *buf, | |
| 358 | SilcUInt32 buf_size) | |
| 359 | { | |
| 360 | memset(buf, 0, buf_size); | |
| 361 | if ((mode & SILC_UMODE_SERVER_OPERATOR) || | |
| 362 | (mode & SILC_UMODE_ROUTER_OPERATOR)) { | |
| 363 | strcat(buf, (mode & SILC_UMODE_SERVER_OPERATOR) ? | |
| 364 | "[server operator] " : | |
| 365 | (mode & SILC_UMODE_ROUTER_OPERATOR) ? | |
| 366 | "[SILC operator] " : "[unknown mode] "); | |
| 367 | } | |
| 368 | if (mode & SILC_UMODE_GONE) | |
| 369 | strcat(buf, "[away] "); | |
| 370 | if (mode & SILC_UMODE_INDISPOSED) | |
| 371 | strcat(buf, "[indisposed] "); | |
| 372 | if (mode & SILC_UMODE_BUSY) | |
| 373 | strcat(buf, "[busy] "); | |
| 374 | if (mode & SILC_UMODE_PAGE) | |
| 375 | strcat(buf, "[wake me up] "); | |
| 376 | if (mode & SILC_UMODE_HYPER) | |
| 377 | strcat(buf, "[hyperactive] "); | |
| 378 | if (mode & SILC_UMODE_ROBOT) | |
| 379 | strcat(buf, "[robot] "); | |
| 380 | if (mode & SILC_UMODE_ANONYMOUS) | |
| 381 | strcat(buf, "[anonymous] "); | |
| 382 | if (mode & SILC_UMODE_BLOCK_PRIVMSG) | |
| 383 | strcat(buf, "[blocks private messages] "); | |
| 384 | if (mode & SILC_UMODE_DETACHED) | |
| 385 | strcat(buf, "[detached] "); | |
| 386 | if (mode & SILC_UMODE_REJECT_WATCHING) | |
| 387 | strcat(buf, "[rejects watching] "); | |
| 388 | if (mode & SILC_UMODE_BLOCK_INVITE) | |
| 389 | strcat(buf, "[blocks invites] "); | |
| 390 | } | |
| 391 | ||
| 392 | void silcgaim_get_chmode_string(SilcUInt32 mode, char *buf, | |
| 393 | SilcUInt32 buf_size) | |
| 394 | { | |
| 395 | memset(buf, 0, buf_size); | |
| 396 | if (mode & SILC_CHANNEL_MODE_FOUNDER_AUTH) | |
| 397 | strcat(buf, "[permanent] "); | |
| 398 | if (mode & SILC_CHANNEL_MODE_PRIVATE) | |
| 399 | strcat(buf, "[private] "); | |
| 400 | if (mode & SILC_CHANNEL_MODE_SECRET) | |
| 401 | strcat(buf, "[secret] "); | |
| 402 | if (mode & SILC_CHANNEL_MODE_SECRET) | |
| 403 | strcat(buf, "[secret] "); | |
| 404 | if (mode & SILC_CHANNEL_MODE_PRIVKEY) | |
| 405 | strcat(buf, "[private key] "); | |
| 406 | if (mode & SILC_CHANNEL_MODE_INVITE) | |
| 407 | strcat(buf, "[invite only] "); | |
| 408 | if (mode & SILC_CHANNEL_MODE_TOPIC) | |
| 409 | strcat(buf, "[topic restricted] "); | |
| 410 | if (mode & SILC_CHANNEL_MODE_ULIMIT) | |
| 411 | strcat(buf, "[user count limit] "); | |
| 412 | if (mode & SILC_CHANNEL_MODE_PASSPHRASE) | |
| 413 | strcat(buf, "[passphrase auth] "); | |
| 414 | if (mode & SILC_CHANNEL_MODE_CHANNEL_AUTH) | |
| 415 | strcat(buf, "[public key auth] "); | |
| 416 | if (mode & SILC_CHANNEL_MODE_SILENCE_USERS) | |
| 417 | strcat(buf, "[users silenced] "); | |
| 418 | if (mode & SILC_CHANNEL_MODE_SILENCE_OPERS) | |
| 419 | strcat(buf, "[operators silenced] "); | |
| 420 | } | |
| 421 | ||
| 422 | void silcgaim_get_chumode_string(SilcUInt32 mode, char *buf, | |
| 423 | SilcUInt32 buf_size) | |
| 424 | { | |
| 425 | memset(buf, 0, buf_size); | |
| 426 | if (mode & SILC_CHANNEL_UMODE_CHANFO) | |
| 427 | strcat(buf, "[founder] "); | |
| 428 | if (mode & SILC_CHANNEL_UMODE_CHANOP) | |
| 429 | strcat(buf, "[operator] "); | |
| 430 | if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES) | |
| 431 | strcat(buf, "[blocks messages] "); | |
| 432 | if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_USERS) | |
| 433 | strcat(buf, "[blocks user messages] "); | |
| 434 | if (mode & SILC_CHANNEL_UMODE_BLOCK_MESSAGES_ROBOTS) | |
| 435 | strcat(buf, "[blocks robot messages] "); | |
| 436 | if (mode & SILC_CHANNEL_UMODE_QUIET) | |
| 437 | strcat(buf, "[quieted] "); | |
| 438 | } |