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.

157 lines
4.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: nanohttp-server.h,v 1.21 2006/05/31 19:39:34 mrcsys 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_SERVER_H
  25. #define NANO_HTTP_SERVER_H
  26. #include <nanohttp/nanohttp-common.h>
  27. #include <nanohttp/nanohttp-socket.h>
  28. #include <nanohttp/nanohttp-request.h>
  29. #include <nanohttp/nanohttp-stream.h>
  30. typedef struct httpd_conn
  31. {
  32. hsocket_t *sock;
  33. char content_type[25];
  34. http_output_stream_t *out;
  35. hpair_t *header;
  36. }
  37. httpd_conn_t;
  38. /*
  39. Service callback
  40. */
  41. typedef void (*httpd_service) (httpd_conn_t *, hrequest_t *);
  42. typedef int (*httpd_auth) (hrequest_t * req, const char *user,
  43. const char *password);
  44. /*
  45. * Service representation object
  46. */
  47. typedef struct tag_hservice
  48. {
  49. char ctx[255];
  50. httpd_service func;
  51. httpd_auth auth;
  52. struct tag_hservice *next;
  53. }
  54. hservice_t;
  55. #ifdef __cplusplus
  56. extern "C"
  57. {
  58. #endif
  59. /*
  60. Begin httpd_* function set
  61. */
  62. herror_t httpd_init(int argc, char *argv[]);
  63. void httpd_destroy(void);
  64. herror_t httpd_run(void);
  65. int httpd_register(const char *ctx, httpd_service service);
  66. int httpd_register_secure(const char *ctx, httpd_service service,
  67. httpd_auth auth);
  68. int httpd_register_default(const char *ctx, httpd_service service);
  69. int httpd_register_default_secure(const char *ctx, httpd_service service,
  70. httpd_auth auth);
  71. int httpd_get_port(void);
  72. int httpd_get_timeout(void);
  73. void httpd_set_timeout(int t);
  74. const char *httpd_get_protocol(void);
  75. int httpd_get_conncount(void);
  76. hservice_t *httpd_services(void);
  77. herror_t httpd_send_header(httpd_conn_t * res, int code, const char *text);
  78. int httpd_set_header(httpd_conn_t * conn, const char *key,
  79. const char *value);
  80. void httpd_set_headers(httpd_conn_t * conn, hpair_t * header);
  81. int httpd_add_header(httpd_conn_t * conn, const char *key,
  82. const char *value);
  83. void httpd_add_headers(httpd_conn_t * conn, const hpair_t * values);
  84. /*
  85. unsigned char *httpd_get_postdata(httpd_conn_t *conn,
  86. hrequest_t *req, long *received, long max);
  87. */
  88. /* --------------------------------------------------------------
  89. MIME RELATED FUNCTIONS
  90. ---------------------------------------------------------------*/
  91. /*
  92. MIME support httpd_mime_* function set
  93. */
  94. /**
  95. Begin MIME multipart/related POST
  96. Returns: HSOCKET_OK or error flag
  97. */
  98. herror_t httpd_mime_send_header(httpd_conn_t * conn,
  99. const char *related_start,
  100. const char *related_start_info,
  101. const char *related_type, int code,
  102. const char *text);
  103. /**
  104. Send boundary and part header and continue
  105. with next part
  106. */
  107. herror_t httpd_mime_next(httpd_conn_t * conn,
  108. const char *content_id,
  109. const char *content_type,
  110. const char *transfer_encoding);
  111. /**
  112. Send boundary and part header and continue
  113. with next part
  114. */
  115. herror_t httpd_mime_send_file(httpd_conn_t * conn,
  116. const char *content_id,
  117. const char *content_type,
  118. const char *transfer_encoding,
  119. const char *filename);
  120. /**
  121. Finish MIME request
  122. Returns: HSOCKET_OK or error flag
  123. */
  124. herror_t httpd_mime_end(httpd_conn_t * conn);
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif