From: Pekka Riikonen Date: Wed, 1 Nov 2000 21:44:27 +0000 (+0000) Subject: Moved silc_client_ch[u]mode[_char] to client library from silc/. X-Git-Tag: SILC.0.1~336 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=bb1973faaa81ead23b3d5e05b45cddd8a47d51f7;hp=a998ac107c2bb107764c1c495bd9028e03bfcc37 Moved silc_client_ch[u]mode[_char] to client library from silc/. NAMES command now shows users modes on joining with nickname --- diff --git a/CHANGES b/CHANGES index 08341773..bfec5a99 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,13 @@ Wed Nov 1 17:21:26 EET 2000 Pekka Riikonen + * NAMES command reply now shows users mode with the nickname when + joining to channel. + + * Moved silc_client_ch[u]mode[_char] functions from + silc/clientutil.[ch] to lib/silcclient/client.[ch]. Though, that + place sucks, they are utility functions and should be in some + other file. + * Fixed some unsigned int's to unsigned short's. Patch by cras. * Fixed contrib/getopt*.[ch] to not require config.h. Patch by diff --git a/apps/silc/clientutil.c b/apps/silc/clientutil.c index 321160d4..210f50b0 100644 --- a/apps/silc/clientutil.c +++ b/apps/silc/clientutil.c @@ -729,80 +729,3 @@ int silc_client_load_keys(SilcClient client) return TRUE; } - -/* Parses mode mask and returns the mode as string. */ - -char *silc_client_chmode(unsigned int mode) -{ - char string[20]; - - if (!mode) - return NULL; - - memset(string, 0, sizeof(string)); - - if (mode & SILC_CHANNEL_MODE_PRIVATE) - strncat(string, "p", 1); - - if (mode & SILC_CHANNEL_MODE_SECRET) - strncat(string, "s", 1); - - if (mode & SILC_CHANNEL_MODE_PRIVKEY) - strncat(string, "k", 1); - - if (mode & SILC_CHANNEL_MODE_INVITE) - strncat(string, "i", 1); - - if (mode & SILC_CHANNEL_MODE_TOPIC) - strncat(string, "t", 1); - - if (mode & SILC_CHANNEL_MODE_ULIMIT) - strncat(string, "l", 1); - - if (mode & SILC_CHANNEL_MODE_PASSPHRASE) - strncat(string, "a", 1); - - /* Rest of mode is ignored */ - - return strdup(string); -} - -/* Parses channel user mode mask and returns te mode as string */ - -char *silc_client_chumode(unsigned int mode) -{ - char string[4]; - - if (!mode) - return NULL; - - memset(string, 0, sizeof(string)); - - if (mode & SILC_CHANNEL_UMODE_CHANFO) - strncat(string, "f", 1); - - if (mode & SILC_CHANNEL_UMODE_CHANOP) - strncat(string, "o", 1); - - return strdup(string); -} - -/* Parses channel user mode and returns it as special mode character. */ - -char *silc_client_chumode_char(unsigned int mode) -{ - char string[4]; - - if (!mode) - return NULL; - - memset(string, 0, sizeof(string)); - - if (mode & SILC_CHANNEL_UMODE_CHANFO) - strncat(string, "*", 1); - - if (mode & SILC_CHANNEL_UMODE_CHANOP) - strncat(string, "@", 1); - - return strdup(string); -} diff --git a/apps/silc/clientutil.h b/apps/silc/clientutil.h index b682a127..38f0d9e8 100644 --- a/apps/silc/clientutil.h +++ b/apps/silc/clientutil.h @@ -43,8 +43,5 @@ int silc_client_create_key_pair(char *pkcs_name, int bits, SilcPrivateKey *ret_prv_key); int silc_client_check_silc_dir(); int silc_client_load_keys(SilcClient client); -char *silc_client_chmode(unsigned int mode); -char *silc_client_chumode(unsigned int mode); -char *silc_client_chumode_char(unsigned int mode); #endif diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 4cb6fc7a..44659ada 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -2079,3 +2079,80 @@ void silc_client_replace_from_channels(SilcClient client, silc_idcache_list_free(list); } + +/* Parses mode mask and returns the mode as string. */ + +char *silc_client_chmode(unsigned int mode) +{ + char string[20]; + + if (!mode) + return NULL; + + memset(string, 0, sizeof(string)); + + if (mode & SILC_CHANNEL_MODE_PRIVATE) + strncat(string, "p", 1); + + if (mode & SILC_CHANNEL_MODE_SECRET) + strncat(string, "s", 1); + + if (mode & SILC_CHANNEL_MODE_PRIVKEY) + strncat(string, "k", 1); + + if (mode & SILC_CHANNEL_MODE_INVITE) + strncat(string, "i", 1); + + if (mode & SILC_CHANNEL_MODE_TOPIC) + strncat(string, "t", 1); + + if (mode & SILC_CHANNEL_MODE_ULIMIT) + strncat(string, "l", 1); + + if (mode & SILC_CHANNEL_MODE_PASSPHRASE) + strncat(string, "a", 1); + + /* Rest of mode is ignored */ + + return strdup(string); +} + +/* Parses channel user mode mask and returns te mode as string */ + +char *silc_client_chumode(unsigned int mode) +{ + char string[4]; + + if (!mode) + return NULL; + + memset(string, 0, sizeof(string)); + + if (mode & SILC_CHANNEL_UMODE_CHANFO) + strncat(string, "f", 1); + + if (mode & SILC_CHANNEL_UMODE_CHANOP) + strncat(string, "o", 1); + + return strdup(string); +} + +/* Parses channel user mode and returns it as special mode character. */ + +char *silc_client_chumode_char(unsigned int mode) +{ + char string[4]; + + if (!mode) + return NULL; + + memset(string, 0, sizeof(string)); + + if (mode & SILC_CHANNEL_UMODE_CHANFO) + strncat(string, "*", 1); + + if (mode & SILC_CHANNEL_UMODE_CHANOP) + strncat(string, "@", 1); + + return strdup(string); +} diff --git a/lib/silcclient/client.h b/lib/silcclient/client.h index 84cfa324..fdff610e 100644 --- a/lib/silcclient/client.h +++ b/lib/silcclient/client.h @@ -288,4 +288,8 @@ void silc_client_replace_from_channels(SilcClient client, SilcClientConnection conn, SilcClientEntry old, SilcClientEntry new); +char *silc_client_chmode(unsigned int mode); +char *silc_client_chumode(unsigned int mode); +char *silc_client_chumode_char(unsigned int mode); + #endif diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index 5ed0a3b1..8b2f0c35 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -1092,10 +1092,10 @@ SILC_CLIENT_CMD_REPLY_FUNC(names) channel->clients[k].client->nickname = silc_calloc(strlen(nickname) + 8, sizeof(*channel->clients[k]. client->nickname)); + snprintf(t, sizeof(t), "[%d]", c++); + strncat(channel->clients[k].client->nickname, t, strlen(t)); strncat(channel->clients[k].client->nickname, nickname, strlen(nickname)); - snprintf(t, sizeof(t), " [%d]", c++); - strncat(channel->clients[k].client->nickname, t, strlen(t)); } } @@ -1105,10 +1105,19 @@ SILC_CLIENT_CMD_REPLY_FUNC(names) name_list = NULL; len1 = 0; for (k = 0; k < channel->clients_count; k++) { - char *n = channel->clients[k].client->nickname; + char *m, *n = channel->clients[k].client->nickname; len2 = strlen(n); len1 += len2; - name_list = silc_realloc(name_list, sizeof(*name_list) * (len1 + 1)); + + name_list = silc_realloc(name_list, sizeof(*name_list) * (len1 + 3)); + + m = silc_client_chumode_char(channel->clients[k].mode); + if (m) { + memcpy(name_list + (len1 - len2), m, strlen(m)); + len1 += strlen(m); + silc_free(m); + } + memcpy(name_list + (len1 - len2), n, len2); name_list[len1] = 0;