xref: /php-src/ext/sockets/conversions.h (revision 4f275952)
1 #ifndef PHP_SOCK_CONVERSIONS_H
2 #define PHP_SOCK_CONVERSIONS_H 1
3 
4 #include <php.h>
5 
6 #ifndef PHP_WIN32
7 # include <netinet/in.h>
8 # include <sys/socket.h>
9 # if defined(__FreeBSD__) || defined(__NetBSD__)
10 #  include <sys/un.h>
11 #  if defined(__FreeBSD__)
12      // we can't fully implement the ancillary data feature with
13      // the legacy sockcred/LOCAL_CREDS pair (due to lack of process
14      // id handling), so we disable it since only the
15      // sockcred2/LOCAL_CREDS_PERSISTENT pair can address it.
16 #    undef LOCAL_CREDS
17 #  endif
18 # endif
19 #else
20 # include <Ws2tcpip.h>
21 #endif
22 
23 #include "php_sockets.h"
24 
25 /* TYPE DEFINITIONS */
26 struct err_s {
27 	int		has_error;
28 	char	*msg;
29 	int		level;
30 	int		should_free;
31 };
32 
33 struct key_value {
34 	const char	*key;
35 	unsigned	key_size;
36 	void		*value;
37 };
38 
39 /* the complete types of these two are not relevant to the outside */
40 typedef struct _ser_context ser_context;
41 typedef struct _res_context res_context;
42 
43 #define KEY_RECVMSG_RET "recvmsg_ret"
44 
45 typedef void (from_zval_write_field)(const zval *arr_value, char *field, ser_context *ctx);
46 typedef void (to_zval_read_field)(const char *data, zval *zv, res_context *ctx);
47 
48 /* VARIABLE DECLARATIONS */
49 extern const struct key_value empty_key_value_list[];
50 
51 /* AUX FUNCTIONS */
52 void err_msg_dispose(struct err_s *err);
53 void allocations_dispose(zend_llist **allocations);
54 
55 /* CONVERSION FUNCTIONS */
56 void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx);
57 void to_zval_read_int(const char *data, zval *zv, res_context *ctx);
58 
59 #ifdef IPV6_PKTINFO
60 void from_zval_write_in6_pktinfo(const zval *container, char *in6_pktinfo_c, ser_context *ctx);
61 void to_zval_read_in6_pktinfo(const char *data, zval *zv, res_context *ctx);
62 #endif
63 
64 #if defined(SO_PASSCRED) || defined(LOCAL_CREDS_PERSISTENT) || defined(LOCAL_CREDS)
65 void from_zval_write_ucred(const zval *container, char *ucred_c, ser_context *ctx);
66 void to_zval_read_ucred(const char *data, zval *zv, res_context *ctx);
67 #endif
68 
69 #ifdef SCM_RIGHTS
70 size_t calculate_scm_rights_space(const zval *arr, ser_context *ctx);
71 void from_zval_write_fd_array(const zval *arr, char *int_arr, ser_context *ctx);
72 void to_zval_read_fd_array(const char *data, zval *zv, res_context *ctx);
73 #endif
74 
75 void from_zval_write_msghdr_send(const zval *container, char *msghdr_c, ser_context *ctx);
76 void from_zval_write_msghdr_recv(const zval *container, char *msghdr_c, ser_context *ctx);
77 void to_zval_read_msghdr(const char *msghdr_c, zval *zv, res_context *ctx);
78 
79 /* ENTRY POINTS FOR CONVERSIONS */
80 void *from_zval_run_conversions(const zval				*container,
81 								php_socket				*sock,
82 								from_zval_write_field	*writer,
83 								size_t					struct_size,
84 								const char				*top_name,
85 								zend_llist				**allocations /* out */,
86 								struct err_s			*err /* in/out */);
87 
88 zval *to_zval_run_conversions(const char				*structure,
89 							  to_zval_read_field		*reader,
90 							  const char				*top_name,
91 							  const struct key_value	*key_value_pairs,
92 							  struct err_s				*err, zval *zv);
93 
94 #endif
95