aboutsummaryrefslogtreecommitdiffstats
path: root/addons/ooh323c/src/ooSocket.h
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-06-30 16:40:38 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-06-30 16:40:38 +0000
commite9d15cbea7a98184521c851500176da7aa424012 (patch)
treed3d6aa7ea86d11ecaa6e88efbc46a5dde1c63ea5 /addons/ooh323c/src/ooSocket.h
parentb85bdd32a783a8f07004d41db8a696645685a331 (diff)
Move Asterisk-addons modules into the main Asterisk source tree.
Someone asked yesterday, "is there a good reason why we can't just put these modules in Asterisk?". After a brief discussion, as long as the modules are clearly set aside in their own directory and not enabled by default, it is perfectly fine. For more information about why a module goes in addons, see README-addons.txt. chan_ooh323 does not currently compile as it is behind some trunk API updates. However, it will not build by default, so it should be okay for now. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@204413 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'addons/ooh323c/src/ooSocket.h')
-rw-r--r--addons/ooh323c/src/ooSocket.h403
1 files changed, 403 insertions, 0 deletions
diff --git a/addons/ooh323c/src/ooSocket.h b/addons/ooh323c/src/ooSocket.h
new file mode 100644
index 000000000..6a28ef3ac
--- /dev/null
+++ b/addons/ooh323c/src/ooSocket.h
@@ -0,0 +1,403 @@
+/*
+ * Copyright (C) 1997-2005 by Objective Systems, Inc.
+ *
+ * This software is furnished under an open source license and may be
+ * used and copied only in accordance with the terms of this license.
+ * The text of the license may generally be found in the root
+ * directory of this installation in the COPYING file. It
+ * can also be viewed online at the following URL:
+ *
+ * http://www.obj-sys.com/open/license.html
+ *
+ * Any redistributions of this file including modified versions must
+ * maintain this copyright notice.
+ *
+ *****************************************************************************/
+
+/**
+ * @file ooSocket.h
+ * Common runtime constants, data structure definitions, and run-time functions
+ * to support the sockets' operations.
+ */
+#ifndef _OOSOCKET_H_
+#define _OOSOCKET_H_
+
+#ifdef _WIN32_WCE
+#include <winsock.h>
+#elif defined(_WIN32) || defined(_WIN64)
+#include <sys/types.h>
+#define INCL_WINSOCK_API_TYPEDEFS 1
+#define INCL_WINSOCK_API_PROTOTYPES 0
+#include <winsock2.h>
+#else
+#include <sys/types.h>
+#include "sys/time.h"
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+#endif
+
+#include "ooasn1.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef EXTERN
+#ifdef MAKE_DLL
+#define EXTERN __declspec(dllexport)
+#elif defined (USEASN1DLL)
+#define EXTERN __declspec(dllimport)
+#else
+#define EXTERN
+#endif /* MAKE_DLL */
+#endif /* EXTERN */
+
+/**
+ * @defgroup sockets Socket Layer
+ * @{
+ */
+#if defined (_WIN64)
+typedef unsigned __int64 OOSOCKET; /**< Socket's handle */
+#elif defined (_WIN32)
+typedef unsigned int OOSOCKET; /**< Socket's handle */
+#else
+typedef int OOSOCKET; /**< Socket's handle */
+#endif
+
+#define OOSOCKET_INVALID ((OOSOCKET)-1)
+
+
+/**
+ * The IP address represented as unsigned long value. The most significant 8
+ * bits in this unsigned long value represent the first number of the IP
+ * address. The least significant 8 bits represent the last number of the IP
+ * address.
+ */
+typedef unsigned long OOIPADDR;
+
+#define OOIPADDR_ANY ((OOIPADDR)0)
+#define OOIPADDR_LOCAL ((OOIPADDR)0x7f000001UL) /* 127.0.0.1 */
+
+typedef struct OOInterface{
+ char *name;
+ char *addr;
+ char *mask;
+ struct OOInterface *next;
+}OOInterface;
+
+
+
+/**
+ * This function permits an incoming connection attempt on a socket. It
+ * extracts the first connection on the queue of pending connections on socket.
+ * It then creates a new socket and returns a handle to the new socket. The
+ * newly created socket is the socket that will handle the actual connection
+ * and has the same properties as original socket. See description of 'accept'
+ * socket function for further details.
+ *
+ * @param socket The socket's handle created by call to ::rtSocketCreate
+ * function.
+ * @param pNewSocket The pointer to variable to receive the new socket's
+ * handle.
+ * @param destAddr Optional pointer to a buffer that receives the IP
+ * address of the connecting entity. It may be NULL.
+ * @param destPort Optional pointer to a buffer that receives the port of
+ * the connecting entity. It may be NULL.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketAccept (OOSOCKET socket, OOSOCKET *pNewSocket,
+ OOIPADDR* destAddr, int* destPort);
+
+/**
+ * This function converts an IP address to its string representation.
+ *
+ * @param ipAddr The IP address to be converted.
+ * @param pbuf Pointer to the buffer to receive a string with the IP
+ * address.
+ * @param bufsize Size of the buffer.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketAddrToStr (OOIPADDR ipAddr, char* pbuf, int bufsize);
+
+/**
+ * This function associates a local address with a socket. It is used on an
+ * unconnected socket before subsequent calls to the ::rtSocketConnect or
+ * ::rtSocketListen functions. See description of 'bind' socket function for
+ * further details.
+ *
+ * @param socket The socket's handle created by call to ::rtSocketCreate
+ * function.
+ * @param addr The local IP address to assign to the socket.
+ * @param port The local port number to assign to the socket.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketBind (OOSOCKET socket, OOIPADDR addr, int port);
+
+/**
+ * This function closes an existing socket.
+ *
+ * @param socket The socket's handle created by call to ::rtSocketCreate
+ * or ::rtSocketAccept function.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketClose (OOSOCKET socket);
+
+/**
+ * This function establishes a connection to a specified socket. It is used to
+ * create a connection to the specified destination. When the socket call
+ * completes successfully, the socket is ready to send and receive data. See
+ * description of 'connect' socket function for further details.
+ *
+ * @param socket The socket's handle created by call to ::rtSocketCreate
+ * function.
+ * @param host The null-terminated string with the IP address in the
+ * following format: "NNN.NNN.NNN.NNN", where NNN is a
+ * number in the range (0..255).
+ * @param port The destination port to connect.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketConnect (OOSOCKET socket, const char* host, int port);
+
+/**
+ * This function creates a socket. The only streaming TCP/IP sockets are
+ * supported at the moment.
+ *
+ * @param psocket The pointer to the socket's handle variable to receive
+ * the handle of new socket.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketCreate (OOSOCKET* psocket);
+
+/**
+ * This function creates a UDP datagram socket.
+ *
+ * @param psocket The pointer to the socket's handle variable to receive
+ * the handle of new socket.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketCreateUDP (OOSOCKET* psocket);
+
+/**
+ * This function initiates use of sockets by an application. This function must
+ * be called first before use sockets.
+ *
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketsInit (void);
+
+/**
+ * This function terminates use of sockets by an application. This function
+ * must be called after done with sockets.
+ *
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketsCleanup (void);
+
+/**
+ * This function places a socket a state where it is listening for an incoming
+ * connection. To accept connections, a socket is first created with the
+ * ::rtSocketCreate function and bound to a local address with the
+ * ::rtSocketBind function, a maxConnection for incoming connections is
+ * specified with ::rtSocketListen, and then the connections are accepted with
+ * the ::rtSocketAccept function. See description of 'listen' socket function
+ * for further details.
+ *
+ * @param socket The socket's handle created by call to
+ * ::rtSocketCreate function.
+ * @param maxConnection Maximum length of the queue of pending connections.
+ * @return Completion status of operation: 0 (ASN_OK) =
+ * success, negative return value is error.
+ */
+EXTERN int ooSocketListen (OOSOCKET socket, int maxConnection);
+
+
+/**
+ * This function is used to peek at the received data without actually removing
+ * it from the receive socket buffer. A receive call after this will get the
+ * same data from the socket.
+ * @param socket The socket's handle created by call to ::rtSocketCreate
+ * or ::rtSocketAccept function.
+ * @param pbuf Pointer to the buffer for the incoming data.
+ * @param bufsize Length of the buffer.
+ * @return If no error occurs, returns the number of bytes
+ * received. Otherwise, the negative value is error code.
+ */
+EXTERN int ooSocketRecvPeek
+ (OOSOCKET socket, ASN1OCTET* pbuf, ASN1UINT bufsize);
+
+/**
+ * This function receives data from a connected socket. It is used to read
+ * incoming data on sockets. The socket must be connected before calling this
+ * function. See description of 'recv' socket function for further details.
+ *
+ * @param socket The socket's handle created by call to ::rtSocketCreate
+ * or ::rtSocketAccept function.
+ * @param pbuf Pointer to the buffer for the incoming data.
+ * @param bufsize Length of the buffer.
+ * @return If no error occurs, returns the number of bytes
+ * received. Otherwise, the negative value is error code.
+ */
+EXTERN int ooSocketRecv (OOSOCKET socket, ASN1OCTET* pbuf,
+ ASN1UINT bufsize);
+
+/**
+ * This function receives data from a connected/unconnected socket. It is used
+ * to read incoming data on sockets. It populates the remotehost and
+ * remoteport parameters with information of remote host. See description of
+ * 'recvfrom' socket function for further details.
+ *
+ * @param socket The socket's handle created by call to ooSocketCreate
+ *
+ * @param pbuf Pointer to the buffer for the incoming data.
+ * @param bufsize Length of the buffer.
+ * @param remotehost Pointer to a buffer in which remote ip address
+ * will be returned.
+ * @param hostBufLen Length of the buffer passed for remote ip address.
+ * @param remoteport Pointer to an int in which remote port number
+ * will be returned.
+ *
+ * @return If no error occurs, returns the number of bytes
+ * received. Otherwise, negative value.
+ */
+EXTERN int ooSocketRecvFrom (OOSOCKET socket, ASN1OCTET* pbuf,
+ ASN1UINT bufsize, char * remotehost,
+ ASN1UINT hostBufLen, int * remoteport);
+/**
+ * This function sends data on a connected socket. It is used to write outgoing
+ * data on a connected socket. See description of 'send' socket function for
+ * further details.
+ *
+ * @param socket The socket's handle created by call to ::rtSocketCreate
+ * or ::rtSocketAccept function.
+ * @param pdata Buffer containing the data to be transmitted.
+ * @param size Length of the data in pdata.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketSend (OOSOCKET socket, const ASN1OCTET* pdata,
+ ASN1UINT size);
+
+/**
+ * This function sends data on a connected or unconnected socket. See
+ * description of 'sendto' socket function for further details.
+ *
+ * @param socket The socket's handle created by call to ::rtSocketCreate
+ * or ::rtSocketAccept function.
+ * @param pdata Buffer containing the data to be transmitted.
+ * @param size Length of the data in pdata.
+ * @param remotehost Remote host ip address to which data has to
+ * be sent.
+ * @param remoteport Remote port ip address to which data has to
+ * be sent.
+ *
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketSendTo(OOSOCKET socket, const ASN1OCTET* pdata,
+ ASN1UINT size, const char* remotehost,
+ int remoteport);
+
+/**
+ * This function is used for synchronous monitoring of multiple sockets.
+ * For more information refer to documnetation of "select" system call.
+ *
+ * @param nfds The highest numbered descriptor to be monitored
+ * plus one.
+ * @param readfds The descriptors listed in readfds will be watched for
+ * whether read would block on them.
+ * @param writefds The descriptors listed in writefds will be watched for
+ * whether write would block on them.
+ * @param exceptfds The descriptors listed in exceptfds will be watched for
+ * exceptions.
+ * @param timeout Upper bound on amout of time elapsed before select
+ * returns.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketSelect(int nfds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval * timeout);
+
+/**
+ * This function converts the string with IP address to a double word
+ * representation. The converted address may be used with the ::rtSocketBind
+ * function.
+ *
+ * @param pIPAddrStr The null-terminated string with the IP address in the
+ * following format: "NNN.NNN.NNN.NNN", where NNN is a
+ * number in the range (0..255).
+ * @param pIPAddr Pointer to the converted IP address.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketStrToAddr (const char* pIPAddrStr, OOIPADDR* pIPAddr);
+
+/**
+ * This function converts an internet dotted ip address to network address
+ *
+ * @param inetIp The null-terminated string with the IP address in the
+ * following format: "NNN.NNN.NNN.NNN", where NNN is a
+ * number in the range (0..255).
+ * @param netIp Buffer in which the converted address will be returned.
+
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooSocketConvertIpToNwAddr(char *inetIp, char *netIp);
+
+/**
+ * This function retrives the IP address of the local host.
+ *
+ * @param pIPAddrs Pointer to a char buffer in which local IP address will be
+ * returned.
+ * @return Completion status of operation: 0 (ASN_OK) = success,
+ * negative return value is error.
+ */
+EXTERN int ooGetLocalIPAddress(char * pIPAddrs);
+
+
+EXTERN int ooSocketGetSockName(OOSOCKET socket, struct sockaddr_in *name,
+ int *size);
+
+
+EXTERN long ooSocketHTONL(long val);
+
+EXTERN short ooSocketHTONS(short val);
+
+/**
+ * This function is used to retrieve the ip and port number used by the socket
+ * passed as parameter. It internally uses getsockname system call for this
+ * purpose.
+ * @param socket Socket for which ip and port has to be determined.
+ * @param ip Buffer in which ip address will be returned.
+ * @param len Length of the ip address buffer.
+ * @param port Pointer to integer in which port number will be returned.
+ *
+ * @return ASN_OK, on success; -ve on failed.
+ */
+EXTERN int ooSocketGetIpAndPort(OOSOCKET socket, char *ip, int len, int *port);
+
+
+EXTERN int ooSocketGetInterfaceList(OOCTXT *pctxt, OOInterface **ifList);
+/**
+ * @}
+ */
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _OOSOCKET_H_ */
+