yuezonghe | c78e2ef | 2025-02-13 17:57:46 -0800 | [diff] [blame^] | 1 | /*******************************************************************************
|
| 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 |
|
| 53 | typedef struct Timer
|
| 54 | {
|
| 55 | struct timeval end_time;
|
| 56 | } Timer;
|
| 57 |
|
| 58 | void TimerInit(Timer*);
|
| 59 | char TimerIsExpired(Timer*);
|
| 60 | void TimerCountdownMS(Timer*, unsigned int);
|
| 61 | void TimerCountdown(Timer*, unsigned int);
|
| 62 | int TimerLeftMS(Timer*);
|
| 63 |
|
| 64 | typedef 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 |
|
| 73 | int linux_read(Network*, unsigned char*, int, int);
|
| 74 | int linux_write(Network*, unsigned char*, int, int);
|
| 75 |
|
| 76 | DLLExport void NetworkInit(Network*);
|
| 77 | DLLExport int NetworkConnect(Network*, char*, int);
|
| 78 | DLLExport int NetworkConnectBySSL(Network*, const char*, int, const char*);
|
| 79 | DLLExport int NetworkConnectNotSSL(Network*, const char*, const char*);
|
| 80 | DLLExport void NetworkDisconnect(Network*);
|
| 81 | DLLExport void ShowCerts(SSL *);
|
| 82 |
|
| 83 | #endif
|