RCube
Rcube Rest Server calculates sail routes based on Grib files and sailing boat polar files
Loading...
Searching...
No Matches
r3server.c File Reference
#include <stdbool.h>
#include <dirent.h>
#include <errno.h>
#include <stdarg.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <limits.h>
#include <locale.h>
#include "glibwrapper.h"
#include "r3types.h"
#include "r3util.h"
#include "engine.h"
#include "grib.h"
#include "readgriball.h"
#include "polar.h"
#include "inline.h"
#include "option.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
Include dependency graph for r3server.c:

Go to the source code of this file.

Data Structures

struct  ClientRequest
 Client Request description. More...
 
struct  FileInfo
 Structure to store file information. More...
 

Macros

#define SYNOPSYS   "<port> | -<option> [<parameter file>]"
 RCube is a routing software for sailing.
 
#define MAX_SIZE_REQUEST   2048
 
#define MAX_SIZE_RESOURCE_NAME   256
 
#define PATTERN   "GFS"
 
#define MAX_SIZE_FEED_BACK   1024
 
#define ADMIN_LEVEL   10
 
#define BIG_BUFFER_SIZE   (300*MILLION)
 
#define MAX_SIZE_MESS   100000
 
#define GPX_ROUTE_FILE_NAME   "gpxroute.tmp"
 

Enumerations

enum  {
  REQ_KILL = -1793 , REQ_TEST = 0 , REQ_ROUTING = 1 , REQ_COORD = 2 ,
  REQ_FORBID = 3 , REQ_POLAR = 4 , REQ_GRIB = 5 , REQ_DIR = 6 ,
  REQ_PAR_RAW = 7 , REQ_PAR_JSON = 8 , REQ_INIT = 9 , REQ_FEEDBACK = 10 ,
  REQ_DUMP_FILE = 11 , REQ_NEAREST_PORT = 12 , REQ_MARKS = 13 , REQ_CHECK_GRIB = 14 ,
  REQ_GPX_ROUTE = 15 , REQ_GRIB_DUMP = 16
}
 

Functions

static void polygonToJson (MyPolygon *po, char *str, size_t maxLen)
 Generate Json array for polygon.
 
static bool updateWindGrib (ClientRequest *clientReq, char *checkMessage, size_t maxLen)
 update Grib file if required
 
static bool updateCurrentGrib (ClientRequest *clientReq, char *checkMessage, size_t maxLen)
 update current file if required
 
static double approxSegmentLengthNm (double lat0, double lon0, double lat1, double lon1)
 Approximate great-circle segment length in nautical miles.
 
static bool segmentOverSea (double lat0, double lon0, double lat1, double lon1)
 Check if the straight segment between (lat0, lon0) and (lat1, lon1) stays entirely over allowed sea areas.
 
static int checkRoute (const SailRoute *route)
 Check that every consecutive segment of a route is fully over sea.
 
static void forbidToJson (char *res, size_t maxLen)
 Exclusion zone is an array of polygons.
 
static char * isochronesToStrCatJson (char *res, size_t maxLen)
 generate json description of isochrones.
 
static char * isoDescToStrCatJson (char *res, size_t maxLen)
 generate json description of isochrones decriptor.
 
static char * routeToJson (SailRoute *route, bool isoc, bool isoDesc, char *res, size_t maxLen)
 generate json description of track boats
 
static double round4 (double x)
 
static void infoCoordToJson (double lat, double lon, ClientRequest *clientReq, char *res, size_t maxLen)
 information associated to coord (lat lon) isSea, isSeaTolerant, grib wind and current
 
static bool getRealIPAddress (const char *headers, char *clientAddress, size_t bufferSize)
 Retrieves the real client IP address from HTTP headers.
 
static char * extractUserAgent (const char *saveBuffer)
 extract user agent
 
static int extractLevel (const char *buffer)
 extract level
 
static bool allowedLevel (ClientRequest *clientReq)
 compare level of authorization with request
 
static int compareByName (const void *a, const void *b)
 Comparator to sort by name (ascending order)
 
static int compareByMtime (const void *a, const void *b)
 Comparator to sort by modification date (most recent first)
 
static bool matchFilter (const char *filename, const char **filter)
 Checks if the filename matches one of the suffixes in the filter.
 
static char * nearestPortToStrJson (double lat, double lon, char *out, size_t maxLen)
 return neareAst port to lat, lon
 
static char * jsonEscapeStrdup (const char *s)
 Escape JSON string ; malloc(), to free()
 
static char * listDirToStrJson (char *root, char *dir, bool sortByName, const char *pattern, const char **filter, char *out, size_t maxLen)
 
static bool initContext (const char *parameterFileName, const char *pattern)
 Make initialization
return false if readParam or readGribAll fail.
 
static const char * getCurrentDate ()
 date for logging
 
static void handleFeedbackRequest (const char *fileName, const char *date, const char *clientIPAddress, const char *string)
 store feedback information
 
static void logRequest (const char *fileName, const char *date, int serverPort, const char *remote_addr, char *dataReq, const char *userAgent, ClientRequest *client, double duration)
 log client Request side effect: dataReq is modified
 
static bool decodeHttpReq (const char *req, ClientRequest *clientReq)
 decode request from client and fill ClientRequest structure return true if correct false if impossible to decode
 
static bool checkParamAndUpdate (ClientRequest *clientReq, char *checkMessage, size_t maxLen)
 check validity of parameters
 
static const char * getMimeType (const char *path)
 Translate extension in MIME type.
 
static void serveStaticFile (int client_socket, const char *requested_path)
 serve static file
 
int memoryUsage (void)
 Return the current memory usage (resident set size) in kilobytes.
 
static char * testToJson (int serverPort, const char *clientIP, const char *userAgent, int level, char *out, size_t maxLen)
 Provide system information.
 
void sendBinaryResponse (int sock, const void *data, size_t len, const char *shortnames)
 send over network binary data
 
static void buildInitialOfShortNameList (const Zone *zone, char *str, size_t len)
 build list of short names.
 
static bool launchAction (int serverPort, int sock, ClientRequest *clientReq, const char *date, const char *clientIPAddress, const char *userAgent, char *outBuffer, size_t maxLen)
 launch action and returns outBuffer after execution
 
static int sendAll (int fd, const void *buf, size_t len)
 robust send
 
static bool handleClient (int serverPort, int clientFd, struct sockaddr_in *client_addr)
 Handle client connection and launch actions.
 
int main (int argc, char *argv[])
 main server first argument (mandatory): port number second argument (optionnal): parameter file
 

Variables

char * bigBuffer = NULL
 
const char * filter [] = {".csv", ".pol", ".grb", ".grb2", ".log", ".txt", ".par", ".yaml", ".json", NULL}
 
const int typeLevel [16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
 
char parameterFileName [MAX_SIZE_FILE_NAME]
 
ClientRequest clientReq
 

Macro Definition Documentation

◆ ADMIN_LEVEL

#define ADMIN_LEVEL   10

Definition at line 40 of file r3server.c.

◆ BIG_BUFFER_SIZE

#define BIG_BUFFER_SIZE   (300*MILLION)

Definition at line 41 of file r3server.c.

◆ GPX_ROUTE_FILE_NAME

#define GPX_ROUTE_FILE_NAME   "gpxroute.tmp"

Definition at line 43 of file r3server.c.

◆ MAX_SIZE_FEED_BACK

#define MAX_SIZE_FEED_BACK   1024

Definition at line 39 of file r3server.c.

◆ MAX_SIZE_MESS

#define MAX_SIZE_MESS   100000

Definition at line 42 of file r3server.c.

◆ MAX_SIZE_REQUEST

#define MAX_SIZE_REQUEST   2048

Definition at line 36 of file r3server.c.

◆ MAX_SIZE_RESOURCE_NAME

#define MAX_SIZE_RESOURCE_NAME   256

Definition at line 37 of file r3server.c.

◆ PATTERN

#define PATTERN   "GFS"

Definition at line 38 of file r3server.c.

◆ SYNOPSYS

#define SYNOPSYS   "<port> | -<option> [<parameter file>]"

RCube is a routing software for sailing.

It computes the optimal route from a starting point (pOr) to a destination point (pDest) at a given START_TIME, using GRIB weather data and a boat polar diagram. to launch : r3server <port number> [parameter file]

Definition at line 35 of file r3server.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
REQ_KILL 
REQ_TEST 
REQ_ROUTING 
REQ_COORD 
REQ_FORBID 
REQ_POLAR 
REQ_GRIB 
REQ_DIR 
REQ_PAR_RAW 
REQ_PAR_JSON 
REQ_INIT 
REQ_FEEDBACK 
REQ_DUMP_FILE 
REQ_NEAREST_PORT 
REQ_MARKS 
REQ_CHECK_GRIB 
REQ_GPX_ROUTE 
REQ_GRIB_DUMP 

Definition at line 50 of file r3server.c.

Function Documentation

◆ allowedLevel()

static bool allowedLevel ( ClientRequest clientReq)
static

compare level of authorization with request

Definition at line 579 of file r3server.c.

References ADMIN_LEVEL, clientReq, ClientRequest::level, ClientRequest::model, REQ_KILL, ClientRequest::type, and typeLevel.

Referenced by handleClient().

Here is the caller graph for this function:

◆ approxSegmentLengthNm()

static double approxSegmentLengthNm ( double  lat0,
double  lon0,
double  lat1,
double  lon1 
)
static

Approximate great-circle segment length in nautical miles.

This function estimates the distance between two geographic points (lat0, lon0) and (lat1, lon1) in nautical miles (NM) using a local equirectangular projection. For routing validation this is accurate enough and cheaper than a full haversine.

Latitudes and longitudes are expressed in decimal degrees.

Returns
Approximate distance in nautical miles.

Definition at line 198 of file r3server.c.

References DEG_TO_RAD.

Referenced by segmentOverSea().

Here is the caller graph for this function:

◆ buildInitialOfShortNameList()

static void buildInitialOfShortNameList ( const Zone zone,
char *  str,
size_t  len 
)
static

build list of short names.

Only initials. Result can be uv, uvg, uvw, uvwg. uv mandatory. Response is false if not u and v

Definition at line 1262 of file r3server.c.

References isPresentGrib(), uvPresentGrib(), and zone.

Referenced by launchAction().

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

◆ checkParamAndUpdate()

static bool checkParamAndUpdate ( ClientRequest clientReq,
char *  checkMessage,
size_t  maxLen 
)
static

check validity of parameters

Definition at line 973 of file r3server.c.

References Par::allwaysSea, Pp::amure, ClientRequest::boats, buildRootName(), clientReq, ClientRequest::cogStep, Par::cogStep, competitors, ClientRequest::constCurrentD, Par::constCurrentD, ClientRequest::constCurrentS, Par::constCurrentS, ClientRequest::constWave, Par::constWave, ClientRequest::constWindTwd, Par::constWindTwd, ClientRequest::constWindTws, Par::constWindTws, Zone::dataDate, Zone::dataTime, ClientRequest::dayEfficiency, Par::dayEfficiency, ClientRequest::epochStart, ClientRequest::forbid, g_path_get_basename(), g_strlcpy, gribDateTimeToEpoch(), Par::gribFileName, ClientRequest::gribName, hasSlash(), ClientRequest::initialAmure, isInZone(), isSeaTolerant(), ClientRequest::jFactor, Par::jFactor, ClientRequest::kFactor, Par::kFactor, ClientRequest::lat, Pp::lat, WayPoint::lat, Competitor::lat, Zone::latMax, Zone::latMin, ClientRequest::lon, Pp::lon, WayPoint::lon, Competitor::lon, Zone::lonLeft, Zone::lonRight, MAX, MAX_SIZE_DIR_NAME, MAX_SIZE_FILE_NAME, MAX_SIZE_NAME, ClientRequest::maxWind, Par::maxWind, ClientRequest::model, mostRecentFile(), ClientRequest::motorSpeed, Par::motorSpeed, WayPointList::n, CompetitorsList::n, ClientRequest::name, Competitor::name, name, ClientRequest::nBoats, ClientRequest::nightEfficiency, Par::nightEfficiency, ClientRequest::nSectors, Par::nSectors, Zone::nTimeStamp, ClientRequest::nWp, par, Par::pDest, ClientRequest::penalty0, Par::penalty0, ClientRequest::penalty1, Par::penalty1, ClientRequest::penalty2, Par::penalty2, Par::polarFileName, ClientRequest::polarName, polMat, Par::pOr, ClientRequest::rangeCog, Par::rangeCog, readPolar(), sailPolMat, ClientRequest::staminaVR, Par::staminaVR, Par::startTimeInHours, CompetitorsList::t, WayPointList::t, ClientRequest::threshold, Par::threshold, Zone::timeStamp, ClientRequest::timeStep, tIsSea, Par::tStep, updateCurrentGrib(), updateWindGrib(), Par::wavePolFileName, wavePolMat, ClientRequest::wavePolName, wayPoints, ClientRequest::withCurrent, Par::withCurrent, ClientRequest::withWaves, Par::withWaves, Par::workingDir, ClientRequest::wp, ClientRequest::xWind, Par::xWind, and zone.

Referenced by launchAction().

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

◆ checkRoute()

static int checkRoute ( const SailRoute route)
static

Check that every consecutive segment of a route is fully over sea.

The route is assumed to be an ordered list of waypoints. For each pair of consecutive waypoints, segmentOverSea() is called. If any segment crosses land or a forbidden area, the function returns false.

Parameters
routepointer to SailRoute.
Returns
-1 if all segments are OK (sea only)
i index of the first invalid segment [i -> i+1]

Definition at line 277 of file r3server.c.

References SailPoint::lat, SailPoint::lon, SailRoute::n, route, segmentOverSea(), and SailRoute::t.

Referenced by routeToJson().

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

◆ compareByMtime()

static int compareByMtime ( const void *  a,
const void *  b 
)
static

Comparator to sort by modification date (most recent first)

Definition at line 601 of file r3server.c.

References FileInfo::mtime, and FileInfo::name.

Referenced by listDirToStrJson().

Here is the caller graph for this function:

◆ compareByName()

static int compareByName ( const void *  a,
const void *  b 
)
static

Comparator to sort by name (ascending order)

Definition at line 595 of file r3server.c.

References FileInfo::name.

Referenced by listDirToStrJson().

Here is the caller graph for this function:

◆ decodeHttpReq()

static bool decodeHttpReq ( const char *  req,
ClientRequest clientReq 
)
static

decode request from client and fill ClientRequest structure return true if correct false if impossible to decode

Definition at line 858 of file r3server.c.

References ClientRequest::boats, clientReq, ClientRequest::cogStep, ClientRequest::constCurrentD, ClientRequest::constCurrentS, ClientRequest::constWave, ClientRequest::constWindTwd, ClientRequest::constWindTws, ClientRequest::currentGribName, ClientRequest::dayEfficiency, ClientRequest::dirName, ClientRequest::epochStart, ClientRequest::feedback, ClientRequest::fileName, ClientRequest::forbid, g_str_has_prefix(), g_strfreev(), g_strlcpy, g_strsplit(), g_strstrip(), ClientRequest::gribName, ClientRequest::initialAmure, ClientRequest::isoc, ClientRequest::isoDesc, ClientRequest::jFactor, ClientRequest::kFactor, ClientRequest::lat, ClientRequest::lon, MAX_N_COMPETITORS, MAX_N_WAY_POINT, MAX_SIZE_NAME, ClientRequest::maxWind, ClientRequest::model, ClientRequest::motorSpeed, ClientRequest::name, name, ClientRequest::nBoats, ClientRequest::nightEfficiency, ClientRequest::nSectors, ClientRequest::nWp, ClientRequest::penalty0, ClientRequest::penalty1, ClientRequest::penalty2, ClientRequest::polarName, ClientRequest::rangeCog, ClientRequest::sortByName, ClientRequest::staminaVR, ClientRequest::threshold, ClientRequest::timeStep, ClientRequest::type, ClientRequest::wavePolName, ClientRequest::withCurrent, ClientRequest::withWaves, ClientRequest::wp, and ClientRequest::xWind.

Referenced by handleClient().

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

◆ extractLevel()

static int extractLevel ( const char *  buffer)
static

extract level

Definition at line 570 of file r3server.c.

References ADMIN_LEVEL, Par::authent, and par.

Referenced by handleClient().

Here is the caller graph for this function:

◆ extractUserAgent()

static char * extractUserAgent ( const char *  saveBuffer)
static

extract user agent

Definition at line 556 of file r3server.c.

Referenced by handleClient().

Here is the caller graph for this function:

◆ forbidToJson()

static void forbidToJson ( char *  res,
size_t  maxLen 
)
static

Exclusion zone is an array of polygons.

Definition at line 286 of file r3server.c.

References forbidZones, Par::nForbidZone, par, and polygonToJson().

Referenced by launchAction().

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

◆ getCurrentDate()

static const char * getCurrentDate ( )
static

date for logging

Definition at line 813 of file r3server.c.

Referenced by handleClient().

Here is the caller graph for this function:

◆ getMimeType()

static const char * getMimeType ( const char *  path)
static

Translate extension in MIME type.

Definition at line 1115 of file r3server.c.

Referenced by serveStaticFile().

Here is the caller graph for this function:

◆ getRealIPAddress()

static bool getRealIPAddress ( const char *  headers,
char *  clientAddress,
size_t  bufferSize 
)
static

Retrieves the real client IP address from HTTP headers.

Parameters
headersA string containing the HTTP headers.
clientAddressBuffer to store the client's IP address.
bufferSizeSize of the clientAddress buffer.
Returns
true if the IP address was successfully found and stored, false if not found or error.

Definition at line 530 of file r3server.c.

References g_strlcpy, and g_strstrip().

Referenced by handleClient().

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

◆ handleClient()

static bool handleClient ( int  serverPort,
int  clientFd,
struct sockaddr_in *  client_addr 
)
static

Handle client connection and launch actions.

Definition at line 1466 of file r3server.c.

References allowedLevel(), BIG_BUFFER_SIZE, bigBuffer, clientReq, decodeHttpReq(), extractLevel(), extractUserAgent(), g_strlcpy, getCurrentDate(), getRealIPAddress(), launchAction(), ClientRequest::level, Par::logFileName, logRequest(), MAX_SIZE_LINE, MAX_SIZE_REQUEST, monotonic(), par, sendAll(), and serveStaticFile().

Referenced by main().

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

◆ handleFeedbackRequest()

static void handleFeedbackRequest ( const char *  fileName,
const char *  date,
const char *  clientIPAddress,
const char *  string 
)
static

store feedback information

Definition at line 822 of file r3server.c.

Referenced by launchAction().

Here is the caller graph for this function:

◆ infoCoordToJson()

static void infoCoordToJson ( double  lat,
double  lon,
ClientRequest clientReq,
char *  res,
size_t  maxLen 
)
static

information associated to coord (lat lon) isSea, isSeaTolerant, grib wind and current

Definition at line 485 of file r3server.c.

References clientReq, currentZone, Zone::dataDate, Zone::dataTime, findWindGrib(), gribDateTimeToEpoch(), Par::gribFileName, isInZone(), isSea(), isSeaTolerant(), MAX_SIZE_MESS, Zone::nTimeStamp, par, round4(), Zone::timeStamp, tIsSea, tMax, updateWindGrib(), and zone.

Referenced by launchAction().

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

◆ initContext()

static bool initContext ( const char *  parameterFileName,
const char *  pattern 
)
static

◆ isochronesToStrCatJson()

static char * isochronesToStrCatJson ( char *  res,
size_t  maxLen 
)
static

generate json description of isochrones.

Concatenate it to res

Definition at line 302 of file r3server.c.

References Pp::father, IsoDesc::first, g_strlcat, Pp::id, isocArray, isoDesc, Pp::lat, Pp::lon, MAX_SIZE_ISOC, nIsoc, and IsoDesc::size.

Referenced by routeToJson().

Here is the caller graph for this function:

◆ isoDescToStrCatJson()

static char * isoDescToStrCatJson ( char *  res,
size_t  maxLen 
)
static

generate json description of isochrones decriptor.

Conatenate te description to res

Definition at line 343 of file r3server.c.

References g_strlcat, isoDesc, and nIsoc.

Referenced by routeToJson().

Here is the caller graph for this function:

◆ jsonEscapeStrdup()

static char * jsonEscapeStrdup ( const char *  s)
static

Escape JSON string ; malloc(), to free()

Definition at line 631 of file r3server.c.

Referenced by listDirToStrJson().

Here is the caller graph for this function:

◆ launchAction()

static bool launchAction ( int  serverPort,
int  sock,
ClientRequest clientReq,
const char *  date,
const char *  clientIPAddress,
const char *  userAgent,
char *  outBuffer,
size_t  maxLen 
)
static

launch action and returns outBuffer after execution

Definition at line 1275 of file r3server.c.

References bigBuffer, ClientRequest::boats, buildInitialOfShortNameList(), buildRootName(), buildUVGWarray(), checkGribToStr(), checkParamAndUpdate(), clientReq, competitors, ClientRequest::currentGribName, ClientRequest::dirName, exportRouteToGpx(), ClientRequest::feedback, Par::feedbackFileName, ClientRequest::fileName, filter, forbidToJson(), g_strlcpy, GPX_ROUTE_FILE_NAME, ClientRequest::gribName, gribToStrJson(), handleFeedbackRequest(), hasSlash(), infoCoordToJson(), initContext(), ClientRequest::isoc, ClientRequest::isoDesc, ClientRequest::lat, ClientRequest::level, listDirToStrJson(), ClientRequest::lon, Par::marksFileName, MAX_SIZE_DIR_NAME, MAX_SIZE_FILE_NAME, MAX_SIZE_NAME, MAX_SIZE_TEXT, ClientRequest::model, mostRecentFile(), SailRoute::n, ClientRequest::nBoats, nearestPortToStrJson(), normalizeSpaces(), ClientRequest::nWp, par, parameterFileName, paramToStrJson(), PATTERN, Par::polarFileName, ClientRequest::polarName, polToStrJson(), readMarkCSVToJson(), readTextFile(), REQ_CHECK_GRIB, REQ_COORD, REQ_DIR, REQ_DUMP_FILE, REQ_FEEDBACK, REQ_FORBID, REQ_GPX_ROUTE, REQ_GRIB, REQ_GRIB_DUMP, REQ_INIT, REQ_KILL, REQ_MARKS, REQ_NEAREST_PORT, REQ_PAR_JSON, REQ_PAR_RAW, REQ_POLAR, REQ_ROUTING, REQ_TEST, SailRoute::ret, route, routeToJson(), ROUTING_ERROR, routingLaunch(), CompetitorsList::runIndex, sendBinaryResponse(), ClientRequest::sortByName, TEMP_FILE_NAME, testToJson(), tGribData, ClientRequest::type, updateCurrentGrib(), updateWindGrib(), WIND, Par::workingDir, ClientRequest::wp, writeParam(), and zone.

Referenced by handleClient().

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

◆ listDirToStrJson()

static char * listDirToStrJson ( char *  root,
char *  dir,
bool  sortByName,
const char *  pattern,
const char **  filter,
char *  out,
size_t  maxLen 
)
static

Function: listDirToJson

Lists the regular files in the directory constructed from root/dir, applies a pattern filter ans a suffix filter if provided, sorts the list either by name or by modification date (most recent first), and generates a JSON string containing an array of arrays in the format [filename, size, modification date].

In case of an error (e.g., unable to open the directory), the error is printed to the console and a corresponding JSON error response is returned.

Definition at line 675 of file r3server.c.

References compareByMtime(), compareByName(), filter, g_str_has_prefix(), g_strlcat, jsonEscapeStrdup(), matchFilter(), MAX_SIZE_LINE, FileInfo::mtime, FileInfo::name, name, and FileInfo::size.

Referenced by launchAction().

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

◆ logRequest()

static void logRequest ( const char *  fileName,
const char *  date,
int  serverPort,
const char *  remote_addr,
char *  dataReq,
const char *  userAgent,
ClientRequest client,
double  duration 
)
static

log client Request side effect: dataReq is modified

Definition at line 834 of file r3server.c.

References g_strdelimit(), g_strlcpy, g_strstrip(), MAX_SIZE_LINE, and ClientRequest::type.

Referenced by handleClient().

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

◆ main()

int main ( int  argc,
char *  argv[] 
)

main server first argument (mandatory): port number second argument (optionnal): parameter file

Definition at line 1574 of file r3server.c.

References BIG_BUFFER_SIZE, bigBuffer, clientReq, CURRENT, g_strlcpy, handleClient(), initContext(), isocArray, isoDesc, monotonic(), optionManage(), parameterFileName, PARAMETERS_FILE, REQ_KILL, route, SYNOPSYS, SailRoute::t, tGribData, tIsSea, ClientRequest::type, and WIND.

Here is the call graph for this function:

◆ matchFilter()

static bool matchFilter ( const char *  filename,
const char **  filter 
)
static

Checks if the filename matches one of the suffixes in the filter.

Definition at line 609 of file r3server.c.

References filter, and g_str_has_suffix().

Referenced by listDirToStrJson().

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

◆ memoryUsage()

int memoryUsage ( void  )

Return the current memory usage (resident set size) in kilobytes.

Returns
int Memory usage in KB, or -1 on error.

Definition at line 1187 of file r3server.c.

Referenced by testToJson().

Here is the caller graph for this function:

◆ nearestPortToStrJson()

static char * nearestPortToStrJson ( double  lat,
double  lon,
char *  out,
size_t  maxLen 
)
static

return neareAst port to lat, lon

Definition at line 620 of file r3server.c.

References MAX_SIZE_NAME, nearestPort(), par, and Par::tidesFileName.

Referenced by launchAction().

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

◆ polygonToJson()

static void polygonToJson ( MyPolygon po,
char *  str,
size_t  maxLen 
)
static

Generate Json array for polygon.

Definition at line 125 of file r3server.c.

References Point::lat, Point::lon, MyPolygon::n, and MyPolygon::points.

Referenced by forbidToJson().

Here is the caller graph for this function:

◆ round4()

static double round4 ( double  x)
inlinestatic

Definition at line 477 of file r3server.c.

Referenced by infoCoordToJson().

Here is the caller graph for this function:

◆ routeToJson()

◆ segmentOverSea()

static bool segmentOverSea ( double  lat0,
double  lon0,
double  lat1,
double  lon1 
)
static

Check if the straight segment between (lat0, lon0) and (lat1, lon1) stays entirely over allowed sea areas.

The function samples intermediate points along the geodesic segment (approximated as a straight interpolation in lat/lon space) and calls isSea(lat, lon) on each sample.

Rationale:

  • Each endpoint is already supposed to be valid water, but in practice a straight line between two valid nodes may cross land (e.g. cutting across a headland or an island).
  • We discretize the segment into small steps in nautical miles (NM). Finer step -> safer, but more calls to isSea().

Assumptions:

  • isSea(lat, lon) is fast (array lookup).
  • Lat/lon variations between the two points are small enough that linear interpolation in degrees is acceptable for validation.
Parameters
lat0start latitude in decimal degrees
lon0start longitude in decimal degrees
lat1end latitude in decimal degrees
lon1end longitude in decimal degrees
Returns
true if all sampled points are at sea (and not in forbidden areas)
false if any sampled point is on land / forbidden

Definition at line 235 of file r3server.c.

References approxSegmentLengthNm(), CLAMP, isSea(), and tIsSea.

Referenced by checkRoute().

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

◆ sendAll()

static int sendAll ( int  fd,
const void *  buf,
size_t  len 
)
static

robust send

Definition at line 1450 of file r3server.c.

Referenced by handleClient().

Here is the caller graph for this function:

◆ sendBinaryResponse()

void sendBinaryResponse ( int  sock,
const void *  data,
size_t  len,
const char *  shortnames 
)

send over network binary data

Definition at line 1234 of file r3server.c.

Referenced by launchAction().

Here is the caller graph for this function:

◆ serveStaticFile()

static void serveStaticFile ( int  client_socket,
const char *  requested_path 
)
static

serve static file

Definition at line 1131 of file r3server.c.

References getMimeType(), par, and Par::web.

Referenced by handleClient().

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

◆ testToJson()

static char * testToJson ( int  serverPort,
const char *  clientIP,
const char *  userAgent,
int  level,
char *  out,
size_t  maxLen 
)
static

Provide system information.

Definition at line 1205 of file r3server.c.

References currentZone, formatThousandSep(), gribReaderVersion(), MAX_SIZE_LINE, MAX_SIZE_TEXT_FILE, memoryUsage(), Zone::nbLat, Zone::nbLon, Zone::nTimeStamp, PROG_AUTHOR, PROG_NAME, PROG_VERSION, and zone.

Referenced by launchAction().

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

◆ updateCurrentGrib()

static bool updateCurrentGrib ( ClientRequest clientReq,
char *  checkMessage,
size_t  maxLen 
)
static

update current file if required

Definition at line 166 of file r3server.c.

References buildRootName(), clientReq, CURRENT, Par::currentGribFileName, ClientRequest::currentGribName, currentZone, g_strlcpy, MAX_SIZE_FILE_NAME, par, and readGribAll().

Referenced by checkParamAndUpdate(), and launchAction().

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

◆ updateWindGrib()

static bool updateWindGrib ( ClientRequest clientReq,
char *  checkMessage,
size_t  maxLen 
)
static

update Grib file if required

Definition at line 143 of file r3server.c.

References buildRootName(), clientReq, g_strlcpy, Par::gribFileName, ClientRequest::gribName, MAX_SIZE_FILE_NAME, par, readGribAll(), WIND, and zone.

Referenced by checkParamAndUpdate(), infoCoordToJson(), and launchAction().

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

Variable Documentation

◆ bigBuffer

char* bigBuffer = NULL

Definition at line 45 of file r3server.c.

Referenced by handleClient(), launchAction(), and main().

◆ clientReq

◆ filter

const char* filter[] = {".csv", ".pol", ".grb", ".grb2", ".log", ".txt", ".par", ".yaml", ".json", NULL}

Definition at line 48 of file r3server.c.

Referenced by launchAction(), listDirToStrJson(), and matchFilter().

◆ parameterFileName

char parameterFileName[MAX_SIZE_FILE_NAME]

Definition at line 59 of file r3server.c.

Referenced by initContext(), launchAction(), and main().

◆ typeLevel

const int typeLevel[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

Definition at line 57 of file r3server.c.

Referenced by allowedLevel().