RSA sync with private
[platform/core/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginTextConvert.cpp
1 /*
2 * Copyright 2012  Samsung Electronics Co., Ltd
3 *
4 * Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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 <stdlib.h>
18 #include <ctype.h>
19 #include "MmsPluginMIME.h"
20 #include "MmsPluginCodec.h"
21 #include "MmsPluginTextConvert.h"
22 #include "MsgDebug.h"
23 #include "MmsPluginUtil.h"
24
25 const char *MmsPluginTextConvertGetCharSet(int MIBEnum)
26 {
27         const char * result_str = NULL;
28
29         result_str = MmsGetTextByCode(MmsCodeCharSet, (unsigned short int)MIBEnum);
30         MSG_DEBUG("[MIBEnum = %d, Charset = %s]", MIBEnum, result_str);
31
32         return result_str;
33 }
34
35 bool MmsPluginTextConvert(const char *pToCodeSet, const char *pFromCodeset, const char *pSrc, int srcLen, char **ppDest, int *pDestLen)
36 {
37         char *pDest = NULL;
38         gsize bytes_read = 0;
39         gsize bytes_written = 0;
40         GError *error = NULL;
41
42         if (pToCodeSet == NULL || pFromCodeset == NULL) {
43                 MSG_DEBUG("Error input parameter Codeset to = %s, from = %s", pToCodeSet, pFromCodeset);
44                 goto __CATCH;
45         }
46
47         MSG_DEBUG("Codeset to = %s, from = %s", pToCodeSet, pFromCodeset);
48
49         if (pSrc == NULL || ppDest == NULL || pDestLen == NULL) {
50                 MSG_DEBUG("Error input parameter pSrc = %p, ppDest = %p, pDestLen = %p", pSrc, ppDest, pDestLen);
51                 goto __CATCH;
52         }
53
54         pDest = g_convert (pSrc, srcLen,
55                         pToCodeSet, pFromCodeset,
56                &bytes_read, &bytes_written,
57                &error);
58
59         if (error != NULL) {
60                 printf("Error in g_convert, GError = %d:%s, pSrc = %s\n", error->code, error->message, pSrc);
61                 goto __CATCH;
62         }
63
64         if (pDest == NULL || bytes_written == 0 || bytes_read == 0) {
65                 printf("Error in g_convert, pDest = %s, bytes_written = %d, bytes_read = %d\n", pDest, bytes_written, bytes_read);
66                 goto __CATCH;
67         }
68
69         *ppDest = pDest;
70         *pDestLen = bytes_written;
71
72         return true;
73
74 __CATCH:
75         if (pDest)
76                 g_free(pDest);
77
78         return false;
79 }