1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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
17#ifndef DM_NO_SESSION_DLL
18/*==================================================================================================
19
20    Source Name: dmSessionAPI.cc
21
22    General Description: Implementation of External interfaces to Server Session.
23
24==================================================================================================*/
25
26#include "dmSessionFactory.h"
27#include "xpl_dm_Manager.h"
28#include "xpl_Lib.h"
29#include "xpl_Logger.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35SYNCML_DM_RET_STATUS_T
36DmProcessServerData(CPCHAR szPrincipal,
37                                 const DmtSessionProp&  session)
38{
39    SYNCML_DM_RET_STATUS_T ret_status;
40
41#ifndef DM_NO_SESSION_LIB
42    const char * lib_name = XPL_DM_GetEnv(SYNCML_DM_SESSION_LIB);
43    /* Loads dynamic library */
44    XPL_DL_HANDLE_T lib_handle = XPL_DL_Load(lib_name);
45
46    if ( lib_handle == NULL )
47        return SYNCML_DM_FAIL;
48
49    XPL_DL_HANDLE_T pFunc = XPL_DL_GetFunction(lib_handle, "DmProcessServerDataInternal");
50
51    if ( pFunc == NULL )
52    {
53       XPL_DL_Unload(lib_handle);
54       return SYNCML_DM_FAIL;
55    }
56
57    ret_status = ((SYNCML_DM_RET_STATUS_T (*)(CPCHAR ,const DmtSessionProp&))(pFunc))(szPrincipal,session);
58
59    XPL_DL_Unload(lib_handle);
60#else
61    ret_status = DmProcessServerDataInternal(szPrincipal,session);
62    XPL_LOG_DM_SESS_Debug(("Returning from DmProcessServerDataInternal status=%d\n", ret_status));
63#endif
64
65    return ret_status;
66
67}
68
69SYNCML_DM_RET_STATUS_T
70DmProcessScriptData(const UINT8 * docInputBuffer,
71                                 UINT32 inDocSize,
72                                 BOOLEAN isWBXML,
73                                 DMBuffer & oResult)
74{
75    SYNCML_DM_RET_STATUS_T ret_status;
76
77#ifndef DM_NO_SESSION_LIB
78    const char * lib_name = XPL_DM_GetEnv(SYNCML_DM_SESSION_LIB);
79    /* Loads dynamic library */
80    XPL_DL_HANDLE_T lib_handle = XPL_DL_Load(lib_name);
81
82    if ( lib_handle == NULL )
83        return SYNCML_DM_FAIL;
84
85    XPL_DL_HANDLE_T pFunc = XPL_DL_GetFunction(lib_handle, "DmProcessScriptDataInternal");
86
87    if ( pFunc == NULL )
88    {
89       XPL_DL_Unload(lib_handle);
90       return SYNCML_DM_FAIL;
91    }
92
93    ret_status = ((SYNCML_DM_RET_STATUS_T (*)(const UINT8 * , UINT32, BOOLEAN, DMBuffer &))(pFunc))
94                    (docInputBuffer,inDocSize,isWBXML,oResult);
95
96    XPL_DL_Unload(lib_handle);
97#else
98    ret_status = DmProcessScriptDataInternal(docInputBuffer,inDocSize,isWBXML,oResult);
99#endif
100
101    return ret_status;
102
103
104}
105
106SYNCML_DM_RET_STATUS_T
107DmBootstrap(const UINT8 * docInputBuffer,
108                    UINT32 inDocSize,
109                    BOOLEAN isWBXML,
110                    BOOLEAN isProcess,
111                    DMString & serverID)
112{
113
114    SYNCML_DM_RET_STATUS_T ret_status;
115
116#ifndef DM_NO_SESSION_LIB
117    const char * lib_name = XPL_DM_GetEnv(SYNCML_DM_SESSION_LIB);
118
119    XPL_DL_HANDLE_T lib_handle = XPL_DL_Load(lib_name);
120
121    if ( lib_handle == NULL )
122        return SYNCML_DM_FAIL;
123
124    XPL_DL_HANDLE_T pFunc = XPL_DL_GetFunction(lib_handle, "DmBootstrapInternal");
125
126    if ( pFunc == NULL )
127    {
128       XPL_DL_Unload(lib_handle);
129       return SYNCML_DM_FAIL;
130    }
131
132    ret_status = ((SYNCML_DM_RET_STATUS_T (*)(const UINT8 * , UINT32, BOOLEAN, BOOLEAN, DMString &))(pFunc))
133                    (docInputBuffer,inDocSize,isWBXML,isProcess, serverID);
134
135    XPL_DL_Unload(lib_handle);
136#else
137    ret_status = DmBootstrapInternal(docInputBuffer,inDocSize,isWBXML,isProcess, serverID);
138#endif
139    return ret_status;
140
141}
142
143SYNCML_DM_RET_STATUS_T
144DmAuthenticateServer(SYNCML_DM_AuthContext_T& AuthContext )
145{
146    SYNCML_DM_RET_STATUS_T ret_status;
147
148#ifndef DM_NO_SESSION_LIB
149    const char * lib_name = XPL_DM_GetEnv(SYNCML_DM_SESSION_LIB);
150
151    XPL_DL_HANDLE_T lib_handle = XPL_DL_Load(lib_name);
152    if ( lib_handle == NULL )
153        return SYNCML_DM_FAIL;
154
155    XPL_DL_HANDLE_T pFunc = XPL_DL_GetFunction(lib_handle, "DmAuthenticateServerInternal");
156    if ( pFunc == NULL )
157    {
158        XPL_DL_Unload(lib_handle);
159        return SYNCML_DM_FAIL;
160    }
161    ret_status = ((SYNCML_DM_RET_STATUS_T (*)(SYNCML_DM_AuthContext_T& ))(pFunc))(AuthContext);
162
163    XPL_DL_Unload(lib_handle);
164#else
165    ret_status = DmAuthenticateServerInternal(AuthContext);
166#endif
167
168    return ret_status;
169}
170
171#ifdef __cplusplus
172}
173#endif
174
175#endif
176