Modernize Bongo 0.7.0 foundation
This commit is contained in:
@@ -268,11 +268,12 @@ AuthSqlite_SetPassword(const char *user, const char *password)
|
||||
int
|
||||
AuthSqlite_GetUserStore(const char *user, struct sockaddr_in *store)
|
||||
{
|
||||
memset(store, 0, sizeof(store));
|
||||
UNUSED_PARAMETER(user);
|
||||
memset(store, 0, sizeof(*store));
|
||||
store->sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
store->sin_family = AF_INET;
|
||||
store->sin_port = htons(689);
|
||||
return TRUE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -333,6 +334,8 @@ AuthSqlite_InterfaceVersion(void)
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAMETER(argv);
|
||||
printf("This cannot be run directly");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@@ -399,9 +399,10 @@ MsgIsComment(unsigned char *base, unsigned char *limit, unsigned char **out)
|
||||
}
|
||||
|
||||
EXPORT BOOL
|
||||
MsgParseAddress(unsigned char *addressLine, size_t addressLineLength, unsigned char **local_part, unsigned char **domain ) {
|
||||
MsgParseAddress(char *addressLine, size_t addressLineLength, char **local_part, char **domain ) {
|
||||
UNUSED_PARAMETER(addressLineLength);
|
||||
/*TODO: this is a terribly simple parser of an email address into the local_part and the domain. this needs to be better */
|
||||
unsigned char *at = strchr(addressLine, '@');
|
||||
char *at = strchr(addressLine, '@');
|
||||
if (at) {
|
||||
*at = '\0';
|
||||
(*local_part)= MemStrdup(addressLine);
|
||||
|
||||
+87
-65
@@ -42,6 +42,8 @@
|
||||
#include <bongoutil.h>
|
||||
#include <bongostore.h>
|
||||
#include <curl/curl.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MSGAPI_FLAG_EXITING (1 << 0)
|
||||
#define MSGAPI_FLAG_STANDALONE (1 << 1)
|
||||
@@ -93,7 +95,7 @@ struct {
|
||||
struct {
|
||||
unsigned long local;
|
||||
|
||||
unsigned char string[16];
|
||||
char string[INET_ADDRSTRLEN];
|
||||
} address;
|
||||
|
||||
struct {
|
||||
@@ -123,24 +125,28 @@ MsgGetUpdateStatus(char *record, int record_length);
|
||||
void
|
||||
MsgNmapChallenge(const unsigned char *response, unsigned char *reply, size_t length)
|
||||
{
|
||||
unsigned char *ptr;
|
||||
unsigned char *salt;
|
||||
const unsigned char *start;
|
||||
const unsigned char *end;
|
||||
static char access[NMAP_HASH_SIZE] = { '\0' };
|
||||
xpl_hash_context ctx;
|
||||
|
||||
MsgGetServerCredential(access);
|
||||
|
||||
if (access[0] && reply && (length > 32) && ((ptr = strchr(response, '<')) != NULL)) {
|
||||
salt = ++ptr;
|
||||
|
||||
if ((ptr = strchr(ptr, '>')) != NULL) {
|
||||
*ptr = '\0';
|
||||
}
|
||||
|
||||
start = response
|
||||
? (const unsigned char *)strchr((const char *)response, '<')
|
||||
: NULL;
|
||||
if (access[0] && reply && (length > 32) && start != NULL) {
|
||||
start++;
|
||||
end = (const unsigned char *)strchr((const char *)start, '>');
|
||||
if (end == NULL) {
|
||||
*reply = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
XplHashNew(&ctx, XPLHASH_MD5);
|
||||
XplHashWrite(&ctx, salt, strlen(salt));
|
||||
XplHashWrite(&ctx, start, (size_t)(end - start));
|
||||
XplHashWrite(&ctx, access, NMAP_HASH_SIZE);
|
||||
XplHashFinal(&ctx, XPLHASH_LOWERCASE, reply, XPLHASH_MD5_LENGTH);
|
||||
XplHashFinal(&ctx, XPLHASH_LOWERCASE, (char *)reply, XPLHASH_MD5_LENGTH);
|
||||
} else if (reply) {
|
||||
*reply = '\0';
|
||||
}
|
||||
@@ -151,6 +157,7 @@ MsgNmapChallenge(const unsigned char *response, unsigned char *reply, size_t len
|
||||
EXPORT const unsigned char *
|
||||
MsgGetServerDN(unsigned char *buffer)
|
||||
{
|
||||
UNUSED_PARAMETER(buffer);
|
||||
// DEPRECATED
|
||||
return(NULL);
|
||||
}
|
||||
@@ -158,6 +165,8 @@ MsgGetServerDN(unsigned char *buffer)
|
||||
EXPORT BOOL
|
||||
MsgDomainExists(const unsigned char *domain, unsigned char *domainObjectDN)
|
||||
{
|
||||
UNUSED_PARAMETER(domain);
|
||||
UNUSED_PARAMETER(domainObjectDN);
|
||||
// DEPRECATED ?
|
||||
/* FIXME later; when we handle parent objects */
|
||||
return(FALSE);
|
||||
@@ -308,7 +317,7 @@ MsgGetDir(MsgApiDirectory directory, char *buffer, size_t buffer_size)
|
||||
EXPORT const char *
|
||||
MsgGetFile(MsgApiFile file, char *buffer, size_t buffer_size)
|
||||
{
|
||||
const unsigned char *path;
|
||||
const char *path;
|
||||
switch(file) {
|
||||
case MSGAPI_FILE_PUBKEY:
|
||||
path = XPL_DEFAULT_CERT_PATH;
|
||||
@@ -374,7 +383,6 @@ MsgLibraryStop(void)
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Get a config property from global configuration file. Removes dependency
|
||||
* on NCPServer object in the directory (as well as others). See msgapi.h for
|
||||
@@ -383,44 +391,53 @@ MsgLibraryStop(void)
|
||||
BOOL
|
||||
MsgGetConfigProperty(unsigned char *Buffer, unsigned char *Property)
|
||||
{
|
||||
int result = FALSE;
|
||||
char line[512];
|
||||
char *ptr;
|
||||
FILE *fh;
|
||||
int len;
|
||||
char conf_path[FILENAME_MAX];
|
||||
BOOL result = FALSE;
|
||||
char line[MSGSRV_CONFIG_MAX_PROP_CHARS * 2 + 4];
|
||||
char *name;
|
||||
char *value;
|
||||
char *end;
|
||||
FILE *fh;
|
||||
char conf_path[FILENAME_MAX];
|
||||
|
||||
snprintf(conf_path, FILENAME_MAX, "%s/bongo.conf", XPL_DEFAULT_CONF_DIR);
|
||||
if (Buffer == NULL || Property == NULL)
|
||||
return FALSE;
|
||||
Buffer[0] = '\0';
|
||||
if (snprintf(conf_path, sizeof(conf_path), "%s/%s", XPL_DEFAULT_CONF_DIR,
|
||||
MSGSRV_CONFIG_FILENAME) >= (int)sizeof(conf_path))
|
||||
return FALSE;
|
||||
|
||||
if (!(fh = fopen(conf_path, "r"))) {
|
||||
return result;
|
||||
}
|
||||
|
||||
while (fgets(line, 512, fh)) {
|
||||
if (line[0] != '#') {
|
||||
if ((ptr = strchr(line, '='))) {
|
||||
*ptr++ = '\0';
|
||||
len = strlen(ptr);
|
||||
|
||||
if (!strcmp(line, Property)) {
|
||||
if (ptr[len - 1] == '\n') {
|
||||
ptr[len - 1] = '\0';
|
||||
}
|
||||
|
||||
strncpy(Buffer, ptr, MSGSRV_CONFIG_MAX_PROP_CHARS);
|
||||
result = TRUE;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (fgets(line, sizeof(line), fh)) {
|
||||
name = line;
|
||||
while (isspace((unsigned char)*name))
|
||||
name++;
|
||||
if (*name == '#' || *name == '\0')
|
||||
continue;
|
||||
value = strchr(name, '=');
|
||||
if (value == NULL)
|
||||
continue;
|
||||
*value++ = '\0';
|
||||
end = name + strlen(name);
|
||||
while (end > name && isspace((unsigned char)end[-1]))
|
||||
*--end = '\0';
|
||||
if (strcmp(name, (const char *)Property) != 0)
|
||||
continue;
|
||||
while (isspace((unsigned char)*value))
|
||||
value++;
|
||||
end = value + strlen(value);
|
||||
while (end > value && isspace((unsigned char)end[-1]))
|
||||
*--end = '\0';
|
||||
snprintf((char *)Buffer, MSGSRV_CONFIG_MAX_PROP_CHARS + 1, "%s", value);
|
||||
result = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
fclose(fh);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
MsgGetUid(char *buffer, int buflen)
|
||||
@@ -452,10 +469,7 @@ MsgGetUid(char *buffer, int buflen)
|
||||
static BOOL
|
||||
MsgLibraryStart(void)
|
||||
{
|
||||
unsigned long i;
|
||||
struct sockaddr_in server_sockaddr;
|
||||
unsigned char path[XPL_MAX_PATH + 1];
|
||||
XplThreadID ID;
|
||||
|
||||
/* Prepare later config updates */
|
||||
XplRWLockInit(&MsgGlobal.configLock);
|
||||
@@ -468,12 +482,13 @@ MsgLibraryStart(void)
|
||||
|
||||
/* set the ip address up correctly */
|
||||
server_sockaddr.sin_addr.s_addr = XplGetHostIPAddress();
|
||||
sprintf(MsgGlobal.address.string, "%d.%d.%d.%d",
|
||||
server_sockaddr.sin_addr.s_net,
|
||||
server_sockaddr.sin_addr.s_host,
|
||||
server_sockaddr.sin_addr.s_lh,
|
||||
server_sockaddr.sin_addr.s_impno);
|
||||
MsgGlobal.address.local = inet_addr(MsgGlobal.address.string);
|
||||
if (inet_ntop(AF_INET, &server_sockaddr.sin_addr,
|
||||
MsgGlobal.address.string,
|
||||
sizeof(MsgGlobal.address.string)) == NULL) {
|
||||
strcpy(MsgGlobal.address.string, "127.0.0.1");
|
||||
server_sockaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
}
|
||||
MsgGlobal.address.local = server_sockaddr.sin_addr.s_addr;
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -504,8 +519,6 @@ MsgGetAvailableVersion(int *version)
|
||||
*/
|
||||
char record[500];
|
||||
char *ptr;
|
||||
int v;
|
||||
|
||||
if (!MsgGetUpdateStatus(record, 499))
|
||||
return FALSE;
|
||||
|
||||
@@ -542,7 +555,6 @@ MsgGetUpdateStatus(char *record, int record_length)
|
||||
static BOOL
|
||||
MsgReadConfiguration(void)
|
||||
{
|
||||
unsigned long i;
|
||||
struct tm *timeStruct;
|
||||
time_t utcTime;
|
||||
long tmp;
|
||||
@@ -609,6 +621,7 @@ MsgLibraryShutdown(void)
|
||||
MsgGlobal.flags |= MSGAPI_FLAG_EXITING;
|
||||
|
||||
oldGid = XplSetThreadGroupID(MsgGlobal.groupID);
|
||||
UNUSED_PARAMETER(oldGid);
|
||||
|
||||
MsgLibraryStop();
|
||||
|
||||
@@ -717,8 +730,8 @@ MsgClearRecoveryFlag(char *agent_name)
|
||||
EXPORT BOOL
|
||||
MsgGetServerCredential(char *buffer)
|
||||
{
|
||||
unsigned char credential[4097];
|
||||
unsigned char file[120];
|
||||
char credential[4097];
|
||||
char file[120];
|
||||
FILE *credfile;
|
||||
|
||||
memset(credential, 0, sizeof(credential));
|
||||
@@ -738,9 +751,10 @@ MsgGetServerCredential(char *buffer)
|
||||
EXPORT BOOL
|
||||
MsgSetServerCredential()
|
||||
{
|
||||
unsigned char credential[4097];
|
||||
unsigned char path[XPL_MAX_PATH];
|
||||
char credential[4097];
|
||||
char path[XPL_MAX_PATH];
|
||||
FILE *credfile;
|
||||
int fd;
|
||||
const char *posschars =
|
||||
"abcdefghijlkmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWYXZ"
|
||||
@@ -748,18 +762,26 @@ MsgSetServerCredential()
|
||||
int i, range;
|
||||
|
||||
range = strlen(posschars);
|
||||
for (i=0; i<4097; i++) {
|
||||
int ran = rand() % range;
|
||||
credential[i] = posschars[ran];
|
||||
XplRandomData(credential, sizeof(credential) - 1);
|
||||
for (i = 0; i < (int)sizeof(credential) - 1; i++) {
|
||||
credential[i] = posschars[(unsigned char)credential[i] % range];
|
||||
}
|
||||
credential[4096] = '\0';
|
||||
|
||||
snprintf(path, XPL_MAX_PATH, "%s/credential.dat", XPL_DEFAULT_DBF_DIR);
|
||||
credfile = fopen(path, "wb");
|
||||
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
|
||||
if (fd >= 0 && fchmod(fd, S_IRUSR | S_IWUSR) != 0) {
|
||||
close(fd);
|
||||
fd = -1;
|
||||
}
|
||||
credfile = fd >= 0 ? fdopen(fd, "wb") : NULL;
|
||||
if (credfile) {
|
||||
fwrite(credential, sizeof(char), sizeof(credential), credfile);
|
||||
fclose(credfile);
|
||||
return TRUE;
|
||||
BOOL ok = fwrite(credential, sizeof(char), sizeof(credential), credfile) == sizeof(credential);
|
||||
ok = (fclose(credfile) == 0) && ok;
|
||||
return ok;
|
||||
}
|
||||
if (fd >= 0) {
|
||||
close(fd);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ MsgAuthGetUserStore(const char *user, struct sockaddr_in *store)
|
||||
f = (AuthPlugin_GetUserStore *)&function->func;
|
||||
result = (*f)(user, store);
|
||||
} else {
|
||||
memset(store, 0, sizeof(store));
|
||||
memset(store, 0, sizeof(*store));
|
||||
store->sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
store->sin_family = AF_INET;
|
||||
store->sin_port = htons(689);
|
||||
|
||||
@@ -129,7 +129,6 @@ static Connection *
|
||||
ConnectToStore(const char *user)
|
||||
{
|
||||
char buffer[CONN_BUFSIZE + 1];
|
||||
struct sockaddr_in addr;
|
||||
Connection *conn;
|
||||
int ret;
|
||||
|
||||
@@ -304,10 +303,10 @@ RemoveGuidForeach (void *key, void *value, void *data)
|
||||
RemoveGuidForeachData *rgfd = data;
|
||||
EventData *evtData = value;
|
||||
|
||||
int ccode;
|
||||
UNUSED_PARAMETER(key);
|
||||
|
||||
NMAPSendCommandF(rgfd->conn, "UNLINK /calendars/%s %s\r\n", rgfd->calendarName, evtData->guid);
|
||||
ccode = NMAPReadAnswer(rgfd->conn, rgfd->buffer, rgfd->bufferLen, TRUE);
|
||||
NMAPReadAnswer(rgfd->conn, rgfd->buffer, rgfd->bufferLen, TRUE);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -427,6 +426,8 @@ MsgImportIcs(FILE *fh,
|
||||
int ret;
|
||||
const char *icsName;
|
||||
char *icsNameDup = NULL;
|
||||
|
||||
UNUSED_PARAMETER(calendarColor);
|
||||
|
||||
component = ParseIcs(fh);
|
||||
if (!component) {
|
||||
@@ -701,7 +702,7 @@ MsgImportIcsUrl(const char *user,
|
||||
FILE *fh = XplOpenTemp("/tmp", "w+", filename);
|
||||
char cred[1024];
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, TRUE);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
if (aliasedUrl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, aliasedUrl);
|
||||
} else {
|
||||
|
||||
+62
-32
@@ -176,10 +176,10 @@ MsgGetDate(long rataDie, unsigned long *day, unsigned long *month, unsigned long
|
||||
}
|
||||
|
||||
EXPORT BOOL
|
||||
MsgGetRFC822Date(long offset, long utcTime, unsigned char *dateBuffer)
|
||||
MsgGetRFC822Date(long offset, long utcTime, char *dateBuffer)
|
||||
{
|
||||
struct tm timeStruct;
|
||||
unsigned char tempBuffer[80];
|
||||
char tempBuffer[80];
|
||||
|
||||
if (utcTime == 0) {
|
||||
utcTime = time(NULL);
|
||||
@@ -263,16 +263,22 @@ uint64_t
|
||||
MsgParseRFC822Date(const char *date)
|
||||
{
|
||||
uint64_t utc;
|
||||
char *copy;
|
||||
char *dayPtr;
|
||||
char *monthPtr;
|
||||
char *yearPtr;
|
||||
unsigned long month;
|
||||
|
||||
dayPtr = strchr(date, ',');
|
||||
copy = MemStrdup(date);
|
||||
if (copy == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
dayPtr = strchr(copy, ',');
|
||||
if (dayPtr) {
|
||||
dayPtr++;
|
||||
} else {
|
||||
dayPtr = (char *)date;
|
||||
dayPtr = copy;
|
||||
}
|
||||
|
||||
while((*dayPtr == ' ') || (*dayPtr == '\t')) {
|
||||
@@ -290,11 +296,13 @@ MsgParseRFC822Date(const char *date)
|
||||
yearPtr++;
|
||||
utc = MsgGetUTC((unsigned long)atol(dayPtr), month, (unsigned long)atol(yearPtr), 0, 0, 0);
|
||||
if (utc < ((unsigned long) -1)) {
|
||||
MemFree(copy);
|
||||
return(utc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MemFree(copy);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -463,22 +471,43 @@ MsgGetDMY(unsigned long utcTime, unsigned long *day, unsigned long *month, unsig
|
||||
* %Y - Year with century as decimal number
|
||||
* %Z - Timezone offset from UTC (+/- 0000) */
|
||||
|
||||
EXPORT unsigned long
|
||||
MsgPrint(unsigned char *buffer, int bufSize, unsigned char *format, unsigned long timeIn, MsgDateFormat *dateInfo)
|
||||
static void
|
||||
MsgAppendFormat(char **dest, char *limit, const char *format, ...)
|
||||
{
|
||||
unsigned long rataDie;
|
||||
unsigned char *src;
|
||||
unsigned char *dest;
|
||||
unsigned char *limit;
|
||||
size_t available;
|
||||
int written;
|
||||
va_list args;
|
||||
|
||||
if (*dest >= limit) {
|
||||
return;
|
||||
}
|
||||
available = (size_t)(limit - *dest);
|
||||
va_start(args, format);
|
||||
written = vsnprintf(*dest, available, format, args);
|
||||
va_end(args);
|
||||
if (written < 0 || (size_t)written >= available) {
|
||||
*dest = limit;
|
||||
} else {
|
||||
*dest += written;
|
||||
}
|
||||
}
|
||||
|
||||
EXPORT unsigned long
|
||||
MsgPrint(char *buffer, int bufSize, const char *format, unsigned long timeIn, const MsgDateFormat *dateInfo)
|
||||
{
|
||||
const char *src;
|
||||
char *dest;
|
||||
char *limit;
|
||||
struct tm tms;
|
||||
time_t utc;
|
||||
unsigned long i;
|
||||
|
||||
rataDie = 0;
|
||||
src = format;
|
||||
dest = buffer;
|
||||
limit = buffer + bufSize;
|
||||
|
||||
gmtime_r((time_t *)&timeIn, &tms);
|
||||
utc = (time_t)timeIn;
|
||||
gmtime_r(&utc, &tms);
|
||||
|
||||
while (*src && dest < limit) {
|
||||
switch (*src) {
|
||||
@@ -531,13 +560,13 @@ MsgPrint(unsigned char *buffer, int bufSize, unsigned char *format, unsigned lon
|
||||
}
|
||||
|
||||
case 'd': {
|
||||
dest += snprintf(dest, limit - dest, "%02d", tms.tm_mday);
|
||||
MsgAppendFormat(&dest, limit, "%02d", tms.tm_mday);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'H': {
|
||||
dest += snprintf(dest, limit - dest, "%02d", tms.tm_hour);
|
||||
MsgAppendFormat(&dest, limit, "%02d", tms.tm_hour);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
@@ -545,9 +574,9 @@ MsgPrint(unsigned char *buffer, int bufSize, unsigned char *format, unsigned lon
|
||||
case 'I': {
|
||||
if (tms.tm_hour!=0) {
|
||||
if (tms.tm_hour>12) {
|
||||
dest += snprintf(dest, limit - dest, "%02d", tms.tm_hour - 12);
|
||||
MsgAppendFormat(&dest, limit, "%02d", tms.tm_hour - 12);
|
||||
} else {
|
||||
dest += snprintf(dest, limit - dest, "%02d", tms.tm_hour);
|
||||
MsgAppendFormat(&dest, limit, "%02d", tms.tm_hour);
|
||||
}
|
||||
} else {
|
||||
i = limit - dest > 2 ? 2 : limit - dest;
|
||||
@@ -559,19 +588,19 @@ MsgPrint(unsigned char *buffer, int bufSize, unsigned char *format, unsigned lon
|
||||
}
|
||||
|
||||
case 'j': {
|
||||
dest += snprintf(dest, limit - dest, "%d", tms.tm_yday + 1);
|
||||
MsgAppendFormat(&dest, limit, "%d", tms.tm_yday + 1);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'm': {
|
||||
dest += snprintf (dest, limit - dest, "%02d", tms.tm_mon + 1);
|
||||
MsgAppendFormat(&dest, limit, "%02d", tms.tm_mon + 1);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'M': {
|
||||
dest += snprintf(dest, limit - dest, "%02d", tms.tm_min);
|
||||
MsgAppendFormat(&dest, limit, "%02d", tms.tm_min);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
@@ -583,7 +612,7 @@ MsgPrint(unsigned char *buffer, int bufSize, unsigned char *format, unsigned lon
|
||||
}
|
||||
|
||||
case 'p': {
|
||||
dest += snprintf(dest, limit - dest, "%s", tms.tm_hour > 11 ? dateInfo->AmPm[1] : dateInfo->AmPm[0]);
|
||||
MsgAppendFormat(&dest, limit, "%s", tms.tm_hour > 11 ? dateInfo->AmPm[1] : dateInfo->AmPm[0]);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
@@ -591,19 +620,19 @@ MsgPrint(unsigned char *buffer, int bufSize, unsigned char *format, unsigned lon
|
||||
case 'r': {
|
||||
if (tms.tm_hour!=0) {
|
||||
if (tms.tm_hour>12) {
|
||||
dest += snprintf(dest, limit - dest, "%02d:%02d:%02d %s", tms.tm_hour-12, tms.tm_min, tms.tm_sec, dateInfo->AmPm[1]);
|
||||
MsgAppendFormat(&dest, limit, "%02d:%02d:%02d %s", tms.tm_hour-12, tms.tm_min, tms.tm_sec, dateInfo->AmPm[1]);
|
||||
} else {
|
||||
dest += snprintf(dest, limit - dest, "%02d:%02d:%02d %s", tms.tm_hour, tms.tm_min, tms.tm_sec, tms.tm_hour > 11 ? dateInfo->AmPm[1] : dateInfo->AmPm[0]);
|
||||
MsgAppendFormat(&dest, limit, "%02d:%02d:%02d %s", tms.tm_hour, tms.tm_min, tms.tm_sec, tms.tm_hour > 11 ? dateInfo->AmPm[1] : dateInfo->AmPm[0]);
|
||||
}
|
||||
} else {
|
||||
dest += snprintf(dest, limit - dest, "12:%02d:%02d %s", tms.tm_min, tms.tm_sec, dateInfo->AmPm[0]);
|
||||
MsgAppendFormat(&dest, limit, "12:%02d:%02d %s", tms.tm_min, tms.tm_sec, dateInfo->AmPm[0]);
|
||||
}
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'S': {
|
||||
dest += snprintf(dest, limit - dest, "%02d", tms.tm_sec);
|
||||
MsgAppendFormat(&dest, limit, "%02d", tms.tm_sec);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
@@ -615,7 +644,7 @@ MsgPrint(unsigned char *buffer, int bufSize, unsigned char *format, unsigned lon
|
||||
}
|
||||
|
||||
case 'T': {
|
||||
dest += snprintf(dest, limit - dest, "%02d:%02d:%02d", tms.tm_hour, tms.tm_min, tms.tm_sec);
|
||||
MsgAppendFormat(&dest, limit, "%02d:%02d:%02d", tms.tm_hour, tms.tm_min, tms.tm_sec);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
@@ -628,34 +657,34 @@ MsgPrint(unsigned char *buffer, int bufSize, unsigned char *format, unsigned lon
|
||||
rataDieToday = MsgGetRataDie(tms.tm_mday, tms.tm_mon + 1, tms.tm_year + 1900);
|
||||
i = rataDieYearStart % 7;
|
||||
if (i <= dateInfo->wDayStart) {
|
||||
rataDieYearStart -= abs(dateInfo->wDayStart - 7);
|
||||
rataDieYearStart -= 7 - dateInfo->wDayStart;
|
||||
}
|
||||
rataDieYearStart -= i;
|
||||
dest += snprintf(dest, limit - dest, "%d", (int)((rataDieToday-rataDieYearStart) / 7 + 1));
|
||||
MsgAppendFormat(&dest, limit, "%d", (int)((rataDieToday-rataDieYearStart) / 7 + 1));
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'w': {
|
||||
dest += snprintf(dest, limit - dest, "%d", tms.tm_wday);
|
||||
MsgAppendFormat(&dest, limit, "%d", tms.tm_wday);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'y': {
|
||||
dest += snprintf(dest, limit - dest, "%02d", tms.tm_year > 99 ? tms.tm_year - 100 : tms.tm_year);
|
||||
MsgAppendFormat(&dest, limit, "%02d", tms.tm_year > 99 ? tms.tm_year - 100 : tms.tm_year);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'Y': {
|
||||
dest += snprintf(dest, limit - dest, "%04d", tms.tm_year + 1900);
|
||||
MsgAppendFormat(&dest, limit, "%04d", tms.tm_year + 1900);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
|
||||
case 'Z': {
|
||||
dest += snprintf(dest, limit - dest, "%+4.4ld", dateInfo->timezoneOffset/36);
|
||||
MsgAppendFormat(&dest, limit, "%+4.4ld", dateInfo->timezoneOffset/36);
|
||||
src++;
|
||||
continue;
|
||||
}
|
||||
@@ -984,8 +1013,9 @@ MsgGetUTCOffsetByUTC(unsigned long timezone, unsigned long utc)
|
||||
unsigned long year;
|
||||
unsigned long hour;
|
||||
struct tm tms;
|
||||
time_t utcTime = (time_t)utc;
|
||||
|
||||
gmtime_r(&utc, &tms);
|
||||
gmtime_r(&utcTime, &tms);
|
||||
year = tms.tm_year+1900;
|
||||
month = tms.tm_mon+1;
|
||||
day = tms.tm_mday;
|
||||
|
||||
+17
-13
@@ -31,11 +31,20 @@ MsgSQLOpen(char *path, BongoMemStack *memstack, int locktimeoutms)
|
||||
|
||||
create = access(path, 0);
|
||||
|
||||
if (!(handle = MemMalloc(sizeof(MsgSQLHandle))) ||
|
||||
memset(handle, 0, sizeof(MsgSQLHandle)), 0 ||
|
||||
SQLITE_OK != sqlite3_open(path, &handle->db)) {
|
||||
handle = MemMalloc(sizeof(MsgSQLHandle));
|
||||
if (!handle) {
|
||||
Log(LOG_ERROR, "sql3: Out of memory opening database \"%s\"", path);
|
||||
return NULL;
|
||||
}
|
||||
memset(handle, 0, sizeof(MsgSQLHandle));
|
||||
|
||||
if (SQLITE_OK != sqlite3_open(path, &handle->db)) {
|
||||
Log(LOG_ERROR, "sql3: Failed to open database \"%s\"", path);
|
||||
goto fail;
|
||||
if (handle->db) {
|
||||
sqlite3_close(handle->db);
|
||||
}
|
||||
MemFree(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Log(LOG_TRACE, "open handle %ld", handle->db);
|
||||
@@ -53,11 +62,6 @@ MsgSQLOpen(char *path, BongoMemStack *memstack, int locktimeoutms)
|
||||
|
||||
return handle;
|
||||
|
||||
fail:
|
||||
if (handle) {
|
||||
MsgSQLClose(handle);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -135,7 +139,7 @@ int
|
||||
MsgSQLBeginTransaction(MsgSQLHandle *handle)
|
||||
{
|
||||
MsgSQLStatement *stmt;
|
||||
int result, reset;
|
||||
int result;
|
||||
int count = 1 + handle->lockTimeoutMs / MSGSQL_STMT_SLEEP_MS;
|
||||
BOOL locked = FALSE;
|
||||
|
||||
@@ -154,7 +158,7 @@ MsgSQLBeginTransaction(MsgSQLHandle *handle)
|
||||
do {
|
||||
result = sqlite3_step(stmt->stmt);
|
||||
Log(LOG_TRACE, "sql3: BEGIN TRAN stmt %ld", stmt->stmt);
|
||||
reset = sqlite3_reset(stmt->stmt);
|
||||
sqlite3_reset(stmt->stmt);
|
||||
Log(LOG_TRACE, "sql: - bt reset stmt %ld", stmt->stmt);
|
||||
} while (SQLITE_BUSY == result && --count && (XplDelay(MSGSQL_STMT_SLEEP_MS), 1));
|
||||
|
||||
@@ -423,7 +427,7 @@ MsgSQLResultInt64(MsgSQLStatement *_stmt, int column)
|
||||
int
|
||||
MsgSQLResultText(MsgSQLStatement *_stmt, int column, char *result, size_t result_size)
|
||||
{
|
||||
const char *out = sqlite3_column_text(_stmt->stmt, column);
|
||||
const char *out = (const char *)sqlite3_column_text(_stmt->stmt, column);
|
||||
Log(LOG_TRACE, "sql3: - result text %ld", _stmt->stmt);
|
||||
if (out != NULL)
|
||||
strncpy(result, out, result_size);
|
||||
@@ -436,7 +440,7 @@ MsgSQLResultTextPtr(MsgSQLStatement *_stmt, int column, char **ptr)
|
||||
{
|
||||
*ptr = NULL;
|
||||
|
||||
const char *result = sqlite3_column_text(_stmt->stmt, column);
|
||||
const char *result = (const char *)sqlite3_column_text(_stmt->stmt, column);
|
||||
if (result != NULL) *ptr = g_strdup(result);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user