6 * Copyright (C) 2010-2013 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 const gchar
*tmp
= sipmsg_find_header(msg
, "Transfer-Encoding");
90 if (tmp
&& sipe_strcase_equal(tmp
, "chunked")) {
91 msg
->bodylen
= SIPMSG_BODYLEN_CHUNKED
;
93 SIPE_DEBUG_FATAL_NOFORMAT("sipmsg_parse_header(): Content-Length header not found");
98 tmp
= sipmsg_find_header(msg
, "CSeq");
100 /* SHOULD NOT HAPPEN */
103 parts
= g_strsplit(tmp
, " ", 2);
104 msg
->method
= g_strdup(parts
[1]);
111 struct sipmsg
*sipmsg_copy(const struct sipmsg
*other
) {
112 struct sipmsg
*msg
= g_new0(struct sipmsg
, 1);
115 msg
->response
= other
->response
;
116 msg
->responsestr
= g_strdup(other
->responsestr
);
117 msg
->method
= g_strdup(other
->method
);
118 msg
->target
= g_strdup(other
->target
);
120 list
= other
->headers
;
122 struct sipnameval
*elem
= list
->data
;
123 sipmsg_add_header_now(msg
, elem
->name
, elem
->value
);
127 list
= other
->new_headers
;
129 struct sipnameval
*elem
= list
->data
;
130 sipmsg_add_header(msg
, elem
->name
, elem
->value
);
134 msg
->bodylen
= other
->bodylen
;
135 msg
->body
= g_strdup(other
->body
);
136 msg
->signature
= g_strdup(other
->signature
);
137 msg
->rand
= g_strdup(other
->rand
);
138 msg
->num
= g_strdup(other
->num
);
143 char *sipmsg_to_string(const struct sipmsg
*msg
) {
145 GString
*outstr
= g_string_new("");
146 struct sipnameval
*elem
;
149 g_string_append_printf(outstr
, "SIP/2.0 %d Unknown\r\n",
152 g_string_append_printf(outstr
, "%s %s SIP/2.0\r\n",
153 msg
->method
, msg
->target
);
158 /*Todo: remove the LFCR in a good way*/
159 /*if(sipe_strequal(elem->name,"Proxy-Authorization"))
160 g_string_append_printf(outstr, "%s: %s", elem->name,
163 g_string_append_printf(outstr
, "%s: %s\r\n", elem
->name
,
165 cur
= g_slist_next(cur
);
168 g_string_append_printf(outstr
, "\r\n%s", msg
->bodylen
? msg
->body
: "");
170 return g_string_free(outstr
, FALSE
);
174 * Adds header to current message headers
176 void sipmsg_add_header_now(struct sipmsg
*msg
, const gchar
*name
, const gchar
*value
) {
177 struct sipnameval
*element
= g_new0(struct sipnameval
,1);
179 /* SANITY CHECK: the calling code must be fixed if this happens! */
181 SIPE_DEBUG_ERROR("sipmsg_add_header_now: NULL value for %s",
186 element
->name
= g_strdup(name
);
187 element
->value
= g_strdup(value
);
188 msg
->headers
= g_slist_append(msg
->headers
, element
);
192 * Adds header to separate storage for future merge
194 void sipmsg_add_header(struct sipmsg
*msg
, const gchar
*name
, const gchar
*value
) {
195 struct sipnameval
*element
= g_new0(struct sipnameval
,1);
197 /* SANITY CHECK: the calling code must be fixed if this happens! */
199 SIPE_DEBUG_ERROR("sipmsg_add_header: NULL value for %s", name
);
203 element
->name
= g_strdup(name
);
204 element
->value
= g_strdup(value
);
205 msg
->new_headers
= g_slist_append(msg
->new_headers
, element
);
209 * Removes header if it's not in keepers array
211 void sipmsg_strip_headers(struct sipmsg
*msg
, const gchar
*keepers
[]) {
213 struct sipnameval
*elem
;
215 entry
= msg
->headers
;
218 gboolean keeper
= FALSE
;
222 if (!g_ascii_strcasecmp(elem
->name
, keepers
[i
])) {
230 GSList
*to_delete
= entry
;
231 SIPE_DEBUG_INFO("sipmsg_strip_headers: removing %s", elem
->name
);
232 entry
= g_slist_next(entry
);
233 msg
->headers
= g_slist_delete_link(msg
->headers
, to_delete
);
238 entry
= g_slist_next(entry
);
244 * Merges newly added headers to message
246 void sipmsg_merge_new_headers(struct sipmsg
*msg
) {
247 while(msg
->new_headers
) {
248 msg
->headers
= g_slist_append(msg
->headers
, msg
->new_headers
->data
);
249 msg
->new_headers
= g_slist_remove(msg
->new_headers
, msg
->new_headers
->data
);
253 void sipmsg_free(struct sipmsg
*msg
) {
255 sipe_utils_nameval_free(msg
->headers
);
256 sipe_utils_nameval_free(msg
->new_headers
);
257 g_free(msg
->signature
);
260 g_free(msg
->responsestr
);
268 void sipmsg_remove_header_now(struct sipmsg
*msg
, const gchar
*name
) {
269 struct sipnameval
*elem
;
270 GSList
*tmp
= msg
->headers
;
273 // OCS2005 can send the same header in either all caps or mixed case
274 if (sipe_strcase_equal(elem
->name
, name
)) {
275 msg
->headers
= g_slist_remove(msg
->headers
, elem
);
281 tmp
= g_slist_next(tmp
);
286 const gchar
*sipmsg_find_header(const struct sipmsg
*msg
, const gchar
*name
) {
287 return sipe_utils_nameval_find_instance (msg
->headers
, name
, 0);
290 const gchar
*sipmsg_find_header_instance(const struct sipmsg
*msg
, const gchar
*name
, int which
) {
291 return sipe_utils_nameval_find_instance(msg
->headers
, name
, which
);
294 gchar
*sipmsg_find_part_of_header(const char *hdr
, const char * before
, const char * after
, const char * def
) {
302 //printf("partof %s w/ %s before and %s after\n", hdr, before, after);
304 tmp
= before
== NULL
? hdr
: strstr(hdr
, before
);
306 //printf ("not found, returning null\n");
310 if (before
!= NULL
) {
311 tmp
+= strlen(before
);
312 //printf ("tmp now %s\n", tmp);
315 if (after
!= NULL
&& (tmp2
= strstr(tmp
, after
))) {
316 gchar
* res
= g_strndup(tmp
, tmp2
- tmp
);
317 //printf("returning %s\n", res);
320 res2
= g_strdup(tmp
);
321 //printf("returning %s\n", res2);
325 int sipmsg_parse_cseq(struct sipmsg
*msg
)
329 items
= g_strsplit(sipmsg_find_header(msg
, "CSeq"), " ", 1);
331 res
= atoi(items
[0]);
338 * Parse EndPoints header from INVITE request
339 * Returns a list of end points: contact URI plus optional epid.
340 * You must free the values and the list.
343 * EndPoints: "alice alisson" <sip:alice@atlanta.local>, <sip:bob@atlanta.local>;epid=ebca82d94d, <sip:carol@atlanta.local>
344 * EndPoints: "alice, alisson" <sip:alice@atlanta.local>, <sip:bob@atlanta.local>
345 * EndPoints: "alice alisson" <sip:alice@atlanta.local>, "Super, Man" <sip:super@atlanta.local>
347 * @param header (in) EndPoints header contents
349 * @return GSList with struct sipendpoint as elements
351 GSList
*sipmsg_parse_endpoints_header(const gchar
*header
)
354 gchar
**parts
= g_strsplit(header
, ",", 0);
358 for (i
= 0; (part
= parts
[i
]) != NULL
; i
++) {
359 /* Does the part contain a URI? */
360 gchar
*contact
= sipmsg_find_part_of_header(part
, "<", ">", NULL
);
362 struct sipendpoint
*end_point
= g_new(struct sipendpoint
, 1);
363 end_point
->contact
= contact
;
364 end_point
->epid
= sipmsg_find_part_of_header(part
, "epid=", NULL
, NULL
);
365 list
= g_slist_append(list
, end_point
);
373 void sipmsg_parse_p_asserted_identity(const gchar
*header
, gchar
**sip_uri
,
380 if (g_ascii_strncasecmp(header
, "tel:", 4) == 0) {
381 *tel_uri
= g_strdup(header
);
385 parts
= g_strsplit(header
, ",", 0);
387 for (p
= parts
; *p
; p
++) {
388 gchar
*uri
= sipmsg_find_part_of_header(*p
, "<", ">", NULL
);
392 if (g_ascii_strncasecmp(uri
, "sip:", 4) == 0) {
394 SIPE_DEBUG_WARNING_NOFORMAT("More than one "
395 "sip: URI found in P-Asserted-Identity!");
400 } else if (g_ascii_strncasecmp(uri
, "tel:", 4) == 0){
402 SIPE_DEBUG_WARNING_NOFORMAT("More than one "
403 "tel: URI found in P-Asserted-Identity!");
417 * sipmsg_find_auth_header will return the particular WWW-Authenticate
418 * header specified by *name.
420 * Use this function when you want to look for a specific authentication
421 * method such as NTLM or Kerberos
424 const gchar
*sipmsg_find_auth_header(struct sipmsg
*msg
, const gchar
*name
) {
426 struct sipnameval
*elem
;
427 int name_len
= strlen(name
);
431 /* SIPE_DEBUG_INFO("Current header: %s", elem->value); */
432 if (elem
&& elem
->name
&&
433 (sipe_strcase_equal(elem
->name
,"WWW-Authenticate") ||
434 sipe_strcase_equal(elem
->name
,"Authentication-Info")) ) {
435 if (!g_ascii_strncasecmp((gchar
*)elem
->value
, name
, name_len
)) {
436 /* SIPE_DEBUG_INFO("elem->value: %s", elem->value); */
440 /* SIPE_DEBUG_INFO_NOFORMAT("moving to next header"); */
441 tmp
= g_slist_next(tmp
);
443 SIPE_DEBUG_INFO("auth header '%s' not found.", name
);
448 * Parses headers-like 'msgr' attribute of INVITE's 'ms_text_format' header.
449 * Then retrieves value of 'X-MMS-IM-Format'.
451 * 'msgr' typically looks like:
452 * X-MMS-IM-Format: FN=Microsoft%20Sans%20Serif; EF=BI; CO=800000; CS=0; PF=22
454 static gchar
*sipmsg_get_x_mms_im_format(gchar
*msgr
) {
456 gsize msgr_dec64_len
;
461 gchar
*x_mms_im_format
;
464 if (!msgr
) return NULL
;
465 msgr2
= g_strdup(msgr
);
466 while (strlen(msgr2
) % 4 != 0) {
467 gchar
*tmp_msgr2
= msgr2
;
468 msgr2
= g_strdup_printf("%s=", msgr2
);
471 msgr_dec64
= g_base64_decode(msgr2
, &msgr_dec64_len
);
472 msgr_utf8
= g_convert((gchar
*) msgr_dec64
, msgr_dec64_len
, "UTF-8", "UTF-16LE", NULL
, NULL
, NULL
);
475 lines
= g_strsplit(msgr_utf8
,"\r\n\r\n",0);
477 //@TODO: make extraction like parsing of message headers.
478 parts
= g_strsplit(lines
[0],"X-MMS-IM-Format:",0);
479 x_mms_im_format
= g_strdup(parts
[1]);
482 tmp
= x_mms_im_format
;
483 if (x_mms_im_format
) {
484 while(*x_mms_im_format
==' ' || *x_mms_im_format
=='\t') x_mms_im_format
++;
486 x_mms_im_format
= g_strdup(x_mms_im_format
);
488 return x_mms_im_format
;
491 gchar
*sipmsg_get_msgr_string(gchar
*x_mms_im_format
) {
493 gsize msgr_utf16_len
;
499 if (!x_mms_im_format
) return NULL
;
500 msgr_orig
= g_strdup_printf("X-MMS-IM-Format: %s\r\n\r\n", x_mms_im_format
);
501 msgr_utf16
= g_convert(msgr_orig
, -1, "UTF-16LE", "UTF-8", NULL
, &msgr_utf16_len
, NULL
);
503 msgr_enc
= g_base64_encode((guchar
*) msgr_utf16
, msgr_utf16_len
);
505 len
= strlen(msgr_enc
);
506 while (msgr_enc
[len
- 1] == '=') len
--;
507 res
= g_strndup(msgr_enc
, len
);
512 static void msn_parse_format(const char *mime
, char **pre_ret
, char **post_ret
);
515 * Translates X-MMS-IM format to HTML presentation.
517 static gchar
*sipmsg_apply_x_mms_im_format(const char *x_mms_im_format
, gchar
*body
) {
521 if (!x_mms_im_format
) {
522 return body
? g_strdup(body
) : NULL
;
524 msn_parse_format(x_mms_im_format
, &pre
, &post
);
525 res
= g_strdup_printf("%s%s%s", pre
? pre
: "", body
? body
: "", post
? post
: "");
531 struct html_message_data
{
532 gchar
*ms_text_format
;
537 static void get_html_message_mime_cb(gpointer user_data
,
538 const GSList
*fields
,
542 const gchar
*type
= sipe_utils_nameval_find(fields
, "Content-Type");
543 struct html_message_data
*data
= user_data
;
545 if (!data
->preferred
) {
546 gboolean copy
= FALSE
;
548 /* preferred format */
549 if (g_str_has_prefix(type
, "text/html")) {
551 data
->preferred
= TRUE
;
553 /* fallback format */
554 } else if (g_str_has_prefix(type
, "text/plain")) {
559 g_free(data
->ms_text_format
);
561 data
->ms_text_format
= g_strdup(type
);
562 data
->body
= g_strndup(body
, length
);
567 /* ms-text-format: text/plain; charset=UTF-8;msgr=WAAtAE0...DIADQAKAA0ACgA;ms-body=SGk= */
568 gchar
*get_html_message(const gchar
*ms_text_format_in
, const gchar
*body_in
)
572 gchar
*ms_text_format
= NULL
;
575 if (g_str_has_prefix(ms_text_format_in
, "multipart/related") ||
576 g_str_has_prefix(ms_text_format_in
, "multipart/alternative")) {
577 struct html_message_data data
= { NULL
, NULL
, FALSE
};
579 sipe_mime_parts_foreach(ms_text_format_in
, body_in
,
580 get_html_message_mime_cb
, &data
);
582 ms_text_format
= data
.ms_text_format
;
586 ms_text_format
= g_strdup(ms_text_format_in
);
587 body
= g_strdup(body_in
);
593 gchar
*tmp
= sipmsg_find_part_of_header(ms_text_format
, "ms-body=", NULL
, NULL
);
596 g_free(ms_text_format
);
599 res
= (gchar
*) g_base64_decode(tmp
, &len
);
602 g_free(ms_text_format
);
607 if (g_str_has_prefix(ms_text_format
, "text/html")) {
609 * HTML uses tags for formatting, not line breaks. But
610 * clients still might render them, so we need to remove
611 * them to avoid incorrect text rendering.
614 const gchar
*s
= res
;
617 /* No ANSI C nor glib function seems to exist for this :-( */
619 if ((c
!= '\n') && (c
!= '\r'))
625 res
= g_markup_escape_text(res
, -1); // as this is not html
629 msgr
= sipmsg_find_part_of_header(ms_text_format
, "msgr=", ";", NULL
);
631 gchar
*x_mms_im_format
= sipmsg_get_x_mms_im_format(msgr
);
634 res
= sipmsg_apply_x_mms_im_format(x_mms_im_format
, res
);
636 g_free(x_mms_im_format
);
639 g_free(ms_text_format
);
645 get_reason(struct sipmsg
*msg
, const gchar
*header
)
647 const gchar
*diagnostics
= sipmsg_find_header(msg
, header
);
649 return sipmsg_find_part_of_header(diagnostics
, "reason=\"", "\"", NULL
);
655 sipmsg_get_ms_diagnostics_reason(struct sipmsg
*msg
)
657 return get_reason(msg
, "ms-diagnostics");
661 sipmsg_get_ms_diagnostics_public_reason(struct sipmsg
*msg
)
663 return get_reason(msg
, "ms-diagnostics-public");
667 sipmsg_parse_warning(struct sipmsg
*msg
, gchar
**reason
)
671 * Warning: 310 lcs.microsoft.com "You are currently not using the recommended version of the client"
673 const gchar
*hdr
= sipmsg_find_header(msg
, "Warning");
680 gchar
**parts
= g_strsplit(hdr
, " ", 3);
683 code
= atoi(parts
[0]);
685 if (reason
&& parts
[1] && parts
[2]) {
686 size_t len
= strlen(parts
[2]);
687 if (len
> 2 && parts
[2][0] == '"' && parts
[2][len
- 1] == '"')
688 *reason
= g_strndup(parts
[2] + 1, len
- 2);
700 //------------------------------------------------------------------------------------------
701 //TEMP solution to include it here (copy from purple's msn protocol
702 //How to reuse msn's util methods from sipe?
704 /* from internal.h */
706 #define BUF_LEN MSG_LEN
709 msn_parse_format(const char *mime
, char **pre_ret
, char **post_ret
)
712 GString
*pre
= g_string_new(NULL
);
713 GString
*post
= g_string_new(NULL
);
714 unsigned int colors
[3];
716 if (pre_ret
!= NULL
) *pre_ret
= NULL
;
717 if (post_ret
!= NULL
) *post_ret
= NULL
;
719 cur
= strstr(mime
, "FN=");
721 if (cur
&& (*(cur
= cur
+ 3) != ';'))
723 pre
= g_string_append(pre
, "<FONT FACE=\"");
725 while (*cur
&& *cur
!= ';')
727 pre
= g_string_append_c(pre
, *cur
);
731 pre
= g_string_append(pre
, "\">");
732 post
= g_string_prepend(post
, "</FONT>");
735 cur
= strstr(mime
, "EF=");
737 if (cur
&& (*(cur
= cur
+ 3) != ';'))
739 while (*cur
&& *cur
!= ';')
741 pre
= g_string_append_c(pre
, '<');
742 pre
= g_string_append_c(pre
, *cur
);
743 pre
= g_string_append_c(pre
, '>');
744 post
= g_string_prepend_c(post
, '>');
745 post
= g_string_prepend_c(post
, *cur
);
746 post
= g_string_prepend_c(post
, '/');
747 post
= g_string_prepend_c(post
, '<');
752 cur
= strstr(mime
, "CO=");
754 if (cur
&& (*(cur
= cur
+ 3) != ';'))
758 i
= sscanf(cur
, "%02x%02x%02x;", &colors
[0], &colors
[1], &colors
[2]);
771 unsigned int temp
= colors
[0];
773 colors
[0] = colors
[1];
779 unsigned int temp
= colors
[2];
781 colors
[2] = colors
[0];
785 /* hh is undefined in mingw's gcc 4.4
786 * https://sourceforge.net/tracker/index.php?func=detail&aid=2818436&group_id=2435&atid=102435
788 g_snprintf(tag
, sizeof(tag
),
789 "<FONT COLOR=\"#%02x%02x%02x\">",
790 (unsigned char)colors
[0], (unsigned char)colors
[1], (unsigned char)colors
[2]);
792 pre
= g_string_append(pre
, tag
);
793 post
= g_string_prepend(post
, "</FONT>");
797 cur
= strstr(mime
, "RL=");
799 if (cur
&& (*(cur
= cur
+ 3) != ';'))
803 /* RTL text was received */
804 pre
= g_string_append(pre
, "<SPAN style=\"direction:rtl;text-align:right;\">");
805 post
= g_string_prepend(post
, "</SPAN>");
809 cur
= sipe_utils_uri_unescape(pre
->str
);
810 g_string_free(pre
, TRUE
);
817 cur
= sipe_utils_uri_unescape(post
->str
);
818 g_string_free(post
, TRUE
);
820 if (post_ret
!= NULL
)
827 encode_spaces(const char *str
)
829 static char buf
[BUF_LEN
];
833 g_return_val_if_fail(str
!= NULL
, NULL
);
835 for (c
= str
, d
= buf
; *c
!= '\0'; c
++)
852 sipe_parse_html(const char *html
, char **attributes
, char **message
)
854 int len
, retcount
= 0;
857 char *fontface
= NULL
;
860 char direction
= '0';
862 gboolean has_bold
= FALSE
;
863 gboolean has_italic
= FALSE
;
864 gboolean has_underline
= FALSE
;
865 gboolean has_strikethrough
= FALSE
;
867 g_return_if_fail(html
!= NULL
);
868 g_return_if_fail(attributes
!= NULL
);
869 g_return_if_fail(message
!= NULL
);
872 msg
= g_malloc0(len
+ 1);
874 memset(fontcolor
, 0, sizeof(fontcolor
));
875 strcat(fontcolor
, "0");
876 memset(fonteffect
, 0, sizeof(fonteffect
));
878 for (c
= html
; *c
!= '\0';)
882 if (!g_ascii_strncasecmp(c
+ 1, "br>", 3))
884 msg
[retcount
++] = '\r';
885 msg
[retcount
++] = '\n';
888 else if (!g_ascii_strncasecmp(c
+ 1, "i>", 2))
892 strcat(fonteffect
, "I");
897 else if (!g_ascii_strncasecmp(c
+ 1, "b>", 2))
901 strcat(fonteffect
, "B");
906 else if (!g_ascii_strncasecmp(c
+ 1, "u>", 2))
910 strcat(fonteffect
, "U");
911 has_underline
= TRUE
;
915 else if (!g_ascii_strncasecmp(c
+ 1, "s>", 2))
917 if (!has_strikethrough
)
919 strcat(fonteffect
, "S");
920 has_strikethrough
= TRUE
;
924 else if (!g_ascii_strncasecmp(c
+ 1, "a href=\"", 8))
928 if (!g_ascii_strncasecmp(c
, "mailto:", 7))
931 while ((*c
!= '\0') && g_ascii_strncasecmp(c
, "\">", 2))
932 msg
[retcount
++] = *c
++;
937 /* ignore descriptive string */
938 while ((*c
!= '\0') && g_ascii_strncasecmp(c
, "</a>", 4))
944 else if (!g_ascii_strncasecmp(c
+ 1, "span", 4))
946 /* Bi-directional text support using CSS properties in span tags */
949 while (*c
!= '\0' && *c
!= '>')
953 if (!g_ascii_strncasecmp(c
, "dir=\"rtl\"", 9))
958 else if (!g_ascii_strncasecmp(c
, "style=\"", 7))
960 /* Parse inline CSS attributes */
963 while (*(c
+ attr_len
) != '\0' && *(c
+ attr_len
) != '"')
965 if (*(c
+ attr_len
) == '"')
967 char *css_attributes
;
969 css_attributes
= g_strndup(c
, attr_len
);
970 attr_dir
= sipe_backend_markup_css_property(css_attributes
, "direction");
971 g_free(css_attributes
);
972 if (attr_dir
&& (!g_ascii_strncasecmp(attr_dir
, "RTL", 3)))
986 else if (!g_ascii_strncasecmp(c
+ 1, "font", 4))
990 while ((*c
!= '\0') && !g_ascii_strncasecmp(c
, " ", 1))
993 if (!g_ascii_strncasecmp(c
, "color=\"#", 7))
997 fontcolor
[0] = *(c
+ 4);
998 fontcolor
[1] = *(c
+ 5);
999 fontcolor
[2] = *(c
+ 2);
1000 fontcolor
[3] = *(c
+ 3);
1002 fontcolor
[5] = *(c
+ 1);
1006 else if (!g_ascii_strncasecmp(c
, "face=\"", 6))
1008 const char *end
= NULL
;
1009 const char *comma
= NULL
;
1010 unsigned int namelen
= 0;
1013 end
= strchr(c
, '\"');
1014 comma
= strchr(c
, ',');
1016 if (comma
== NULL
|| comma
> end
)
1017 namelen
= (unsigned int)(end
- c
);
1019 namelen
= (unsigned int)(comma
- c
);
1022 fontface
= g_strndup(c
, namelen
);
1027 /* Drop all unrecognized/misparsed font tags */
1028 while ((*c
!= '\0') && g_ascii_strncasecmp(c
, "\">", 2))
1037 while ((*c
!= '\0') && (*c
!= '>'))
1045 if (!g_ascii_strncasecmp(c
, "<", 4))
1047 msg
[retcount
++] = '<';
1050 else if (!g_ascii_strncasecmp(c
, ">", 4))
1052 msg
[retcount
++] = '>';
1055 else if (!g_ascii_strncasecmp(c
, " ", 6))
1057 msg
[retcount
++] = ' ';
1060 else if (!g_ascii_strncasecmp(c
, """, 6))
1062 msg
[retcount
++] = '"';
1065 else if (!g_ascii_strncasecmp(c
, "&", 5))
1067 msg
[retcount
++] = '&';
1070 else if (!g_ascii_strncasecmp(c
, "'", 6))
1072 msg
[retcount
++] = '\'';
1076 msg
[retcount
++] = *c
++;
1079 msg
[retcount
++] = *c
++;
1082 if (fontface
== NULL
)
1083 fontface
= g_strdup("MS Sans Serif");
1085 *attributes
= g_strdup_printf("FN=%s; EF=%s; CO=%s; PF=0; RL=%c",
1086 encode_spaces(fontface
),
1087 fonteffect
, fontcolor
, direction
);