From a04c35ec1b2c710da24ca4d18ebee13f9723c730 Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Wed, 2 Sep 2015 12:12:40 +0200 Subject: [PATCH] mime: add utility function sipe_mime_parts_contain() Allows easy inspection of MIME document's basic structure. --- src/api/sipe-mime.h | 15 +++++++++- src/core/Makefile.am | 1 + src/core/sipe-mime-common.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/core/sipe-mime-common.c diff --git a/src/api/sipe-mime.h b/src/api/sipe-mime.h index ca6fd872..9b208808 100644 --- a/src/api/sipe-mime.h +++ b/src/api/sipe-mime.h @@ -3,7 +3,7 @@ * * pidgin-sipe * - * Copyright (C) 2010-11 SIPE Project + * Copyright (C) 2010-2015 SIPE Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,3 +55,16 @@ void sipe_mime_parts_foreach(const gchar *type, const gchar *body, sipe_mime_parts_cb callback, gpointer user_data); + +/** + * Checks whether MIME document contains a part with given type. + * + * @param type content type of the whole MIME document. + * @param body body of the MIME document. + * @param part_type the MIME type to search for in document parts. + * + * @return @c TRUE if @c body contains such part, otherwise @c FALSE. + */ +gboolean sipe_mime_parts_contain(const gchar *type, + const gchar *body, + const gchar *part_type); diff --git a/src/core/Makefile.am b/src/core/Makefile.am index d57ba3e5..2f0cda6d 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -67,6 +67,7 @@ libsipe_core_la_SOURCES = \ sipe-im.c \ sipe-incoming.h \ sipe-incoming.c \ + sipe-mime-common.c \ sipe-notify.h \ sipe-notify.c \ sipe-ocs2005.h \ diff --git a/src/core/sipe-mime-common.c b/src/core/sipe-mime-common.c new file mode 100644 index 00000000..d1d3e3f4 --- /dev/null +++ b/src/core/sipe-mime-common.c @@ -0,0 +1,67 @@ +/** + * @file sipe-mime.c + * + * pidgin-sipe + * + * Copyright (C) 2015 SIPE Project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "sipe-common.h" +#include "sipe-mime.h" +#include "sipe-utils.h" + +struct parts_contain_cb_data { + const gchar * type; + gboolean result; +}; + +static void +parts_contain_cb(gpointer user_data, const GSList *fields, + SIPE_UNUSED_PARAMETER const gchar *body, + SIPE_UNUSED_PARAMETER gsize length) +{ + struct parts_contain_cb_data *data = user_data; + + if (!data->result && + sipe_strequal(data->type, sipe_utils_nameval_find(fields, "Content-Type"))) { + data->result = TRUE; + } +} + +gboolean +sipe_mime_parts_contain(const gchar *type, + const gchar *body, + const gchar *part_type) +{ + struct parts_contain_cb_data data; + data.type = part_type; + data.result = FALSE; + + sipe_mime_parts_foreach(type, body, parts_contain_cb, &data); + return data.result; +} + +/* + Local Variables: + mode: c + c-file-style: "bsd" + indent-tabs-mode: t + tab-width: 8 + End: +*/ -- 2.11.4.GIT