htmldecode

v1
Tony Olagbaiye 7 years ago
parent 614a7d5b5b
commit 32046373b4

@ -15,7 +15,7 @@ struct t_slack_channel_typing
{ {
char *id; char *id;
char *name; char *name;
long ts; time_t ts;
struct t_slack_channel_typing *prev_typing; struct t_slack_channel_typing *prev_typing;
struct t_slack_channel_typing *next_typing; struct t_slack_channel_typing *next_typing;
@ -33,14 +33,14 @@ struct t_slack_channel_topic
{ {
char *value; char *value;
char *creator; char *creator;
long last_set; time_t last_set;
}; };
struct t_slack_channel_purpose struct t_slack_channel_purpose
{ {
char *value; char *value;
char *creator; char *creator;
long last_set; time_t last_set;
}; };
struct t_slack_channel struct t_slack_channel
@ -48,7 +48,7 @@ struct t_slack_channel
enum t_slack_channel_type type; enum t_slack_channel_type type;
char *id; char *id;
char *name; char *name;
int created; time_t created;
/* channel */ /* channel */
int is_general; int is_general;

@ -1,3 +1,4 @@
#include <libwebsockets.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -48,6 +49,51 @@ char *slack_message_translate_code(struct t_slack_workspace *workspace,
} }
} }
void slack_message_htmldecode(char *dest, const char *src, size_t n)
{
size_t i, j;
for (i = 0, j = 0; i < n; i++, j++)
switch (src[i])
{
case '\0':
dest[j] = '\0';
return;
case '&':
if (src[i+1] == 'g' &&
src[i+2] == 't' &&
src[i+3] == ';')
{
dest[j] = '>';
i += 3;
break;
}
else if (src[i+1] == 'l' &&
src[i+2] == 't' &&
src[i+3] == ';')
{
dest[j] = '<';
i += 3;
break;
}
else if (src[i+1] == 'a' &&
src[i+2] == 'm' &&
src[i+3] == 'p' &&
src[i+4] == ';')
{
dest[j] = '&';
i += 4;
break;
}
/* fallthrough */
default:
dest[j] = src[i];
break;
}
dest[j-1] = '\0';
return;
}
char *slack_message_decode(struct t_slack_workspace *workspace, char *slack_message_decode(struct t_slack_workspace *workspace,
const char *text) const char *text)
{ {
@ -142,6 +188,9 @@ char *slack_message_decode(struct t_slack_workspace *workspace,
strncat(decoded_text, cursor, strncat(decoded_text, cursor,
SLACK_MESSAGE_MAX_LENGTH - strlen(decoded_text) - 1); SLACK_MESSAGE_MAX_LENGTH - strlen(decoded_text) - 1);
slack_message_htmldecode(decoded_text, decoded_text,
SLACK_MESSAGE_MAX_LENGTH);
regfree(&reg); regfree(&reg);
return decoded_text; return decoded_text;
} }

Loading…
Cancel
Save