strip '\r\n' from user names

Signed-off-by: Chris Michael <cp.michael@samsung.com>
This commit is contained in:
Chris Michael 2015-02-12 13:45:32 -05:00
parent b8825ed092
commit 39b74a1c00
1 changed files with 39 additions and 6 deletions

View File

@ -4,6 +4,33 @@
#include "channel.h"
#include <time.h>
static int
_find_crlf(const char *data, int length, int *lf)
{
int i = 0;
*lf = 0;
for (; i < length; i++)
{
/* find crlf (\r\n) */
if ((data[i] == 0x0D) &&
(i < (length - 1)) && (data[i + 1] == 0x0A))
{
*lf = 2;
return i;
}
/* find just lf */
if (data[i] == 0x0A)
{
*lf = 1;
return i;
}
}
return -1;
}
void
_callback_server_connected(Express_Network *net, const char *event EINA_UNUSED, const char *source, const char **params EINA_UNUSED, unsigned int count EINA_UNUSED, void *data EINA_UNUSED)
{
@ -138,6 +165,7 @@ _callback_channel_names(Express_Network *net EINA_UNUSED, const char *event EINA
Channel *chl = NULL;
char **users;
unsigned int n = 0, i = 0;
int crlf = 0, lf = 0;
/* DBG("Channel Names: %s", params[0]); */
/* DBG("\tCount: %d", count); */
@ -157,13 +185,18 @@ _callback_channel_names(Express_Network *net EINA_UNUSED, const char *event EINA
users = eina_str_split_full(params[3], " ", -1, &n);
for (; i < n; i++)
{
if (users[i][0] == '@')
{
users[i]++;
_channel_userlist_user_append(chl, users[i], EINA_TRUE);
}
char buff[PATH_MAX];
crlf = _find_crlf(users[i], strlen(users[i]), &lf);
if (crlf > 0)
eina_strlcpy(buff, users[i], crlf + lf);
else
_channel_userlist_user_append(chl, users[i], EINA_FALSE);
eina_strlcpy(buff, users[i], strlen(users[i]) + 1);
if (buff[0] == '@')
_channel_userlist_user_append(chl, buff + 1, EINA_TRUE);
else
_channel_userlist_user_append(chl, buff, EINA_FALSE);
}
_channel_userlist_go(chl);