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_TPT_CONNECTION_H 18#define _DM_TPT_CONNECTION_H 19 20#ifndef __cplusplus 21#error "This is a C++ header file; it requires C++ to compile." 22#endif 23 24//----------------------------------------------------------------------- 25// 26// Header Name: dm_tpt_connection.H 27// 28// General Description: This file contains the class declaration for 29// SYNCML_DM_Connection and SYNCML_DM_OTAConnection. 30// 31//----------------------------------------------------------------------- 32 33#include "syncml_dm_data_types.h" 34#include "dm_tpt_utils.h" 35#include "dmSessionDefs.h" 36#include "dmMemory.h" 37#include "xpl_HTTP.h" 38 39 40//----------------------------------------------------------------------- 41// CONSTANTS 42//----------------------------------------------------------------------- 43 44// define for initial chunk size for HTTP transport 45#define DMTPT_HTTP_CHUNK_SIZE 10240 46 47// define for initial chunk size for WSP transport 48#define DMTPT_WSP_CHUNK_SIZE 8192 49 50// define for maximum number of retries 51#define DMTPT_MAX_RETRIES 5 52 53//----------------------------------------------------------------------- 54// MACROS 55//----------------------------------------------------------------------- 56 57//----------------------------------------------------------------------- 58// ENUMS 59//----------------------------------------------------------------------- 60//----------------------------------------------------------------------- 61// STRUCTURES AND OTHER TYPEDEFS 62//----------------------------------------------------------------------- 63 64//----------------------------------------------------------------------- 65// GLOBAL VARIABLE DECLARATIONS 66//----------------------------------------------------------------------- 67//----------------------------------------------------------------------- 68// FUNCTION PROTOTYPES 69//----------------------------------------------------------------------- 70 71//----------------------------------------------------------------------- 72// CLASS 73//----------------------------------------------------------------------- 74 75 76#if (!defined (PLATFORM_ANDROID) || defined(DM_NATIVE_HTTP)) 77// Abstract class that provides the interfaces to the DMUA for Sending/ 78// Receiving documents 79 80class SYNCML_DM_Connection 81{ 82protected: 83 84 // AddrType stores stores the format and interpretation of the 85 // DMAcc/x/AddrType node value 86 XPL_ADDR_TYPE_T AddrType; 87 88 // URL of the SyncML DM Server 89 DMString m_szURL; 90 91public: 92 93 virtual SYNCML_DM_RET_STATUS_T Init(UINT32 dwMaxAcptSize, 94 XPL_ADDR_TYPE_T AddressType, 95 CPCHAR ConRef) = 0; 96 97 // Interface for Send method 98 virtual SYNCML_DM_RET_STATUS_T Send( 99 const SYNCML_DM_INDIRECT_BUFFER_T *psSendDoc, 100 SYNCML_DM_INDIRECT_BUFFER_T *psRecvDoc, 101 const UINT8 *pbContentType, 102 const DMCredHeaders * psCredHeaders) = 0; 103 104 // Interface for SetURI method 105 virtual SYNCML_DM_RET_STATUS_T SetURI(CPCHAR szURL); 106 107 inline void* operator new(size_t sz) 108 { 109 return (DmAllocMem(sz)); 110 } 111 112 inline void operator delete(void* buf) 113 { 114 DmFreeMem(buf); 115 } 116}; 117 118 119class SYNCML_DM_OTAConnection : public SYNCML_DM_Connection 120{ 121public: 122 123 SYNCML_DM_OTAConnection(); 124 125 virtual ~SYNCML_DM_OTAConnection(); 126 127 virtual SYNCML_DM_RET_STATUS_T Init(UINT32 dwMaxAcptSize, 128 XPL_ADDR_TYPE_T AddressType, 129 CPCHAR ConRef); 130 131 // Method to send the SyncML document to the SyncML Server 132 virtual SYNCML_DM_RET_STATUS_T Send( 133 const SYNCML_DM_INDIRECT_BUFFER_T *psSendDoc, 134 SYNCML_DM_INDIRECT_BUFFER_T *psRecvDoc, 135 const UINT8 *pbContentType, 136 const DMCredHeaders * psCredHeaders); 137 138private: 139 140 XPL_HTTP_HANDLE_T m_hConnection; 141 142 // Number of retries that are attempted 143 UINT8 bNumRetries; 144 145 // Maximum size of the Message 146 MAX_MSG_SIZE_T dwMaxAcceptSize; 147 148 // HTTP header to be sent to the Server 149 DMBuffer m_oHttpHdr; 150 151 // SyncML document to be sent to the Server 152 SYNCML_DM_INDIRECT_BUFFER_T *psSendSyncMLDoc; 153 154 // SyncML document to be received from the Server 155 SYNCML_DM_INDIRECT_BUFFER_T *psRecvSyncMLDoc; 156 157 // Credential headers sent and received from the Server 158 DMCredHeaders * m_pCredHeaders; 159 160 DMString m_szConRef; 161 162#ifdef DM_DUMP_SYNCML_PACKAGE 163 164 // The path where the dump package file stores 165 DMString dump_path; 166 167 int package_counter; 168 169 char * HTTP_HEADER_SERVER; 170 char * HTTP_HEADER_DATE; 171 char * HTTP_HEADER_ACCEPT_RANGES; 172 char * HTTP_HEADER_CACHE_CONTROL; 173 char * HTTP_HEADER_CONNECTION; 174 char * HTTP_HEADER_CONTENT_TYPE; 175 char * HTTP_HEADER_X_SYNCML_HMAC; 176 177 DMString bodyFileName; 178 DMString bodyFileExt; 179 180 DMString hdrFileName; 181 DMString hdrFileExt; 182 183#endif 184 185 // Method that prepares request headers 186 SYNCML_DM_RET_STATUS_T PrepareRequestHeaders(const UINT8 *pbContentTypetoSend); 187 188 // Method that computes the HTTP header fields length 189 UINT16 ComputeHTTPHeaderLength(const UINT8 *pbContentTypetoSend); 190 191 // Method that Sends the Inital chunk of the SyncML document 192 SYNCML_DM_RET_STATUS_T SendInitialChunk(void); 193 194 SYNCML_DM_RET_STATUS_T ProcessCredHeaders(CPCHAR pbOrigHmacStr); 195 196 SYNCML_DM_RET_STATUS_T IssueURLRequest(XPL_HTTP_CODE_T *ret_code); 197 198 SYNCML_DM_RET_STATUS_T ConvertXPLCode(XPL_HTTP_RET_STATUS_T http_result); 199}; 200 201#else //under android platform 202 203#include "JNIHelp.h" 204#include "jni.h" 205 206class SYNCML_DM_OTAConnection 207{ 208 public: 209 210 SYNCML_DM_OTAConnection(); 211 212 ~SYNCML_DM_OTAConnection(); 213 214 SYNCML_DM_RET_STATUS_T Init(UINT32 dwMaxAcptSize, 215 XPL_ADDR_TYPE_T AddressType, 216 CPCHAR ConRef); 217 218 // Method to send the SyncML document to the SyncML Server 219 SYNCML_DM_RET_STATUS_T Send( 220 const SYNCML_DM_INDIRECT_BUFFER_T *psSendDoc, 221 SYNCML_DM_INDIRECT_BUFFER_T *psRecvDoc, 222 const UINT8 *pbContentType, 223 const DMCredHeaders * psCredHeaders); 224 225 SYNCML_DM_RET_STATUS_T SetURI(CPCHAR szURL); 226 227 private: 228 229 SYNCML_DM_RET_STATUS_T ProcessCredHeaders(CPCHAR pbOrigHmacStr); 230 UINT32 m_maxAcptSize; 231 232 DMString m_szURL; 233 234 jobject m_jNetConnObj; 235 236 jmethodID m_jSendRequest; 237 jmethodID m_jGetRespLength; 238 jmethodID m_jGetRespData; 239 jmethodID m_jSetContentType; 240 jmethodID m_jclose; 241 jmethodID m_jEnbleApnByName; 242 243 // Credential headers sent and received from the Server 244 DMCredHeaders * m_pCredHeaders; 245}; 246#endif 247 248//--------------------------------------------------------------------- 249#endif /* _DM_TPT_CONNECTION_H */ 250