A simple library to support serving https.

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Wed Aug 28 07:10:59 2019 +0000
Revision:
5:ee5489ee1117
Parent:
2:82268409e83f
Child:
10:e269fd7b9500
Added connection status

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 5:ee5489ee1117 1 #include <stdlib.h>
andrewboyson 2:82268409e83f 2 #include <stdint.h>
andrewboyson 2:82268409e83f 3 #include <stdbool.h>
andrewboyson 2:82268409e83f 4
andrewboyson 2:82268409e83f 5 #include "tls-session.h"
andrewboyson 2:82268409e83f 6 #include "mstimer.h"
andrewboyson 2:82268409e83f 7
andrewboyson 2:82268409e83f 8 #define TLS_MAX_SESSIONS 4
andrewboyson 2:82268409e83f 9
andrewboyson 2:82268409e83f 10 static struct TlsSession sessions[TLS_MAX_SESSIONS];
andrewboyson 2:82268409e83f 11
andrewboyson 5:ee5489ee1117 12 struct TlsSession* TlsSessionGetOldest() //Never fails so never returns NULL
andrewboyson 2:82268409e83f 13 {
andrewboyson 2:82268409e83f 14 struct TlsSession* pOldest = 0;
andrewboyson 2:82268409e83f 15 uint32_t ageOldest = 0;
andrewboyson 5:ee5489ee1117 16 for (struct TlsSession* p = sessions; p < sessions + TLS_MAX_SESSIONS; p++)
andrewboyson 2:82268409e83f 17 {
andrewboyson 5:ee5489ee1117 18 if (!p->state) return p; //Found an empty slot so just return it
andrewboyson 5:ee5489ee1117 19 uint32_t age = MsTimerCount - p->lastUsed;
andrewboyson 2:82268409e83f 20 if (age >= ageOldest)
andrewboyson 2:82268409e83f 21 {
andrewboyson 2:82268409e83f 22 ageOldest = age;
andrewboyson 5:ee5489ee1117 23 pOldest = p;
andrewboyson 2:82268409e83f 24 }
andrewboyson 2:82268409e83f 25 }
andrewboyson 2:82268409e83f 26 return pOldest; //Otherwise return the oldest
andrewboyson 2:82268409e83f 27 }
andrewboyson 2:82268409e83f 28
andrewboyson 5:ee5489ee1117 29 struct TlsSession* TlsSessionOrNull(int sessionIndex)
andrewboyson 2:82268409e83f 30 {
andrewboyson 5:ee5489ee1117 31 if (sessionIndex < 0) return NULL;
andrewboyson 5:ee5489ee1117 32 if (sessionIndex >= TLS_MAX_SESSIONS) return NULL;
andrewboyson 2:82268409e83f 33 return &sessions[sessionIndex];
andrewboyson 2:82268409e83f 34 }
andrewboyson 2:82268409e83f 35 int TlsSessionGetIndex(struct TlsSession* pSession)
andrewboyson 2:82268409e83f 36 {
andrewboyson 5:ee5489ee1117 37 if (!pSession) return -1;
andrewboyson 2:82268409e83f 38 return pSession - sessions;
andrewboyson 2:82268409e83f 39 }