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 & SYNCML_DM_OTAConnection class 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 3 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 77// Abstract class that provides the interfaces to the DMUA for Sending/ 78// Receiving documents 79 80class SYNCML_DM_Connection 81{ 82protected: 83 // AddrType stores stores the format and interpretation of the 84 // DMAcc/x/AddrType node value 85 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}; 119 120 121class SYNCML_DM_OTAConnection : public SYNCML_DM_Connection 122{ 123 124public: 125 126 SYNCML_DM_OTAConnection(); 127 128 129 ~SYNCML_DM_OTAConnection(); 130 131 virtual SYNCML_DM_RET_STATUS_T Init(UINT32 dwMaxAcptSize, 132 XPL_ADDR_TYPE_T AddressType, 133 CPCHAR ConRef); 134 135 // Method to send the SyncML document to the SyncML Server 136 virtual SYNCML_DM_RET_STATUS_T Send( 137 const SYNCML_DM_INDIRECT_BUFFER_T *psSendDoc, 138 SYNCML_DM_INDIRECT_BUFFER_T *psRecvDoc, 139 const UINT8 *pbContentType, 140 const DMCredHeaders * psCredHeaders); 141 142 143private: 144 XPL_HTTP_HANDLE_T m_hConnection; 145 146 // Number of retries that are attempted 147 UINT8 bNumRetries; 148 149 // Maximum size of the Message 150 MAX_MSG_SIZE_T dwMaxAcceptSize; 151 152 // HTTP header to be sent to the Server 153 DMBuffer m_oHttpHdr; 154 155 // SyncML document to be sent to the Server 156 SYNCML_DM_INDIRECT_BUFFER_T *psSendSyncMLDoc; 157 158 // SyncML document to be received from the Server 159 SYNCML_DM_INDIRECT_BUFFER_T *psRecvSyncMLDoc; 160 161 // Credential headers sent and received from the Server 162 DMCredHeaders * m_pCredHeaders; 163 164 165 DMString m_szConRef; 166 167#ifdef DM_DUMP_SYNCML_PACKAGE 168 169 // The path where the dump package file stores 170 DMString dump_path; 171 172 int package_counter; 173 174 char * HTTP_HEADER_SERVER; 175 char * HTTP_HEADER_DATE; 176 char * HTTP_HEADER_ACCEPT_RANGES; 177 char * HTTP_HEADER_CACHE_CONTROL; 178 char * HTTP_HEADER_CONNECTION; 179 char * HTTP_HEADER_CONTENT_TYPE; 180 char * HTTP_HEADER_X_SYNCML_HMAC; 181 182 DMString bodyFileName; 183 DMString bodyFileExt; 184 185 DMString hdrFileName; 186 DMString hdrFileExt; 187#endif 188 189 // Method that prepares request headers 190 SYNCML_DM_RET_STATUS_T PrepareRequestHeaders(const UINT8 *pbContentTypetoSend); 191 192 // Method that computes the HTTP header fields length 193 UINT16 ComputeHTTPHeaderLength(const UINT8 *pbContentTypetoSend); 194 195 // Method that Sends the Inital chunk of the SyncML document 196 SYNCML_DM_RET_STATUS_T SendInitialChunk(void); 197 198 SYNCML_DM_RET_STATUS_T ProcessCredHeaders(CPCHAR pbOrigHmacStr); 199 200 SYNCML_DM_RET_STATUS_T IssueURLRequest(XPL_HTTP_CODE_T *ret_code); 201 202 SYNCML_DM_RET_STATUS_T ConvertXPLCode(XPL_HTTP_RET_STATUS_T http_result); 203 204}; 205 206 207//--------------------------------------------------------------------- 208#endif /* _DM_TPT_CONNECTION_H */ 209