bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / remotecontrol / mDNSResponder / dnssd_ipc.h
blob568c5218dcb839df7361ba21607c8bb43303f169
1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef INCLUDED_SD_SOURCE_UI_REMOTECONTROL_MDNSRESPONDER_DNSSD_IPC_H
30 #define INCLUDED_SD_SOURCE_UI_REMOTECONTROL_MDNSRESPONDER_DNSSD_IPC_H
34 // Common cross platform services
36 #if defined(WIN32)
37 # include <winsock2.h>
38 #endif
40 #include "dns_sd.h"
42 #if defined(WIN32)
43 # define dnssd_InvalidSocket INVALID_SOCKET
44 # define dnssd_SocketValid(s) ((s) != INVALID_SOCKET)
45 # define dnssd_EWOULDBLOCK WSAEWOULDBLOCK
46 # define dnssd_EINTR WSAEINTR
47 # define dnssd_ECONNRESET WSAECONNRESET
48 # define dnssd_sock_t SOCKET
49 # define dnssd_socklen_t int
50 # define dnssd_close(sock) closesocket(sock)
51 # define dnssd_errno WSAGetLastError()
52 # define dnssd_strerror(X) win32_strerror(X)
53 # define ssize_t int
54 # define getpid _getpid
55 # define unlink _unlink
56 extern char *win32_strerror(int inErrorCode);
57 #else
58 # include <sys/types.h>
59 # include <unistd.h>
60 # include <sys/un.h>
61 # include <string.h>
62 # include <stdio.h>
63 # include <stdlib.h>
64 # include <sys/stat.h>
65 # include <sys/socket.h>
66 # include <netinet/in.h>
67 # include <arpa/inet.h>
68 # define dnssd_InvalidSocket -1
69 # define dnssd_SocketValid(s) ((s) >= 0)
70 # define dnssd_EWOULDBLOCK EWOULDBLOCK
71 # define dnssd_EINTR EINTR
72 # define dnssd_ECONNRESET ECONNRESET
73 # define dnssd_EPIPE EPIPE
74 # define dnssd_sock_t int
75 # define dnssd_socklen_t unsigned int
76 # define dnssd_close(sock) close(sock)
77 # define dnssd_errno errno
78 # define dnssd_strerror(X) strerror(X)
79 #endif
81 #if defined(USE_TCP_LOOPBACK)
82 # define AF_DNSSD AF_INET
83 # define MDNS_TCP_SERVERADDR "127.0.0.1"
84 # define MDNS_TCP_SERVERPORT 5354
85 # define LISTENQ 5
86 # define dnssd_sockaddr_t struct sockaddr_in
87 #else
88 # define AF_DNSSD AF_LOCAL
89 # ifndef MDNS_UDS_SERVERPATH
90 # define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
91 # endif
92 # define LISTENQ 100
93 // longest legal control path length
94 # define MAX_CTLPATH 256
95 # define dnssd_sockaddr_t struct sockaddr_un
96 #endif
98 // Compatibility workaround
99 #ifndef AF_LOCAL
100 #define AF_LOCAL AF_UNIX
101 #endif
103 // General UDS constants
104 #define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
106 // IPC data encoding constants and types
107 #define VERSION 1
108 #define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
110 // Structure packing macro. If we're not using GNUC, it's not fatal. Most compilers naturally pack the on-the-wire
111 // structures correctly anyway, so a plain "struct" is usually fine. In the event that structures are not packed
112 // correctly, our compile-time assertion checks will catch it and prevent inadvertent generation of non-working code.
113 #ifndef packedstruct
114 #if ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 9)))
115 #define packedstruct struct __attribute__((__packed__))
116 #define packedunion union __attribute__((__packed__))
117 #else
118 #define packedstruct struct
119 #define packedunion union
120 #endif
121 #endif
123 typedef enum
125 request_op_none = 0, // No request yet received on this connection
126 connection_request = 1, // connected socket via DNSServiceConnect()
127 reg_record_request, // reg/remove record only valid for connected sockets
128 remove_record_request,
129 enumeration_request,
130 reg_service_request,
131 browse_request,
132 resolve_request,
133 query_request,
134 reconfirm_record_request,
135 add_record_request,
136 update_record_request,
137 setdomain_request, // Up to here is in Tiger and B4W 1.0.3
138 getproperty_request, // New in B4W 1.0.4
139 port_mapping_request, // New in Leopard and B4W 2.0
140 addrinfo_request,
141 send_bpf, // New in SL
142 release_request,
144 cancel_request = 63
145 } request_op_t;
147 typedef enum
149 enumeration_reply_op = 64,
150 reg_service_reply_op,
151 browse_reply_op,
152 resolve_reply_op,
153 query_reply_op,
154 reg_record_reply_op, // Up to here is in Tiger and B4W 1.0.3
155 getproperty_reply_op, // New in B4W 1.0.4
156 port_mapping_reply_op, // New in Leopard and B4W 2.0
157 addrinfo_reply_op
158 } reply_op_t;
160 #if defined(_WIN64)
161 # pragma pack(push,4)
162 #endif
164 // Define context object big enough to hold a 64-bit pointer,
165 // to accommodate 64-bit clients communicating with 32-bit daemon.
166 // There's no reason for the daemon to ever be a 64-bit process, but its clients might be
167 typedef packedunion
169 void *context;
170 uint32_t u32[2];
171 } client_context_t;
173 typedef packedstruct
175 uint32_t version;
176 uint32_t datalen;
177 uint32_t ipc_flags;
178 uint32_t op; // request_op_t or reply_op_t
179 client_context_t client_context; // context passed from client, returned by server in corresponding reply
180 uint32_t reg_index; // identifier for a record registered via DNSServiceRegisterRecord() on a
181 // socket connected by DNSServiceCreateConnection(). Must be unique in the scope of the connection, such that and
182 // index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
183 } ipc_msg_hdr;
185 #if defined(_WIN64)
186 # pragma pack(pop)
187 #endif
189 // routines to write to and extract data from message buffers.
190 // caller responsible for bounds checking.
191 // ptr is the address of the pointer to the start of the field.
192 // it is advanced to point to the next field, or the end of the message
194 void put_uint32(const uint32_t l, char **ptr);
195 uint32_t get_uint32(const char **ptr, const char *end);
197 void put_uint16(uint16_t s, char **ptr);
198 uint16_t get_uint16(const char **ptr, const char *end);
200 #define put_flags put_uint32
201 #define get_flags get_uint32
203 #define get_error_code get_uint32
205 int put_string(const char *str, char **ptr);
206 int get_string(const char **ptr, const char *const end, char *buffer, int buflen);
208 void put_rdata(const int rdlen, const unsigned char *rdata, char **ptr);
209 const char *get_rdata(const char **ptr, const char *end, int rdlen); // return value is rdata pointed to by *ptr -
210 // rdata is not copied from buffer.
212 void ConvertHeaderBytes(ipc_msg_hdr *hdr);
214 struct CompileTimeAssertionChecks_dnssd_ipc
216 // Check that the compiler generated our on-the-wire packet format structure definitions
217 // properly packed, without adding padding bytes to align fields on 32-bit or 64-bit boundaries.
218 char assert0[(sizeof(client_context_t) == 8) ? 1 : -1];
219 char assert1[(sizeof(ipc_msg_hdr) == 28) ? 1 : -1];
222 #endif // INCLUDED_SD_SOURCE_UI_REMOTECONTROL_MDNSRESPONDER_DNSSD_IPC_H