Modify flora license version.
[platform/core/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginTextConvert.cpp
1 /*
2 * Copyright 2012-2013  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *    http://floralicense.org/license/
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <glib.h>
17 #include "MmsPluginDebug.h"
18 #include "MmsPluginMIME.h"
19 #include "MmsPluginCodec.h"
20 #include "MmsPluginTextConvert.h"
21 #include "MmsPluginUtil.h"
22
23 const char *MmsPluginTextConvertGetCharSet(int MIBEnum)
24 {
25         const char * result_str = NULL;
26
27         result_str = MmsGetTextByCode(MmsCodeCharSet, (unsigned short int)MIBEnum);
28         MSG_DEBUG("[MIBEnum = %d, Charset = %s]", MIBEnum, result_str);
29
30         return result_str;
31 }
32
33 bool MmsPluginTextConvert(const char *pToCodeSet, const char *pFromCodeset, const char *pSrc, int srcLen, char **ppDest, int *pDestLen)
34 {
35         char *pDest = NULL;
36         gsize bytes_read = 0;
37         gsize bytes_written = 0;
38         GError *error = NULL;
39
40         if (pToCodeSet == NULL || pFromCodeset == NULL) {
41                 MSG_DEBUG("Error input parameter Codeset to = %s, from = %s", pToCodeSet, pFromCodeset);
42                 goto __CATCH;
43         }
44
45         MSG_DEBUG("Codeset to = %s, from = %s", pToCodeSet, pFromCodeset);
46
47         if (pSrc == NULL || ppDest == NULL || pDestLen == NULL) {
48                 MSG_DEBUG("Error input parameter pSrc = %p, ppDest = %p, pDestLen = %p", pSrc, ppDest, pDestLen);
49                 goto __CATCH;
50         }
51
52         pDest = g_convert (pSrc, srcLen,
53                         pToCodeSet, pFromCodeset,
54                &bytes_read, &bytes_written,
55                &error);
56
57         if (error != NULL) {
58                 printf("Error in g_convert, GError = %d:%s, pSrc = %s\n", error->code, error->message, pSrc);
59                 goto __CATCH;
60         }
61
62         if (pDest == NULL || bytes_written == 0 || bytes_read == 0) {
63                 printf("Error in g_convert, pDest = %s, bytes_written = %d, bytes_read = %d\n", pDest, bytes_written, bytes_read);
64                 goto __CATCH;
65         }
66
67         *ppDest = pDest;
68         *pDestLen = bytes_written;
69
70         return true;
71
72 __CATCH:
73         if (pDest)
74                 g_free(pDest);
75
76         return false;
77 }