6 * Copyright (C) 2010-11 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2008 Novell, Inc.
8 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "sipe-backend.h"
34 #include "sipe-mime.h"
35 #include "sipe-utils.h"
37 struct sipmsg
*sipmsg_parse_msg(const gchar
*msg
) {
38 const char *tmp
= strstr(msg
, "\r\n\r\n");
44 line
= g_strndup(msg
, tmp
- msg
);
46 smsg
= sipmsg_parse_header(line
);
47 smsg
->body
= g_strdup(tmp
+ 4);
53 struct sipmsg
*sipmsg_parse_header(const gchar
*header
) {
54 struct sipmsg
*msg
= g_new0(struct sipmsg
,1);
55 gchar
**lines
= g_strsplit(header
,"\r\n",0);
57 const gchar
*contentlength
;
63 parts
= g_strsplit(lines
[0], " ", 3);
64 if(!parts
[0] || !parts
[1] || !parts
[2]) {
70 if(strstr(parts
[0],"SIP") || strstr(parts
[0],"HTTP")) { /* numeric response */
71 msg
->responsestr
= g_strdup(parts
[2]);
72 msg
->response
= strtol(parts
[1],NULL
,10);
73 } else { /* request */
74 msg
->method
= g_strdup(parts
[0]);
75 msg
->target
= g_strdup(parts
[1]);
79 if (sipe_utils_parse_lines(&msg
->headers
, lines
+ 1, ":") == FALSE
) {
85 contentlength
= sipmsg_find_header(msg
, "Content-Length");
87 msg
->bodylen
= strtol(contentlength
,NULL
,10);
89 SIPE_DEBUG_FATAL_NOFORMAT("sipmsg_parse_header(): Content-Length header not found");
93 tmp
= sipmsg_find_header(msg
, "CSeq");
95 /* SHOULD NOT HAPPEN */
98 parts
= g_strsplit(tmp
, " ", 2);
99 msg
->method
= g_strdup(parts
[1]);
106 struct sipmsg
*sipmsg_copy(const struct sipmsg
*other
) {
107 struct sipmsg
*msg
= g_new0(struct sipmsg
, 1);
110 msg
->response
= other
->response
;
111 msg
->responsestr
= g_strdup(other
->responsestr
);
112 msg
->method
= g_strdup(other
->method
);
113 msg
->target
= g_strdup(other
->target
);
115 list
= other
->headers
;
117 struct sipnameval
*elem
= list
->data
;
118 sipmsg_add_header_now(msg
, elem
->name
, elem
->value
);
122 list
= other
->new_headers
;
124 struct sipnameval
*elem
= list
->data
;
125 sipmsg_add_header(msg
, elem
->name
, elem
->value
);
129 msg
->bodylen
= other
->bodylen
;
130 msg
->body
= g_strdup(other
->body
);
131 msg
->signature
= g_strdup(other
->signature
);
132 msg
->rand
= g_strdup(other
->rand
);
133 msg
->num
= g_strdup(other
->num
);
138 char *sipmsg_to_string(const struct sipmsg
*msg
) {
140 GString
*outstr
= g_string_new("");
141 struct sipnameval
*elem
;
144 g_string_append_printf(outstr
, "SIP/2.0 %d Unknown\r\n",
147 g_string_append_printf(outstr
, "%s %s SIP/2.0\r\n",
148 msg
->method
, msg
->target
);
153 /*Todo: remove the LFCR in a good way*/
154 /*if(sipe_strequal(elem->name,"Proxy-Authorization"))
155 g_string_append_printf(outstr, "%s: %s", elem->name,
158 g_string_append_printf(outstr
, "%s: %s\r\n", elem
->name
,
160 cur
= g_slist_next(cur
);
163 g_string_append_printf(outstr
, "\r\n%s", msg
->bodylen
? msg
->body
: "");
165 return g_string_free(outstr
, FALSE
);
169 * Adds header to current message headers at specified position
171 void sipmsg_add_header_now_pos(struct sipmsg
*msg
, const gchar
*name
, const gchar
*value
, int pos
) {
172 struct sipnameval
*element
= g_new0(struct sipnameval
,1);
174 /* SANITY CHECK: the calling code must be fixed if this happens! */
176 SIPE_DEBUG_ERROR("sipmsg_add_header_now_pos: NULL value for %s (%d)",
181 element
->name
= g_strdup(name
);
182 element
->value
= g_strdup(value
);
183 msg
->headers
= g_slist_insert(msg
->headers
, element
,pos
);
187 * Adds header to current message headers
189 void sipmsg_add_header_now(struct sipmsg
*msg
, const gchar
*name
, const gchar
*value
) {
190 struct sipnameval
*element
= g_new0(struct sipnameval
,1);
192 /* SANITY CHECK: the calling code must be fixed if this happens! */
194 SIPE_DEBUG_ERROR("sipmsg_add_header_now: NULL value for %s",
199 element
->name
= g_strdup(name
);
200 element
->value
= g_strdup(value
);
201 msg
->headers
= g_slist_append(msg
->headers
, element
);
205 * Adds header to separate storage for future merge
207 void sipmsg_add_header(struct sipmsg
*msg
, const gchar
*name
, const gchar
*value
) {
208 struct sipnameval
*element
= g_new0(struct sipnameval
,1);
210 /* SANITY CHECK: the calling code must be fixed if this happens! */
212 SIPE_DEBUG_ERROR("sipmsg_add_header: NULL value for %s", name
);
216 element
->name
= g_strdup(name
);
217 element
->value
= g_strdup(value
);
218 msg
->new_headers
= g_slist_append(msg
->new_headers
, element
);
222 * Removes header if it's not in keepers array
224 void sipmsg_strip_headers(struct sipmsg
*msg
, const gchar
*keepers
[]) {
226 struct sipnameval
*elem
;
228 entry
= msg
->headers
;
231 gboolean keeper
= FALSE
;
235 if (!g_strcasecmp(elem
->name
, keepers
[i
])) {
243 GSList
*to_delete
= entry
;
244 SIPE_DEBUG_INFO("sipmsg_strip_headers: removing %s", elem
->name
);
245 entry
= g_slist_next(entry
);
246 msg
->headers
= g_slist_delete_link(msg
->headers
, to_delete
);
251 entry
= g_slist_next(entry
);
257 * Merges newly added headers to message
259 void sipmsg_merge_new_headers(struct sipmsg
*msg
) {
260 while(msg
->new_headers
) {
261 msg
->headers
= g_slist_append(msg
->headers
, msg
->new_headers
->data
);
262 msg
->new_headers
= g_slist_remove(msg
->new_headers
, msg
->new_headers
->data
);
266 void sipmsg_free(struct sipmsg
*msg
) {
268 sipe_utils_nameval_free(msg
->headers
);
269 sipe_utils_nameval_free(msg
->new_headers
);
270 g_free(msg
->signature
);
273 g_free(msg
->responsestr
);
281 void sipmsg_remove_header_now(struct sipmsg
*msg
, const gchar
*name
) {
282 struct sipnameval
*elem
;
283 GSList
*tmp
= msg
->headers
;
286 // OCS2005 can send the same header in either all caps or mixed case
287 if (sipe_strcase_equal(elem
->name
, name
)) {
288 msg
->headers
= g_slist_remove(msg
->headers
, elem
);
294 tmp
= g_slist_next(tmp
);
299 const gchar
*sipmsg_find_header(const struct sipmsg
*msg
, const gchar
*name
) {
300 return sipe_utils_nameval_find_instance (msg
->headers
, name
, 0);
303 const gchar
*sipmsg_find_header_instance(const struct sipmsg
*msg
, const gchar
*name
, int which
) {
304 return sipe_utils_nameval_find_instance(msg
->headers
, name
, which
);
307 gchar
*sipmsg_find_part_of_header(const char *hdr
, const char * before
, const char * after
, const char * def
) {
315 //printf("partof %s w/ %s before and %s after\n", hdr, before, after);
317 tmp
= before
== NULL
? hdr
: strstr(hdr
, before
);
319 //printf ("not found, returning null\n");
323 if (before
!= NULL
) {
324 tmp
+= strlen(before
);
325 //printf ("tmp now %s\n", tmp);
328 if (after
!= NULL
&& (tmp2
= strstr(tmp
, after
))) {
329 gchar
* res
= g_strndup(tmp
, tmp2
- tmp
);
330 //printf("returning %s\n", res);
333 res2
= g_strdup(tmp
);
334 //printf("returning %s\n", res2);
338 int sipmsg_parse_cseq(struct sipmsg
*msg
)
342 items
= g_strsplit(sipmsg_find_header(msg
, "CSeq"), " ", 1);
344 res
= atoi(items
[0]);
351 * Parse EndPoints header from INVITE request
352 * Returns a list of end points: contact URI plus optional epid.
353 * You must free the values and the list.
356 * EndPoints: "alice alisson" <sip:alice@atlanta.local>, <sip:bob@atlanta.local>;epid=ebca82d94d, <sip:carol@atlanta.local>
357 * EndPoints: "alice, alisson" <sip:alice@atlanta.local>, <sip:bob@atlanta.local>
358 * EndPoints: "alice alisson" <sip:alice@atlanta.local>, "Super, Man" <sip:super@atlanta.local>
360 * @param header (in) EndPoints header contents
362 * @return GSList with struct sipendpoint as elements
364 GSList
*sipmsg_parse_endpoints_header(const gchar
*header
)
367 gchar
**parts
= g_strsplit(header
, ",", 0);
371 for (i
= 0; (part
= parts
[i
]) != NULL
; i
++) {
372 /* Does the part contain a URI? */
373 gchar
*contact
= sipmsg_find_part_of_header(part
, "<", ">", NULL
);
375 struct sipendpoint
*end_point
= g_new(struct sipendpoint
, 1);
376 end_point
->contact
= contact
;
377 end_point
->epid
= sipmsg_find_part_of_header(part
, "epid=", NULL
, NULL
);
378 list
= g_slist_append(list
, end_point
);
386 void sipmsg_parse_p_asserted_identity(const gchar
*header
, gchar
**sip_uri
,
393 if (g_ascii_strncasecmp(header
, "tel:", 4) == 0) {
394 *tel_uri
= g_strdup(header
);
398 parts
= g_strsplit(header
, ",", 0);
400 for (p
= parts
; *p
; p
++) {
401 gchar
*uri
= sipmsg_find_part_of_header(*p
, "<", ">", NULL
);
405 if (g_ascii_strncasecmp(uri
, "sip:", 4) == 0) {
407 SIPE_DEBUG_WARNING_NOFORMAT("More than one "
408 "sip: URI found in P-Asserted-Identity!");
413 } else if (g_ascii_strncasecmp(uri
, "tel:", 4) == 0){
415 SIPE_DEBUG_WARNING_NOFORMAT("More than one "
416 "tel: URI found in P-Asserted-Identity!");
430 * sipmsg_find_auth_header will return the particular WWW-Authenticate
431 * header specified by *name.
433 * Use this function when you want to look for a specific authentication
434 * method such as NTLM or Kerberos
437 gchar
*sipmsg_find_auth_header(struct sipmsg
*msg
, const gchar
*name
) {
439 struct sipnameval
*elem
;
440 int name_len
= strlen(name
);
444 /* SIPE_DEBUG_INFO("Current header: %s", elem->value); */
445 if (elem
&& elem
->name
&&
446 (sipe_strcase_equal(elem
->name
,"WWW-Authenticate") ||
447 sipe_strcase_equal(elem
->name
,"Authentication-Info")) ) {
448 if (!g_strncasecmp((gchar
*)elem
->value
, name
, name_len
)) {
449 /* SIPE_DEBUG_INFO("elem->value: %s", elem->value); */
453 /* SIPE_DEBUG_INFO_NOFORMAT("moving to next header"); */
454 tmp
= g_slist_next(tmp
);
456 SIPE_DEBUG_INFO("auth header '%s' not found.", name
);
461 * Parses headers-like 'msgr' attribute of INVITE's 'ms_text_format' header.
462 * Then retrieves value of 'X-MMS-IM-Format'.
464 * 'msgr' typically looks like:
465 * X-MMS-IM-Format: FN=Microsoft%20Sans%20Serif; EF=BI; CO=800000; CS=0; PF=22
467 static gchar
*sipmsg_get_x_mms_im_format(gchar
*msgr
) {
469 gsize msgr_dec64_len
;
474 gchar
*x_mms_im_format
;
477 if (!msgr
) return NULL
;
478 msgr2
= g_strdup(msgr
);
479 while (strlen(msgr2
) % 4 != 0) {
480 gchar
*tmp_msgr2
= msgr2
;
481 msgr2
= g_strdup_printf("%s=", msgr2
);
484 msgr_dec64
= g_base64_decode(msgr2
, &msgr_dec64_len
);
485 msgr_utf8
= g_convert((gchar
*) msgr_dec64
, msgr_dec64_len
, "UTF-8", "UTF-16LE", NULL
, NULL
, NULL
);
488 lines
= g_strsplit(msgr_utf8
,"\r\n\r\n",0);
490 //@TODO: make extraction like parsing of message headers.
491 parts
= g_strsplit(lines
[0],"X-MMS-IM-Format:",0);
492 x_mms_im_format
= g_strdup(parts
[1]);
495 tmp
= x_mms_im_format
;
496 if (x_mms_im_format
) {
497 while(*x_mms_im_format
==' ' || *x_mms_im_format
=='\t') x_mms_im_format
++;
499 x_mms_im_format
= g_strdup(x_mms_im_format
);
501 return x_mms_im_format
;
504 gchar
*sipmsg_get_msgr_string(gchar
*x_mms_im_format
) {
506 gsize msgr_utf16_len
;
512 if (!x_mms_im_format
) return NULL
;
513 msgr_orig
= g_strdup_printf("X-MMS-IM-Format: %s\r\n\r\n", x_mms_im_format
);
514 msgr_utf16
= g_convert(msgr_orig
, -1, "UTF-16LE", "UTF-8", NULL
, &msgr_utf16_len
, NULL
);
516 msgr_enc
= g_base64_encode((guchar
*) msgr_utf16
, msgr_utf16_len
);
518 len
= strlen(msgr_enc
);
519 while (msgr_enc
[len
- 1] == '=') len
--;
520 res
= g_strndup(msgr_enc
, len
);
525 static void msn_parse_format(const char *mime
, char **pre_ret
, char **post_ret
);
528 * Translates X-MMS-IM format to HTML presentation.
530 static gchar
*sipmsg_apply_x_mms_im_format(const char *x_mms_im_format
, gchar
*body
) {
534 if (!x_mms_im_format
) {
535 return body
? g_strdup(body
) : NULL
;
537 msn_parse_format(x_mms_im_format
, &pre
, &post
);
538 res
= g_strdup_printf("%s%s%s", pre
? pre
: "", body
? body
: "", post
? post
: "");
544 struct html_message_data
{
545 gchar
*ms_text_format
;
550 static void get_html_message_mime_cb(gpointer user_data
,
551 const GSList
*fields
,
555 const gchar
*type
= sipe_utils_nameval_find(fields
, "Content-Type");
556 struct html_message_data
*data
= user_data
;
558 if (!data
->preferred
) {
559 gboolean copy
= FALSE
;
561 /* preferred format */
562 if (g_str_has_prefix(type
, "text/html")) {
564 data
->preferred
= TRUE
;
566 /* fallback format */
567 } else if (g_str_has_prefix(type
, "text/plain")) {
572 g_free(data
->ms_text_format
);
574 data
->ms_text_format
= g_strdup(type
);
575 data
->body
= g_strndup(body
, length
);
580 /* ms-text-format: text/plain; charset=UTF-8;msgr=WAAtAE0...DIADQAKAA0ACgA;ms-body=SGk= */
581 gchar
*get_html_message(const gchar
*ms_text_format_in
, const gchar
*body_in
)
585 gchar
*ms_text_format
= NULL
;
588 if (g_str_has_prefix(ms_text_format_in
, "multipart/related") ||
589 g_str_has_prefix(ms_text_format_in
, "multipart/alternative")) {
590 struct html_message_data data
= { NULL
, NULL
, FALSE
};
592 sipe_mime_parts_foreach(ms_text_format_in
, body_in
,
593 get_html_message_mime_cb
, &data
);
595 ms_text_format
= data
.ms_text_format
;
599 ms_text_format
= g_strdup(ms_text_format_in
);
600 body
= g_strdup(body_in
);
606 gchar
*tmp
= sipmsg_find_part_of_header(ms_text_format
, "ms-body=", NULL
, NULL
);
609 g_free(ms_text_format
);
612 res
= (gchar
*) g_base64_decode(tmp
, &len
);
615 g_free(ms_text_format
);
620 if (g_str_has_prefix(ms_text_format
, "text/html")) {
622 * HTML uses tags for formatting, not line breaks. But
623 * clients still might render them, so we need to remove
624 * them to avoid incorrect text rendering.
627 const gchar
*s
= res
;
630 /* No ANSI C nor glib function seems to exist for this :-( */
632 if ((c
!= '\n') && (c
!= '\r'))
638 res
= g_markup_escape_text(res
, -1); // as this is not html
642 msgr
= sipmsg_find_part_of_header(ms_text_format
, "msgr=", ";", NULL
);
644 gchar
*x_mms_im_format
= sipmsg_get_x_mms_im_format(msgr
);
647 res
= sipmsg_apply_x_mms_im_format(x_mms_im_format
, res
);
649 g_free(x_mms_im_format
);
652 g_free(ms_text_format
);
658 get_reason(struct sipmsg
*msg
, const gchar
*header
)
660 const gchar
*diagnostics
= sipmsg_find_header(msg
, header
);
662 return sipmsg_find_part_of_header(diagnostics
, "reason=\"", "\"", NULL
);
668 sipmsg_get_ms_diagnostics_reason(struct sipmsg
*msg
)
670 return get_reason(msg
, "ms-diagnostics");
674 sipmsg_get_ms_diagnostics_public_reason(struct sipmsg
*msg
)
676 return get_reason(msg
, "ms-diagnostics-public");
680 sipmsg_parse_warning(struct sipmsg
*msg
, gchar
**reason
)
684 * Warning: 310 lcs.microsoft.com "You are currently not using the recommended version of the client"
686 const gchar
*hdr
= sipmsg_find_header(msg
, "Warning");
693 gchar
**parts
= g_strsplit(hdr
, " ", 3);
696 code
= atoi(parts
[0]);
698 if (reason
&& parts
[1] && parts
[2]) {
699 size_t len
= strlen(parts
[2]);
700 if (len
> 2 && parts
[2][0] == '"' && parts
[2][len
- 1] == '"')
701 *reason
= g_strndup(parts
[2] + 1, len
- 2);
713 //------------------------------------------------------------------------------------------
714 //TEMP solution to include it here (copy from purple's msn protocol
715 //How to reuse msn's util methods from sipe?
717 /* from internal.h */
719 #define BUF_LEN MSG_LEN
722 msn_parse_format(const char *mime
, char **pre_ret
, char **post_ret
)
725 GString
*pre
= g_string_new(NULL
);
726 GString
*post
= g_string_new(NULL
);
727 unsigned int colors
[3];
729 if (pre_ret
!= NULL
) *pre_ret
= NULL
;
730 if (post_ret
!= NULL
) *post_ret
= NULL
;
732 cur
= strstr(mime
, "FN=");
734 if (cur
&& (*(cur
= cur
+ 3) != ';'))
736 pre
= g_string_append(pre
, "<FONT FACE=\"");
738 while (*cur
&& *cur
!= ';')
740 pre
= g_string_append_c(pre
, *cur
);
744 pre
= g_string_append(pre
, "\">");
745 post
= g_string_prepend(post
, "</FONT>");
748 cur
= strstr(mime
, "EF=");
750 if (cur
&& (*(cur
= cur
+ 3) != ';'))
752 while (*cur
&& *cur
!= ';')
754 pre
= g_string_append_c(pre
, '<');
755 pre
= g_string_append_c(pre
, *cur
);
756 pre
= g_string_append_c(pre
, '>');
757 post
= g_string_prepend_c(post
, '>');
758 post
= g_string_prepend_c(post
, *cur
);
759 post
= g_string_prepend_c(post
, '/');
760 post
= g_string_prepend_c(post
, '<');
765 cur
= strstr(mime
, "CO=");
767 if (cur
&& (*(cur
= cur
+ 3) != ';'))
771 i
= sscanf(cur
, "%02x%02x%02x;", &colors
[0], &colors
[1], &colors
[2]);
784 unsigned int temp
= colors
[0];
786 colors
[0] = colors
[1];
792 unsigned int temp
= colors
[2];
794 colors
[2] = colors
[0];
798 /* hh is undefined in mingw's gcc 4.4
799 * https://sourceforge.net/tracker/index.php?func=detail&aid=2818436&group_id=2435&atid=102435
801 g_snprintf(tag
, sizeof(tag
),
802 "<FONT COLOR=\"#%02x%02x%02x\">",
803 (unsigned char)colors
[0], (unsigned char)colors
[1], (unsigned char)colors
[2]);
805 pre
= g_string_append(pre
, tag
);
806 post
= g_string_prepend(post
, "</FONT>");
810 cur
= strstr(mime
, "RL=");
812 if (cur
&& (*(cur
= cur
+ 3) != ';'))
816 /* RTL text was received */
817 pre
= g_string_append(pre
, "<SPAN style=\"direction:rtl;text-align:right;\">");
818 post
= g_string_prepend(post
, "</SPAN>");
822 cur
= sipe_utils_uri_unescape(pre
->str
);
823 g_string_free(pre
, TRUE
);
830 cur
= sipe_utils_uri_unescape(post
->str
);
831 g_string_free(post
, TRUE
);
833 if (post_ret
!= NULL
)
840 encode_spaces(const char *str
)
842 static char buf
[BUF_LEN
];
846 g_return_val_if_fail(str
!= NULL
, NULL
);
848 for (c
= str
, d
= buf
; *c
!= '\0'; c
++)
865 sipe_parse_html(const char *html
, char **attributes
, char **message
)
867 int len
, retcount
= 0;
870 char *fontface
= NULL
;
873 char direction
= '0';
875 gboolean has_bold
= FALSE
;
876 gboolean has_italic
= FALSE
;
877 gboolean has_underline
= FALSE
;
878 gboolean has_strikethrough
= FALSE
;
880 g_return_if_fail(html
!= NULL
);
881 g_return_if_fail(attributes
!= NULL
);
882 g_return_if_fail(message
!= NULL
);
885 msg
= g_malloc0(len
+ 1);
887 memset(fontcolor
, 0, sizeof(fontcolor
));
888 strcat(fontcolor
, "0");
889 memset(fonteffect
, 0, sizeof(fonteffect
));
891 for (c
= html
; *c
!= '\0';)
895 if (!g_ascii_strncasecmp(c
+ 1, "br>", 3))
897 msg
[retcount
++] = '\r';
898 msg
[retcount
++] = '\n';
901 else if (!g_ascii_strncasecmp(c
+ 1, "i>", 2))
905 strcat(fonteffect
, "I");
910 else if (!g_ascii_strncasecmp(c
+ 1, "b>", 2))
914 strcat(fonteffect
, "B");
919 else if (!g_ascii_strncasecmp(c
+ 1, "u>", 2))
923 strcat(fonteffect
, "U");
924 has_underline
= TRUE
;
928 else if (!g_ascii_strncasecmp(c
+ 1, "s>", 2))
930 if (!has_strikethrough
)
932 strcat(fonteffect
, "S");
933 has_strikethrough
= TRUE
;
937 else if (!g_ascii_strncasecmp(c
+ 1, "a href=\"", 8))
941 if (!g_ascii_strncasecmp(c
, "mailto:", 7))
944 while ((*c
!= '\0') && g_ascii_strncasecmp(c
, "\">", 2))
945 msg
[retcount
++] = *c
++;
950 /* ignore descriptive string */
951 while ((*c
!= '\0') && g_ascii_strncasecmp(c
, "</a>", 4))
957 else if (!g_ascii_strncasecmp(c
+ 1, "span", 4))
959 /* Bi-directional text support using CSS properties in span tags */
962 while (*c
!= '\0' && *c
!= '>')
966 if (!g_ascii_strncasecmp(c
, "dir=\"rtl\"", 9))
971 else if (!g_ascii_strncasecmp(c
, "style=\"", 7))
973 /* Parse inline CSS attributes */
976 while (*(c
+ attr_len
) != '\0' && *(c
+ attr_len
) != '"')
978 if (*(c
+ attr_len
) == '"')
980 char *css_attributes
;
982 css_attributes
= g_strndup(c
, attr_len
);
983 attr_dir
= sipe_backend_markup_css_property(css_attributes
, "direction");
984 g_free(css_attributes
);
985 if (attr_dir
&& (!g_ascii_strncasecmp(attr_dir
, "RTL", 3)))
999 else if (!g_ascii_strncasecmp(c
+ 1, "font", 4))
1003 while ((*c
!= '\0') && !g_ascii_strncasecmp(c
, " ", 1))
1006 if (!g_ascii_strncasecmp(c
, "color=\"#", 7))
1010 fontcolor
[0] = *(c
+ 4);
1011 fontcolor
[1] = *(c
+ 5);
1012 fontcolor
[2] = *(c
+ 2);
1013 fontcolor
[3] = *(c
+ 3);
1015 fontcolor
[5] = *(c
+ 1);
1019 else if (!g_ascii_strncasecmp(c
, "face=\"", 6))
1021 const char *end
= NULL
;
1022 const char *comma
= NULL
;
1023 unsigned int namelen
= 0;
1026 end
= strchr(c
, '\"');
1027 comma
= strchr(c
, ',');
1029 if (comma
== NULL
|| comma
> end
)
1030 namelen
= (unsigned int)(end
- c
);
1032 namelen
= (unsigned int)(comma
- c
);
1035 fontface
= g_strndup(c
, namelen
);
1040 /* Drop all unrecognized/misparsed font tags */
1041 while ((*c
!= '\0') && g_ascii_strncasecmp(c
, "\">", 2))
1050 while ((*c
!= '\0') && (*c
!= '>'))
1058 if (!g_ascii_strncasecmp(c
, "<", 4))
1060 msg
[retcount
++] = '<';
1063 else if (!g_ascii_strncasecmp(c
, ">", 4))
1065 msg
[retcount
++] = '>';
1068 else if (!g_ascii_strncasecmp(c
, " ", 6))
1070 msg
[retcount
++] = ' ';
1073 else if (!g_ascii_strncasecmp(c
, """, 6))
1075 msg
[retcount
++] = '"';
1078 else if (!g_ascii_strncasecmp(c
, "&", 5))
1080 msg
[retcount
++] = '&';
1083 else if (!g_ascii_strncasecmp(c
, "'", 6))
1085 msg
[retcount
++] = '\'';
1089 msg
[retcount
++] = *c
++;
1092 msg
[retcount
++] = *c
++;
1095 if (fontface
== NULL
)
1096 fontface
= g_strdup("MS Sans Serif");
1098 *attributes
= g_strdup_printf("FN=%s; EF=%s; CO=%s; PF=0; RL=%c",
1099 encode_spaces(fontface
),
1100 fonteffect
, fontcolor
, direction
);