MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / timetToSipDateStr

Function timetToSipDateStr

modules/msilo/msfuncs.c:92–118  ·  view source on GitHub ↗

* Build a RFC 3261 compliant Date string from a time_t value * - date: input of time_t to build the string from * - buf: pointer to string for output * - bufLen: length of buf param * * return: >0 length of data copied to buf ; <0 error occurred */

Source from the content-addressed store, hash-verified

90 * return: >0 length of data copied to buf ; <0 error occurred
91 */
92int timetToSipDateStr(time_t date, char* buf, int bufLen)
93{
94 struct tm *gmt;
95 struct tm gmt_buf;
96 char* dayArray[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
97 char* monthArray[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
98 int len = 0;
99
100 gmt = gmtime_r(&date, &gmt_buf);
101 /* In RFC 3261 the format is always GMT and in the string form like
102 * "Wkday, Day Month Year HOUR:MIN:SEC GMT"
103 * "Mon, 19 Feb 2007 18:42:27 GMT"
104 */
105 len = snprintf(buf,bufLen,"Date: %s, %02d %s %d %02d:%02d:%02d GMT\r\n",
106 dayArray[gmt->tm_wday],
107 gmt->tm_mday,
108 monthArray[gmt->tm_mon],
109 1900 + gmt->tm_year,
110 gmt->tm_hour,
111 gmt->tm_min,
112 gmt->tm_sec
113 );
114
115 /* snprintf returns number of chars it should have printed, so you
116 * need to bounds check against input*/
117 return (len > bufLen) ? bufLen : len;
118}
119
120/**
121 * extract the value of Content-Type header

Callers 1

m_build_headersFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected