blob: 749cd3766e01aedbccbd2679ca36cdf7ac6222b4 [file] [log] [blame]
yuezonghec78e2ef2025-02-13 17:57:46 -08001/*******************************************************************************
2 * Copyright (c) 2014 IBM Corp.
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * and Eclipse Distribution License v1.0 which accompany this distribution.
7 *
8 * The Eclipse Public License is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 * and the Eclipse Distribution License is available at
11 * http://www.eclipse.org/org/documents/edl-v10.php.
12 *
13 * Contributors:
14 * Allan Stockdill-Mander - initial API and implementation and/or initial documentation
15 *******************************************************************************/
16
17#if !defined(__MQTT_LINUX_)
18#define __MQTT_LINUX_
19
20#if defined(WIN32_DLL) || defined(WIN64_DLL)
21 #define DLLImport __declspec(dllimport)
22 #define DLLExport __declspec(dllexport)
23#elif defined(LINUX_SO)
24 #define DLLImport extern
25 #define DLLExport __attribute__ ((visibility ("default")))
26#else
27 #define DLLImport
28 #define DLLExport
29#endif
30
31#include <sys/types.h>
32#include <sys/socket.h>
33#include <sys/param.h>
34#include <sys/time.h>
35#include <sys/select.h>
36#include <netinet/in.h>
37#include <netinet/tcp.h>
38#include <arpa/inet.h>
39#include <netdb.h>
40#include <stdio.h>
41#include <unistd.h>
42#include <errno.h>
43#include <fcntl.h>
44
45
46#include <openssl/ssl.h>
47#include <openssl/err.h>
48#include <openssl/evp.h>
49#include <stdlib.h>
50#include <string.h>
51#include <signal.h>
52
53typedef struct Timer
54{
55 struct timeval end_time;
56} Timer;
57
58void TimerInit(Timer*);
59char TimerIsExpired(Timer*);
60void TimerCountdownMS(Timer*, unsigned int);
61void TimerCountdown(Timer*, unsigned int);
62int TimerLeftMS(Timer*);
63
64typedef struct Network
65{
66 int my_socket;
67 int (*mqttread) (struct Network*, unsigned char*, int, int);
68 int (*mqttwrite) (struct Network*, unsigned char*, int, int);
69 SSL *ssl;
70 int useSSL;
71} Network;
72
73int linux_read(Network*, unsigned char*, int, int);
74int linux_write(Network*, unsigned char*, int, int);
75
76DLLExport void NetworkInit(Network*);
77DLLExport int NetworkConnect(Network*, char*, int);
78DLLExport int NetworkConnectBySSL(Network*, const char*, int, const char*);
79DLLExport int NetworkConnectNotSSL(Network*, const char*, const char*);
80DLLExport void NetworkDisconnect(Network*);
81DLLExport void ShowCerts(SSL *);
82
83#endif