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