conversions.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef PHP_SOCK_CONVERSIONS_H
  2. #define PHP_SOCK_CONVERSIONS_H 1
  3. #include <php.h>
  4. #ifndef PHP_WIN32
  5. # include <netinet/in.h>
  6. # include <sys/socket.h>
  7. #else
  8. # include <Ws2tcpip.h>
  9. #endif
  10. #include "php_sockets.h"
  11. /* TYPE DEFINITIONS */
  12. struct err_s {
  13. int has_error;
  14. char *msg;
  15. int level;
  16. int should_free;
  17. };
  18. struct key_value {
  19. const char *key;
  20. unsigned key_size;
  21. void *value;
  22. };
  23. /* the complete types of these two are not relevant to the outside */
  24. typedef struct _ser_context ser_context;
  25. typedef struct _res_context res_context;
  26. #define KEY_RECVMSG_RET "recvmsg_ret"
  27. typedef void (from_zval_write_field)(const zval *arr_value, char *field, ser_context *ctx);
  28. typedef void (to_zval_read_field)(const char *data, zval *zv, res_context *ctx);
  29. /* VARIABLE DECLARATIONS */
  30. extern const struct key_value empty_key_value_list[];
  31. /* AUX FUNCTIONS */
  32. void err_msg_dispose(struct err_s *err);
  33. void allocations_dispose(zend_llist **allocations);
  34. /* CONVERSION FUNCTIONS */
  35. void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx);
  36. void to_zval_read_int(const char *data, zval *zv, res_context *ctx);
  37. #ifdef IPV6_PKTINFO
  38. void from_zval_write_in6_pktinfo(const zval *container, char *in6_pktinfo_c, ser_context *ctx);
  39. void to_zval_read_in6_pktinfo(const char *data, zval *zv, res_context *ctx);
  40. #endif
  41. #ifdef SO_PASSCRED
  42. void from_zval_write_ucred(const zval *container, char *ucred_c, ser_context *ctx);
  43. void to_zval_read_ucred(const char *data, zval *zv, res_context *ctx);
  44. #endif
  45. #ifdef SCM_RIGHTS
  46. size_t calculate_scm_rights_space(const zval *arr, ser_context *ctx);
  47. void from_zval_write_fd_array(const zval *arr, char *int_arr, ser_context *ctx);
  48. void to_zval_read_fd_array(const char *data, zval *zv, res_context *ctx);
  49. #endif
  50. void from_zval_write_msghdr_send(const zval *container, char *msghdr_c, ser_context *ctx);
  51. void from_zval_write_msghdr_recv(const zval *container, char *msghdr_c, ser_context *ctx);
  52. void to_zval_read_msghdr(const char *msghdr_c, zval *zv, res_context *ctx);
  53. /* ENTRY POINTS FOR CONVERSIONS */
  54. void *from_zval_run_conversions(const zval *container,
  55. php_socket *sock,
  56. from_zval_write_field *writer,
  57. size_t struct_size,
  58. const char *top_name,
  59. zend_llist **allocations /* out */,
  60. struct err_s *err /* in/out */);
  61. zval *to_zval_run_conversions(const char *structure,
  62. to_zval_read_field *reader,
  63. const char *top_name,
  64. const struct key_value *key_value_pairs,
  65. struct err_s *err, zval *zv);
  66. #endif