From: Pekka Riikonen Date: Wed, 12 Jul 2000 05:55:50 +0000 (+0000) Subject: Added client_parse_nickname. X-Git-Tag: SILC.0.1~459 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=bde631aaf5c38ac6e4e34f83e71cbda8db42124d;p=silc.git Added client_parse_nickname. --- diff --git a/apps/silc/clientutil.c b/apps/silc/clientutil.c index 0bca24de..6ef0c699 100644 --- a/apps/silc/clientutil.c +++ b/apps/silc/clientutil.c @@ -20,6 +20,9 @@ /* * $Id$ * $Log$ + * Revision 1.5 2000/07/12 05:55:50 priikone + * Added client_parse_nickname. + * * Revision 1.4 2000/07/10 05:40:05 priikone * Added support for verifying incoming public keys from user. * Shows fingerprint of the public key now plus other changes. @@ -946,3 +949,52 @@ int silc_client_verify_server_key(SilcClient client, silc_say(client, "Will not accept server %s key", hostname); return FALSE; } + + +/* Parse nickname string. The format may be !@ to + support multiple same nicknames. The is the final unifier if same + nickname is on same server. Note, this is only local format and server + does not know anything about these. */ + +int silc_client_parse_nickname(char *string, char **nickname, char **server, + unsigned int *num) +{ + unsigned int tlen; + char tmp[256]; + + if (!string) + return FALSE; + + if (strchr(string, '!')) { + tlen = strcspn(string, "!"); + memset(tmp, 0, sizeof(tmp)); + memcpy(tmp, string, tlen); + + if (num) + *num = atoi(tmp); + + if (tlen >= strlen(string)) + return FALSE; + + string += tlen + 1; + } + + if (strchr(string, '@')) { + tlen = strcspn(string, "@"); + + if (nickname) { + *nickname = silc_calloc(tlen + 1, sizeof(char)); + memcpy(*nickname, string, tlen); + } + + if (server) { + *server = silc_calloc(strlen(string) - tlen, sizeof(char)); + memcpy(*server, string + tlen + 1, strlen(string) - tlen - 1); + } + } else { + if (nickname) + *nickname = strdup(string); + } + + return TRUE; +} diff --git a/apps/silc/clientutil.h b/apps/silc/clientutil.h index 1ad7286a..195a5eeb 100644 --- a/apps/silc/clientutil.h +++ b/apps/silc/clientutil.h @@ -48,5 +48,7 @@ int silc_client_verify_server_key(SilcClient client, SilcSocketConnection sock, unsigned char *pk, unsigned int pk_len, SilcSKEPKType pk_type); +int silc_client_parse_nickname(char *string, char **nickname, char **server, + unsigned int *num); #endif