Barracuda Application Server C/C++ Reference
NO
selib.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * SharkSSL Embedded SSL/TLS Stack
10 ****************************************************************************
11 * PROGRAM MODULE
12 *
13 * $Id: selib.h 4914 2021-12-01 18:24:30Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2014 - 2018
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * https://realtimelogic.com
33 ****************************************************************************
34 *
35 */
36
37#ifndef _selib_h
38#define _selib_h
39
40/*
41 The SharkSSL compatibility API makes it easy to write code that can
42 later be upgraded to a secure version, if needed.
43*/
44#ifndef SHARKSSL_COMPAT
45#define SHARKSSL_COMPAT 1
46#endif
47
48#ifndef SE_SHA1
49#define SE_SHA1 1
50#endif
51
52
57#ifndef INTEGRAL_TYPES
58#define INTEGRAL_TYPES
59#ifndef XTYPES
60#ifndef NO_C99
61#include <stdint.h>
62typedef uint8_t U8;
63#ifndef __MBED__
64typedef int8_t S8;
65#endif
66typedef uint16_t U16;
67typedef int16_t S16;
68typedef uint32_t U32;
69typedef int32_t S32;
70typedef uint64_t U64;
71typedef int64_t S64;
72#else
73typedef unsigned char U8;
74typedef signed char S8;
75typedef unsigned short U16;
76typedef signed short S16;
77typedef unsigned long U32;
78typedef signed long S32;
79typedef unsigned long long U64;
80typedef signed long long S64;
81#endif
82#endif
83#endif
84
85#ifndef BaBool
86#define BaBool U8
87#endif
88
91#define INFINITE_TMO (~((U32)0))
92
93#include "selibplat.h"
94
95#ifndef SE_CTX
96#define SeCtx void
97#endif
98
99#ifndef XPRINTF
100#define XPRINTF 0
101#endif
102
103#ifndef TRUE
104#define TRUE 1
105#endif
106
107#ifndef FALSE
108#define FALSE 0
109#endif
110
111#ifndef baAssert
112#ifdef NDEBUG
113#define baAssert(x)
114#else
115#ifdef PRINT_ASSERT
116#define baAssert(x) if(x) xprintf(("failed assertion %s %d\n",__FILE__, __LINE__))
117#else
118#include <assert.h>
119#define baAssert assert
120#endif
121#endif
122#endif
123
124#include <string.h>
125#if XPRINTF
126#include <stdarg.h>
127#endif
128
129#ifdef UMM_MALLOC
130#include <umm_malloc.h>
131#define baMalloc(s) umm_malloc(s)
132#define baRealloc(m, s) umm_realloc(m, s)
133#define baFree(m) umm_free(m)
134#endif
135
136#ifndef NO_BSD_SOCK
142#define SOCKET int
143#endif
144
145#ifndef SE_CTX
146#define SeCtx void
147#endif
148
149#ifndef SOCKET_constructor
150#define SOCKET_constructor(o, ctx) (void)ctx,memset(o,0,sizeof(SOCKET))
151#endif
152
153
154#ifdef __cplusplus
155extern "C" {
156#endif
157
166int se_connect(SOCKET* sock, const char* address, U16 port);
167
176int se_bind(SOCKET* sock, U16 port);
177
187int se_accept(SOCKET** listenSock, U32 timeout, SOCKET** outSock);
188
191void se_close(SOCKET* sock);
192
196
199S32 se_send(SOCKET* sock, const void* buf, U32 len);
200
210S32 se_recv(SOCKET* sock, void* buf, U32 len, U32 timeout);
211
212/* Macro function designed for IPv4
213 sock: a pointer to SOCKET
214 buf: a buf large enough to hold 4 bytes
215 status: int pointer: out value is negative on error and 4 (len) on success
216*/
217#ifndef se_getSockName
218#define se_getSockName(sock, buf, status) do { \
219 struct sockaddr_in in; int size=sizeof(struct sockaddr_in); \
220 *(status) = getsockname(*(sock), (struct sockaddr *)&in, &size); \
221 memcpy((buf), &in.sin_addr.s_addr, 4); \
222 if(*(status) == 0) *(status) = 4; \
223} while(0)
224#endif
225
226
227#if XPRINTF == 1
233#define xprintf(data) _xprintf data
239#ifndef _xprintf /* to handle #define _xprintf printf */
240void _xprintf(const char* fmt, ...);
241#endif
242#else
243#ifndef xprintf
244#define xprintf(data)
245#endif
246#endif
247
249void mainTask(SeCtx* ctx);
250
251#ifdef __cplusplus
252}
253#endif
254
255
256#if SHARKSSL_COMPAT
257typedef struct {void* x; } SharkSsl;
258#define SharkSsl_constructor(sharkSsl, type, cache, inSize,outSize)
259#define SharkSsl_setCAList(sharkSsl, sharkSslCAList)
260#define sharkssl_entropy(entropy)
261#define SharkSsl_createCon(sharkSsl) ((void*)~0)
262#define SharkSsl_terminateCon(sharkSsl, scon)
263#define SharkSsl_destructor(sharkSsl)
264#define SharkSsl_addCertificate(sharkSsl, cert)
265
266#define SharkSslCon void
267
268#if SE_SHA1
269#define SHARKSSL_SHA1_HASH_LEN 20
270typedef struct SharkSslSha1Ctx
271{
272 U32 total[2];
273 U32 state[5];
274 U8 buffer[64];
275} SharkSslSha1Ctx;
276void SharkSslSha1Ctx_constructor(SharkSslSha1Ctx* ctx);
277void SharkSslSha1Ctx_append(SharkSslSha1Ctx* ctx, const U8* data, U32 len);
278void SharkSslSha1Ctx_finish(SharkSslSha1Ctx*,U8 digest[SHARKSSL_SHA1_HASH_LEN]);
279#endif
280
281
282
283#endif
284
285 /* end group selib */
287
288#endif
void se_close(SOCKET *sock)
Close a connected socket connection.
int se_accept(SOCKET **listenSock, U32 timeout, SOCKET **outSock)
Waits for remote connections on the server SOCKET object 'listenSock', initialized by function se_bin...
S32 se_send(SOCKET *sock, const void *buf, U32 len)
Sends data to the connected peer.
int se_connect(SOCKET *sock, const char *address, U16 port)
Initializes a SOCKET object connected to a remote host/address at a given port.
int se_sockValid(SOCKET *sock)
Returns TRUE if socket is valid (connected).
void mainTask(SeCtx *ctx)
Main entry for all example programs.
int se_bind(SOCKET *sock, U16 port)
Initializes a SOCKET object bound to a local port, ready to accept client connections.
S32 se_recv(SOCKET *sock, void *buf, U32 len, U32 timeout)
Waits for data sent by peer.
#define SOCKET
The SOCKET object/handle is an 'int' when using a BSD compatible TCP/IP stack.
Definition: selib.h:142
SeCtx structure: See Context Manager and Bare Metal Systems for details.
Definition: SeCtx.h:71