1 2#include "xpl_HTTP.h" 3#include "dmSocketConnector.h" 4 5 6/* Activetes HTTP transport and set specified URL to connect with server. 7* Do not establish actual connection with server */ 8XPL_HTTP_HANDLE_T XPL_HTTP_Open(CPCHAR url, 9 CPCHAR ConRef, 10 XPL_ADDR_TYPE_T addrType, 11 XPL_HTTP_RET_STATUS_T * result) 12{ 13 DmSocketConnector * p = DmBrwCreateConnector(); 14 15 if ( !p ) { 16 if ( result ) 17 *result = XPL_HTTP_RET_FAIL; 18 return 0; 19 } 20 21 if ( p->Open(url, ConRef, addrType) != SYNCML_DM_SUCCESS ){ 22 delete p; 23 24 if ( result ) 25 *result = XPL_HTTP_RET_FAIL; 26 27 return 0; 28 } 29 30 if ( result ) 31 *result = XPL_HTTP_RET_SUCCESS; 32 33 return (XPL_HTTP_HANDLE_T)p; 34} 35 36/* Sets method for URL request. */ 37XPL_HTTP_RET_STATUS_T 38XPL_HTTP_SetRequestMethod(XPL_HTTP_HANDLE_T handler, 39 XPL_HTTP_METHOD_T method) 40{ 41 DmSocketConnector * p = (DmSocketConnector*) handler; 42 43 if ( !p ) 44 return XPL_HTTP_RET_BADARGUMENT; 45 46 if ( p->SetRequestMethod(method) == SYNCML_DM_SUCCESS ) 47 return XPL_HTTP_RET_SUCCESS; 48 49 return XPL_HTTP_RET_FAIL; 50} 51 52 53/* Sets a general request property. 54* This method is called before Send method */ 55XPL_HTTP_RET_STATUS_T 56XPL_HTTP_SetRequestProperty(XPL_HTTP_HANDLE_T handler, 57 CPCHAR buffer) 58{ 59 DmSocketConnector * p = (DmSocketConnector*) handler; 60 61 if ( !p ) 62 return XPL_HTTP_RET_BADARGUMENT; 63 64 if ( p->SetRequestProperty(buffer) == SYNCML_DM_SUCCESS ) 65 return XPL_HTTP_RET_SUCCESS; 66 67 return XPL_HTTP_RET_FAIL; 68} 69 70/* Sends data to the resource pointed to by the URL. 71* Size specifies size of content to be sent. */ 72XPL_HTTP_RET_STATUS_T 73XPL_HTTP_Send(XPL_HTTP_HANDLE_T handler, 74 CPCHAR buffer, 75 UINT32 size) 76{ 77 DmSocketConnector * p = (DmSocketConnector*) handler; 78 79 if ( !p ) 80 return XPL_HTTP_RET_BADARGUMENT; 81 82 if ( p->Send(buffer, size) == SYNCML_DM_SUCCESS ) 83 return XPL_HTTP_RET_SUCCESS; 84 85 return XPL_HTTP_RET_FAIL; 86} 87 88/* Returns the response length */ 89UINT32 XPL_HTTP_GetResponseLength(XPL_HTTP_HANDLE_T handler) 90{ 91 DmSocketConnector * p = (DmSocketConnector*) handler; 92 93 if ( !p ) 94 return 0; 95 96 return p->GetResponseLength(); 97} 98 99/* Downloads the contents from the resource. The downloaded content is 100* stored in a buffer. */ 101XPL_HTTP_RET_STATUS_T 102XPL_HTTP_GetResponse(XPL_HTTP_HANDLE_T handler, 103 char * buffer, 104 UINT32 size) 105{ 106 DmSocketConnector * p = (DmSocketConnector*) handler; 107 108 if ( !p ) 109 return XPL_HTTP_RET_BADARGUMENT; 110 111 if ( p->GetResponse(buffer, size)== SYNCML_DM_SUCCESS ) 112 return XPL_HTTP_RET_SUCCESS; 113 114 return XPL_HTTP_RET_FAIL; 115} 116 117/* Method returns the value of the header for given header field. */ 118XPL_HTTP_RET_STATUS_T 119XPL_HTTP_GetHeaderField(XPL_HTTP_HANDLE_T handler, 120 CPCHAR field, 121 char ** value) 122{ 123 DmSocketConnector * p = (DmSocketConnector*) handler; 124 125 if ( !p ) 126 return XPL_HTTP_RET_BADARGUMENT; 127 128 if ( p->GetHeaderField(field, value)== SYNCML_DM_SUCCESS ) 129 return XPL_HTTP_RET_SUCCESS; 130 131 return XPL_HTTP_RET_FAIL; 132} 133 134/* Method returns the complete response header as sent by server. */ 135XPL_HTTP_RET_STATUS_T 136XPL_HTTP_GetRespHeader(XPL_HTTP_HANDLE_T handler, 137 char ** header) 138{ 139 return XPL_HTTP_RET_FAIL; 140} 141 142/* Method returns value of content-type in the response header. */ 143XPL_HTTP_RET_STATUS_T 144XPL_HTTP_GetType(XPL_HTTP_HANDLE_T handler, 145 char ** content_type) 146{ 147 return XPL_HTTP_RET_FAIL; 148} 149 150/* Gets status code from HTTP/WAP response message. Returns -1, if no code be 151* discerned from the response (i.e., the response is not valid HTTP/WAP) */ 152XPL_HTTP_CODE_T XPL_HTTP_GetResponseCode(XPL_HTTP_HANDLE_T handler) 153{ 154 DmSocketConnector * p = (DmSocketConnector*) handler; 155 156 if ( !p ) 157 return 0; 158 159 return p->GetResponseCode(); 160} 161 162/* Closes connection with server. */ 163XPL_HTTP_RET_STATUS_T XPL_HTTP_Close(XPL_HTTP_HANDLE_T handler) 164{ 165 DmSocketConnector * p = (DmSocketConnector*) handler; 166 167 if ( !p ) 168 return XPL_HTTP_RET_BADARGUMENT; 169 170 p->Close(); 171 delete p; 172 173 return XPL_HTTP_RET_SUCCESS; 174} 175 176/* Closes request transaction without closing connection with server. */ 177XPL_HTTP_RET_STATUS_T XPL_HTTP_CloseReq(XPL_HTTP_HANDLE_T handler) 178{ 179 DmSocketConnector * p = (DmSocketConnector*) handler; 180 181 if ( !p ) 182 return XPL_HTTP_RET_BADARGUMENT; 183 184 p->CloseReq(); 185 186 return XPL_HTTP_RET_SUCCESS; 187} 188 189/* Sets URL for new request */ 190XPL_HTTP_RET_STATUS_T XPL_HTTP_SetUrl(XPL_HTTP_HANDLE_T handler , 191 CPCHAR url, 192 CPCHAR ConRef, 193 XPL_ADDR_TYPE_T addrType) 194{ 195 DmSocketConnector * p = (DmSocketConnector*) handler; 196 197 if ( !p ) 198 return XPL_HTTP_RET_BADARGUMENT; 199 200 if ( p->SetUrl(url, ConRef, addrType)== SYNCML_DM_SUCCESS ) 201 return XPL_HTTP_RET_SUCCESS; 202 203 return XPL_HTTP_RET_FAIL; 204} 205 206 207/* Dowloads content from the resource. The read content is stored in the file */ 208XPL_HTTP_RET_STATUS_T XPL_HTTP_DowloadByFile(XPL_HTTP_HANDLE_T handler, 209 CPCHAR file_name) 210{ 211 return XPL_HTTP_RET_FAIL; 212} 213 214/* Dowloads content from the resource. The downloaded content is stored in a buffer */ 215XPL_HTTP_RET_STATUS_T XPL_HTTP_DownloadByBuffer(XPL_HTTP_HANDLE_T handler, 216 UINT8 * buffer, 217 UINT32 size) 218{ 219 return XPL_HTTP_RET_FAIL; 220} 221 222 223 224