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 DMSOCKETCONNECTOR_H
18#define DMSOCKETCONNECTOR_H
19
20#ifndef __cplusplus
21#error "This is a C++ header file; it requires C++ to compile."
22#endif
23
24//--------------------------------------------------------------------------------------------------
25//
26//   Module Name: dmSocketConnector.cc
27//
28//   General Description: DmBrwConnector socket implementation class implementation file.
29//
30//--------------------------------------------------------------------------------------------------
31
32#include <sys/types.h>     // Needed for system defined identifiers.
33#include <netinet/in.h>    // Needed for internet address structure.
34#include <sys/socket.h>    // Needed for socket(), bind(), etc...
35
36#include "dmvector.h"
37#include "dmt.hpp"
38#include "xpl_HTTP.h"
39
40class DmSocketConnector
41{
42 public :
43  DmSocketConnector() {
44    proxy_auth = NULL;
45    proxy_enable_check = true;
46    new_session = true;
47    portNum = "80";
48    socket_portNum = "80";
49    responseData = NULL;
50    proxy_url = NULL;
51  }
52
53  ~DmSocketConnector() {
54    if ( responseData != NULL ) {
55       free(responseData);
56       responseData = NULL;
57    }
58  }
59
60
61  SYNCML_DM_RET_STATUS_T Open(CPCHAR url, CPCHAR ConRef, int AddrType);
62
63  SYNCML_DM_RET_STATUS_T SetRequestMethod(XPL_HTTP_METHOD_T method);
64
65  SYNCML_DM_RET_STATUS_T  SetRequestProperty(CPCHAR props);
66
67  SYNCML_DM_RET_STATUS_T Send(CPCHAR data, UINT32 size);
68
69  UINT32 GetResponseLength();
70
71  SYNCML_DM_RET_STATUS_T GetResponse(char * data, UINT32 size);
72
73  SYNCML_DM_RET_STATUS_T GetHeaderField(CPCHAR field, char ** value);
74
75  XPL_HTTP_CODE_T GetResponseCode();
76
77  SYNCML_DM_RET_STATUS_T Close();
78  SYNCML_DM_RET_STATUS_T CloseReq();
79  SYNCML_DM_RET_STATUS_T SetUrl(CPCHAR url, CPCHAR ConRef, int AddrType);
80
81  bool DmStringParserGetItem( DMString& strItem, DMString& strReminder, char cDelim );
82
83  bool DmParseHTTPHeader( char* strBuffer, int dataBufSize, char** strRemaining, int& lenRemaining);
84  bool SetResponseData(unsigned char* dataReceived, int len);
85
86  bool parseURL(DMString strURI, DMString& strAddrPort, DMString& strURIPath);
87  bool parseAddrPort(DMString strAddrPort, DMString& strAddr, DMString& strPort);
88  SYNCML_DM_RET_STATUS_T doSend(CPCHAR data, UINT32 size);
89  SYNCML_DM_RET_STATUS_T getResponse();
90
91 private:
92  unsigned int         server_s;             // Server socket descriptor
93  struct sockaddr_in   server_addr;          // Server Internet address
94  DMString             sentBuf;              // Sent buffer
95  DMString             urlPath;              // The path part of a URL
96  DMString             portNum;
97  DMString             ipAddress;
98  DMString             responseCode;
99  DMString             responseBody;
100  DMMap<DMString, DMString>   responseHeaders;
101  UINT32               responseLength;
102  const char *               proxy_auth;
103  bool                 proxy_enable_check;
104  bool                 new_session;
105  DMString             socket_ipAddress;
106  DMString             socket_portNum;
107  XPL_HTTP_METHOD_T      requestMethod;
108  unsigned char*       responseData;
109  const char *         proxy_url;
110
111};
112
113DmSocketConnector * DmBrwCreateConnector();
114SYNCML_DM_RET_STATUS_T DmBrwDestroyConnector(DmSocketConnector * browser_handler);
115
116#endif
117