gwenhywfar 5.10.1
Macros | Functions
httpsession.c File Reference
#include "httpsession_p.h"
#include "i18n_l.h"
#include <gwenhywfar/syncio.h>
#include <gwenhywfar/syncio_socket.h>
#include <gwenhywfar/syncio_tls.h>
#include <gwenhywfar/syncio_http.h>
#include <gwenhywfar/syncio_file.h>
#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/gui.h>
#include <gwenhywfar/text.h>
#include <assert.h>
#include <unistd.h>
Include dependency graph for httpsession.c:

Go to the source code of this file.

Macros

#define DISABLE_DEBUGLOG
 

Functions

static void _setHostHeaderFromUrl (const char *sUrl, GWEN_DB_NODE *dbHeader)
 
int GWEN_HttpSession__RecvPacket (GWEN_HTTP_SESSION *sess, GWEN_BUFFER *buf)
 
int GWEN_HttpSession__RecvPacketToSio (GWEN_HTTP_SESSION *sess, GWEN_SYNCIO *sio)
 
void GWEN_HttpSession_AddFlags (GWEN_HTTP_SESSION *sess, uint32_t fl)
 
void GWEN_HttpSession_Attach (GWEN_HTTP_SESSION *sess)
 
int GWEN_HttpSession_ConnectionTest (GWEN_HTTP_SESSION *sess)
 
int GWEN_HttpSession_Fini (GWEN_HTTP_SESSION *sess)
 
void GWEN_HttpSession_free (GWEN_HTTP_SESSION *sess)
 
GWEN_HTTP_SESSIONGWEN_HttpSession_fromSocketPassive (GWEN_SOCKET *sk, const char *proto, int port)
 
GWEN_HTTP_SESSIONGWEN_HttpSession_fromSyncIoPassive (GWEN_SYNCIO *sio)
 
uint32_t GWEN_HttpSession_GetFlags (const GWEN_HTTP_SESSION *sess)
 
const char * GWEN_HttpSession_GetHttpContentType (const GWEN_HTTP_SESSION *sess)
 
const char * GWEN_HttpSession_GetHttpUserAgent (const GWEN_HTTP_SESSION *sess)
 
int GWEN_HttpSession_GetHttpVMajor (const GWEN_HTTP_SESSION *sess)
 
int GWEN_HttpSession_GetHttpVMinor (const GWEN_HTTP_SESSION *sess)
 
int GWEN_HttpSession_Init (GWEN_HTTP_SESSION *sess)
 
int GWEN_HttpSession_InitSyncIo (GWEN_HTTP_SESSION *sess, GWEN_SYNCIO *sio)
 
GWEN_HTTP_SESSIONGWEN_HttpSession_new (const char *url, const char *defaultProto, int defaultPort)
 
int GWEN_HttpSession_RecvCommand (GWEN_HTTP_SESSION *sess, GWEN_DB_NODE *dbCommandAndHeader, GWEN_BUFFER *buf)
 
int GWEN_HttpSession_RecvPacket (GWEN_HTTP_SESSION *sess, GWEN_BUFFER *buf)
 
int GWEN_HttpSession_RecvPacketToFile (GWEN_HTTP_SESSION *sess, const char *fname)
 
int GWEN_HttpSession_SendPacket (GWEN_HTTP_SESSION *sess, const char *httpCommand, const uint8_t *buf, uint32_t blen)
 
int GWEN_HttpSession_SendStatus (GWEN_HTTP_SESSION *sess, int resultCode, const char *resultText, const uint8_t *buf, uint32_t blen)
 
void GWEN_HttpSession_SetFlags (GWEN_HTTP_SESSION *sess, uint32_t fl)
 
void GWEN_HttpSession_SetHttpContentType (GWEN_HTTP_SESSION *sess, const char *s)
 
void GWEN_HttpSession_SetHttpUserAgent (GWEN_HTTP_SESSION *sess, const char *s)
 
void GWEN_HttpSession_SetHttpVMajor (GWEN_HTTP_SESSION *sess, int i)
 
void GWEN_HttpSession_SetHttpVMinor (GWEN_HTTP_SESSION *sess, int i)
 
GWEN_HTTPSESSION_INITSYNCIO_FN GWEN_HttpSession_SetInitSyncIoFn (GWEN_HTTP_SESSION *sess, GWEN_HTTPSESSION_INITSYNCIO_FN f)
 
void GWEN_HttpSession_SubFlags (GWEN_HTTP_SESSION *sess, uint32_t fl)
 

Macro Definition Documentation

◆ DISABLE_DEBUGLOG

#define DISABLE_DEBUGLOG

Definition at line 15 of file httpsession.c.

Function Documentation

◆ _setHostHeaderFromUrl()

void _setHostHeaderFromUrl ( const char *  sUrl,
GWEN_DB_NODE dbHeader 
)
static

Definition at line 382 of file httpsession.c.

References GWEN_DB_FLAGS_OVERWRITE_VARS, GWEN_DB_SetCharValue(), GWEN_Url_free(), GWEN_Url_fromString(), and GWEN_Url_GetServer().

Referenced by GWEN_HttpSession_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_HttpSession__RecvPacket()

int GWEN_HttpSession__RecvPacket ( GWEN_HTTP_SESSION sess,
GWEN_BUFFER buf 
)

◆ GWEN_HttpSession__RecvPacketToSio()

int GWEN_HttpSession__RecvPacketToSio ( GWEN_HTTP_SESSION sess,
GWEN_SYNCIO sio 
)

Definition at line 742 of file httpsession.c.

References DBG_INFO, GWEN_DB_GetCharValue(), GWEN_Gui_ProgressLog2(), GWEN_LOGDOMAIN, GWEN_LoggerLevel_Warning, GWEN_SyncIo_Http_GetDbHeaderIn(), GWEN_SyncIo_Http_RecvBodyToSio(), and I18N.

Referenced by GWEN_HttpSession_RecvPacketToFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_HttpSession_AddFlags()

void GWEN_HttpSession_AddFlags ( GWEN_HTTP_SESSION sess,
uint32_t  fl 
)

Definition at line 189 of file httpsession.c.

◆ GWEN_HttpSession_Attach()

void GWEN_HttpSession_Attach ( GWEN_HTTP_SESSION sess)

Definition at line 127 of file httpsession.c.

◆ GWEN_HttpSession_ConnectionTest()

int GWEN_HttpSession_ConnectionTest ( GWEN_HTTP_SESSION sess)

Test-connect to the server. This function can be used to retrieve the SSL certificate from a server as the cert exchange is part of the establishing of a connection. This function connects to the server and immediately disconnects.

Definition at line 876 of file httpsession.c.

References DBG_INFO, DBG_NOTICE, GWEN_ERROR_SSL, GWEN_Gui_ProgressLog(), GWEN_LOGDOMAIN, GWEN_LoggerLevel_Error, GWEN_LoggerLevel_Notice, GWEN_SyncIo_Connect(), GWEN_SyncIo_Disconnect(), and I18N.

Here is the call graph for this function:

◆ GWEN_HttpSession_Fini()

int GWEN_HttpSession_Fini ( GWEN_HTTP_SESSION sess)

Definition at line 401 of file httpsession.c.

References GWEN_SyncIo_Disconnect(), GWEN_SyncIo_free(), and NULL.

Here is the call graph for this function:

◆ GWEN_HttpSession_free()

void GWEN_HttpSession_free ( GWEN_HTTP_SESSION sess)

Definition at line 136 of file httpsession.c.

References GWEN_FREE_OBJECT, GWEN_INHERIT_FINI, and GWEN_SyncIo_free().

Referenced by GWEN_HttpSession_fromSocketPassive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_HttpSession_fromSocketPassive()

GWEN_HTTP_SESSION * GWEN_HttpSession_fromSocketPassive ( GWEN_SOCKET sk,
const char *  proto,
int  port 
)

Create a server HTTP session using the given socket.

The caller is responsible for freeing the object returned (if any).

Returns
session object (NULL on error)
Parameters
sksocket (received via GWEN_Socket_Accept), taken over
protoprotocol used by this server session (either "http" or "https")
portport used by this server session (in ost cases 80 for HTTP, 443 for HTTPS)

Definition at line 64 of file httpsession.c.

References DBG_ERROR, GWEN_Gui_ExtendSyncIo(), GWEN_HTTP_SESSION_FLAGS_PASSIVE, GWEN_HttpSession_free(), GWEN_INHERIT_INIT, GWEN_LOGDOMAIN, GWEN_NEW_OBJECT, GWEN_SyncIo_AddFlags(), GWEN_SYNCIO_FLAGS_PASSIVE, GWEN_SyncIo_GetBaseIo(), GWEN_SyncIo_Socket_TakeOver(), and NULL.

Here is the call graph for this function:

◆ GWEN_HttpSession_fromSyncIoPassive()

GWEN_HTTP_SESSION * GWEN_HttpSession_fromSyncIoPassive ( GWEN_SYNCIO sio)

Create a server HTTP session using the given syncio.

The caller is responsible for freeing the object returned (if any).

Returns
session object (NULL on error)
Parameters
siosynIo object, taken over

Definition at line 104 of file httpsession.c.

References GWEN_HTTP_SESSION_FLAGS_PASSIVE, GWEN_INHERIT_INIT, GWEN_NEW_OBJECT, GWEN_SyncIo_AddFlags(), GWEN_SYNCIO_FLAGS_PASSIVE, and GWEN_SyncIo_GetBaseIo().

Here is the call graph for this function:

◆ GWEN_HttpSession_GetFlags()

uint32_t GWEN_HttpSession_GetFlags ( const GWEN_HTTP_SESSION sess)

Definition at line 169 of file httpsession.c.

◆ GWEN_HttpSession_GetHttpContentType()

const char * GWEN_HttpSession_GetHttpContentType ( const GWEN_HTTP_SESSION sess)

Definition at line 233 of file httpsession.c.

◆ GWEN_HttpSession_GetHttpUserAgent()

const char * GWEN_HttpSession_GetHttpUserAgent ( const GWEN_HTTP_SESSION sess)

Definition at line 209 of file httpsession.c.

◆ GWEN_HttpSession_GetHttpVMajor()

int GWEN_HttpSession_GetHttpVMajor ( const GWEN_HTTP_SESSION sess)

Definition at line 257 of file httpsession.c.

◆ GWEN_HttpSession_GetHttpVMinor()

int GWEN_HttpSession_GetHttpVMinor ( const GWEN_HTTP_SESSION sess)

Definition at line 277 of file httpsession.c.

◆ GWEN_HttpSession_Init()

int GWEN_HttpSession_Init ( GWEN_HTTP_SESSION sess)

◆ GWEN_HttpSession_InitSyncIo()

int GWEN_HttpSession_InitSyncIo ( GWEN_HTTP_SESSION sess,
GWEN_SYNCIO sio 
)

Definition at line 914 of file httpsession.c.

References DBG_INFO, GWEN_ERROR_NOT_IMPLEMENTED, and GWEN_LOGDOMAIN.

Referenced by GWEN_HttpSession_Init().

Here is the caller graph for this function:

◆ GWEN_HttpSession_new()

GWEN_HTTP_SESSION * GWEN_HttpSession_new ( const char *  url,
const char *  defaultProto,
int  defaultPort 
)

Create a client HTTP session (i.e. used to connect to a server).

The caller is responsible for freeing the object returned (if any).

Returns
session object (NULL on error)
Parameters
urlURL of the server to connect to later
defaultProtodefault protocol if not specified by the given url (e.g. "https")
defaultPortdefault TCP port if not specified by the given url

Definition at line 45 of file httpsession.c.

References GWEN_INHERIT_INIT, and GWEN_NEW_OBJECT.

◆ GWEN_HttpSession_RecvCommand()

int GWEN_HttpSession_RecvCommand ( GWEN_HTTP_SESSION sess,
GWEN_DB_NODE dbCommandAndHeader,
GWEN_BUFFER buf 
)

This function receives a command packet from a client.

Returns
HTTP result code if positive, error code if negative)
Parameters
sesspointer to session object
dbCommandAndHeaderon currect receiption a subgroup "command" is created which contains the command parameters receives and a subgroup "header" is created which contains the last HTTP header received
bufbuffer to receive possible HTTP body data

Definition at line 685 of file httpsession.c.

References DBG_ERROR, DBG_INFO, GWEN_Buffer_Crop(), GWEN_Buffer_GetPos(), GWEN_DB_AddGroupChildren(), GWEN_DB_FLAGS_OVERWRITE_GROUPS, GWEN_DB_GetGroup(), GWEN_ERROR_INVALID, GWEN_Gui_ProgressLog(), GWEN_HTTP_SESSION_FLAGS_PASSIVE, GWEN_HttpSession__RecvPacket(), GWEN_LOGDOMAIN, GWEN_LoggerLevel_Debug, GWEN_SyncIo_Disconnect(), GWEN_SyncIo_Http_GetDbCommandIn(), GWEN_SyncIo_Http_GetDbHeaderIn(), and I18N.

Here is the call graph for this function:

◆ GWEN_HttpSession_RecvPacket()

int GWEN_HttpSession_RecvPacket ( GWEN_HTTP_SESSION sess,
GWEN_BUFFER buf 
)

This function receives a response packet from the server and closes the connection. It expects the connection to be established by GWEN_HttpSession_SendPacket().

Definition at line 642 of file httpsession.c.

References DBG_INFO, GWEN_Buffer_Crop(), GWEN_Buffer_GetPos(), GWEN_Gui_ProgressLog(), GWEN_HttpSession__RecvPacket(), GWEN_LOGDOMAIN, GWEN_LoggerLevel_Debug, GWEN_SyncIo_Disconnect(), and I18N.

Here is the call graph for this function:

◆ GWEN_HttpSession_RecvPacketToFile()

int GWEN_HttpSession_RecvPacketToFile ( GWEN_HTTP_SESSION sess,
const char *  fname 
)

◆ GWEN_HttpSession_SendPacket()

int GWEN_HttpSession_SendPacket ( GWEN_HTTP_SESSION sess,
const char *  httpCommand,
const uint8_t *  buf,
uint32_t  blen 
)

This function connects to the server and then sends the given message. The buffer given as argument to this function must only contain the raw data (i.e. the HTTP body, no header).

Parameters
sesshttp session object
httpCommandHTTP command to send (e.g. "GET", "POST")
bufpointer to the http body data to send
blensize of the http body data to send (might be 0)

Definition at line 417 of file httpsession.c.

References DBG_INFO, DBG_NOTICE, GWEN_DB_FLAGS_OVERWRITE_VARS, GWEN_DB_SetCharValue(), GWEN_DB_SetIntValue(), GWEN_ERROR_SSL, GWEN_Gui_ProgressLog(), GWEN_Gui_ProgressLog2(), GWEN_LOGDOMAIN, GWEN_LoggerLevel_Debug, GWEN_LoggerLevel_Error, GWEN_SyncIo_Connect(), GWEN_SyncIo_Disconnect(), GWEN_SyncIo_Http_GetDbCommandOut(), GWEN_SyncIo_Http_GetDbHeaderOut(), GWEN_SyncIo_WriteForced(), and I18N.

Here is the call graph for this function:

◆ GWEN_HttpSession_SendStatus()

int GWEN_HttpSession_SendStatus ( GWEN_HTTP_SESSION sess,
int  resultCode,
const char *  resultText,
const uint8_t *  buf,
uint32_t  blen 
)

This function sends the given response (only usable in PASSIVE mode, i.e. server mode) and closes the connection. The buffer given as argument to this function must only contain the raw data (i.e. the HTTP body, no header).

Parameters
sesshttp session object
resultCodeHTTP result code to send
resultTextHTTP result text to send
bufpointer to the http body data to send
blensize of the http body data to send (might be 0)

Definition at line 501 of file httpsession.c.

References DBG_ERROR, DBG_INFO, GWEN_DB_FLAGS_OVERWRITE_VARS, GWEN_DB_SetCharValue(), GWEN_DB_SetIntValue(), GWEN_ERROR_INVALID, GWEN_Gui_ProgressLog(), GWEN_Gui_ProgressLog2(), GWEN_HTTP_SESSION_FLAGS_PASSIVE, GWEN_LOGDOMAIN, GWEN_LoggerLevel_Debug, GWEN_LoggerLevel_Error, GWEN_SyncIo_Disconnect(), GWEN_SyncIo_Http_GetDbHeaderOut(), GWEN_SyncIo_Http_GetDbStatusOut(), GWEN_SyncIo_WriteForced(), and I18N.

Here is the call graph for this function:

◆ GWEN_HttpSession_SetFlags()

void GWEN_HttpSession_SetFlags ( GWEN_HTTP_SESSION sess,
uint32_t  fl 
)

Definition at line 179 of file httpsession.c.

◆ GWEN_HttpSession_SetHttpContentType()

void GWEN_HttpSession_SetHttpContentType ( GWEN_HTTP_SESSION sess,
const char *  s 
)

Definition at line 243 of file httpsession.c.

References NULL.

◆ GWEN_HttpSession_SetHttpUserAgent()

void GWEN_HttpSession_SetHttpUserAgent ( GWEN_HTTP_SESSION sess,
const char *  s 
)

Definition at line 219 of file httpsession.c.

References NULL.

◆ GWEN_HttpSession_SetHttpVMajor()

void GWEN_HttpSession_SetHttpVMajor ( GWEN_HTTP_SESSION sess,
int  i 
)

Definition at line 267 of file httpsession.c.

◆ GWEN_HttpSession_SetHttpVMinor()

void GWEN_HttpSession_SetHttpVMinor ( GWEN_HTTP_SESSION sess,
int  i 
)

Definition at line 287 of file httpsession.c.

◆ GWEN_HttpSession_SetInitSyncIoFn()

GWEN_HTTPSESSION_INITSYNCIO_FN GWEN_HttpSession_SetInitSyncIoFn ( GWEN_HTTP_SESSION sess,
GWEN_HTTPSESSION_INITSYNCIO_FN  f 
)

Definition at line 157 of file httpsession.c.

◆ GWEN_HttpSession_SubFlags()

void GWEN_HttpSession_SubFlags ( GWEN_HTTP_SESSION sess,
uint32_t  fl 
)

Definition at line 199 of file httpsession.c.