You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
6.0 KiB

8 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: nanohttp-client.h,v 1.24 2006/04/26 17:30:29 m0gg Exp $
  3. *
  4. * CSOAP Project: A http client/server library in C
  5. * Copyright (C) 2003 Ferhat Ayaz
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. *
  22. * Email: ferhatayaz@yahoo.com
  23. ******************************************************************/
  24. #ifndef NANO_HTTP_CLIENT_H
  25. #define NANO_HTTP_CLIENT_H
  26. #include <nanohttp/nanohttp-common.h>
  27. #include <nanohttp/nanohttp-socket.h>
  28. #include <nanohttp/nanohttp-response.h>
  29. #include <nanohttp/nanohttp-stream.h>
  30. typedef struct httpc_conn
  31. {
  32. hsocket_t sock;
  33. hpair_t *header;
  34. hurl_t url;
  35. http_version_t version;
  36. /*
  37. -1 : last dime package 0 : no dime connection >0 : dime package number */
  38. int _dime_package_nr;
  39. long _dime_sent_bytes;
  40. int errcode;
  41. char errmsg[150];
  42. http_output_stream_t *out;
  43. int id; /* uniq id */
  44. } httpc_conn_t;
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /* --------------------------------------------------------------
  49. HTTP CLIENT MODULE RELATED FUNCTIONS
  50. ---------------------------------------------------------------*/
  51. /**
  52. *
  53. * Initializes the httpc_* module. This is called from
  54. * soap_client_init_args().
  55. *
  56. * @param argc Argument count.
  57. * @param argv Argument vector.
  58. *
  59. * @return H_OK on succes or a herror_t struct on failure.
  60. *
  61. * @see httpc_destroy, herror_t, soap_client_init_args
  62. */
  63. herror_t httpc_init(int argc, char *argv[]);
  64. /**
  65. *
  66. * Destroys the httpc_* module
  67. *
  68. * @see httpc_init
  69. *
  70. */
  71. void httpc_destroy(void);
  72. /**
  73. *
  74. * Creates a new connection.
  75. *
  76. */
  77. httpc_conn_t *httpc_new(void);
  78. /**
  79. *
  80. * Release a connection
  81. * (use httpc_close_free() instead)
  82. *
  83. * @see httpc_close_free
  84. *
  85. */
  86. void httpc_free(httpc_conn_t * conn);
  87. /**
  88. *
  89. * Close and release a connection
  90. *
  91. * @see httpc_close, httpc_free
  92. *
  93. */
  94. void httpc_close_free(httpc_conn_t * conn);
  95. /**
  96. *
  97. * Sets header element (key,value) pair.
  98. *
  99. * @return 0 on success or failure (yeah!), 1 if a (key,value) pair was replaced.
  100. *
  101. * @see httpc_add_header, httpc_add_headers
  102. *
  103. */
  104. int httpc_set_header(httpc_conn_t * conn, const char *key, const char *value);
  105. /**
  106. *
  107. * Adds a header element (key, value) pair.
  108. *
  109. * @return 0 on success, -1 on failure.
  110. *
  111. * @see httpc_set_header, httpc_add_headers
  112. *
  113. */
  114. int httpc_add_header(httpc_conn_t *conn, const char *key, const char *value);
  115. /**
  116. *
  117. * Adds a list of (key, value) pairs.
  118. *
  119. * @see httpc_set_header, httpc_add_header
  120. *
  121. */
  122. void httpc_add_headers(httpc_conn_t *conn, const hpair_t *values);
  123. /**
  124. *
  125. * Sets a HEADER_AUTHORIZATION header.
  126. *
  127. * @param conn The HTTP connection.
  128. * @param user The username.
  129. * @param password The password.
  130. *
  131. * @see httpc_set_header, HEADER_AUTHORIZATION
  132. *
  133. */
  134. int httpc_set_basic_authorization(httpc_conn_t *conn, const char *user, const char *password);
  135. /**
  136. *
  137. * Sets a HEADER_PROXY_AUTHORIZATION header.
  138. *
  139. * @param conn The HTTP connection.
  140. * @param user The username.
  141. * @param password The password.
  142. *
  143. * @see httpc_set_header, HEADER_PROXY_AUTHORIZATION
  144. */
  145. int httpc_set_basic_proxy_authorization(httpc_conn_t *conn, const char *user, const char *password);
  146. /**
  147. Invoke a "GET" method request and receive the response
  148. */
  149. herror_t httpc_get(httpc_conn_t * conn, hresponse_t ** out, const char *urlstr);
  150. /**
  151. Start a "POST" method request
  152. Returns: HSOCKET_OK or error flag
  153. */
  154. herror_t httpc_post_begin(httpc_conn_t * conn, const char *url);
  155. /**
  156. End a "POST" method and receive the response.
  157. You MUST call httpc_post_end() before!
  158. */
  159. herror_t httpc_post_end(httpc_conn_t * conn, hresponse_t ** out);
  160. /* --------------------------------------------------------------
  161. DIME RELATED FUNCTIONS
  162. ---------------------------------------------------------------*/
  163. /*
  164. DIME support httpc_dime_* function set
  165. */
  166. /*
  167. int httpc_dime_begin(httpc_conn_t *conn, const char *url);
  168. int httpc_dime_next(httpc_conn_t* conn, long content_length,
  169. const char *content_type, const char *id,
  170. const char *dime_options, int last);
  171. hresponse_t* httpc_dime_end(httpc_conn_t *conn);
  172. */
  173. /* --------------------------------------------------------------
  174. MIME RELATED FUNCTIONS
  175. ---------------------------------------------------------------*/
  176. /*
  177. MIME support httpc_mime_* function set
  178. */
  179. /**
  180. Begin MIME multipart/related POST request
  181. Returns: HSOCKET_OK or error flag
  182. */
  183. herror_t httpc_mime_begin(httpc_conn_t * conn, const char *url,
  184. const char *related_start,
  185. const char *related_start_info,
  186. const char *related_type);
  187. /**
  188. Send boundary and part header and continue
  189. with next part
  190. */
  191. herror_t httpc_mime_next(httpc_conn_t * conn,
  192. const char *content_id,
  193. const char *content_type,
  194. const char *transfer_encoding);
  195. /**
  196. Finish MIME request and get the response
  197. */
  198. herror_t httpc_mime_end(httpc_conn_t * conn, hresponse_t ** out);
  199. /**
  200. Send boundary and part header and continue
  201. with next part
  202. */
  203. herror_t httpc_mime_send_file(httpc_conn_t * conn,
  204. const char *content_id,
  205. const char *content_type,
  206. const char *transfer_encoding,
  207. const char *filename);
  208. #ifdef __cplusplus
  209. }
  210. #endif
  211. #endif