adding get_crashdump_log()

doc_update_sequoia
Volker Birk 7 years ago
parent 3956a42b03
commit e7f3e262fc

@ -8,3 +8,9 @@ LD=$(CC)
# the next two lines are ignored on Windoze
SYSTEM_DB=/usr/local/share/pEp/system.db
PREFIX=$(HOME)
# C makros (not environment variables) to overwrite:
#
# DEFAULT_KEYSERVER - string with default keyserver
# CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps

@ -19,6 +19,8 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
static const char *sql_get_trust;
static const char *sql_least_trust;
static const char *sql_mark_as_compromized;
static const char *sql_crashdump;
bool in_first = false;
assert(sqlite3_threadsafe());
@ -199,6 +201,8 @@ DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
sql_least_trust = "select min(comm_type) from trust where pgp_keypair_fpr = ?1 ;";
sql_mark_as_compromized = "update trust not indexed set comm_type = 15 where pgp_keypair_fpr = ?1 ;";
sql_crashdump = "select title, entity, description, comment from log order by timestamp desc limit ?1 ;";
}
int_result = sqlite3_prepare_v2(_session->db, sql_log, (int)strlen(sql_log),
@ -315,9 +319,24 @@ DYNAMIC_API void release(PEP_SESSION session)
}
}
static void _clean_log_value(char *text)
{
if (text) {
for (char *c = text; *c; c++) {
if (*c < 32)
*c = 32;
else if (*c == '"')
*c = '\'';
}
}
}
DYNAMIC_API PEP_STATUS log_event(
PEP_SESSION session, const char *title, const char *entity,
const char *description, const char *comment
PEP_SESSION session,
char *title,
char *entity,
char *description,
char *comment
)
{
PEP_STATUS status = PEP_STATUS_OK;
@ -330,6 +349,11 @@ DYNAMIC_API PEP_STATUS log_event(
if (!(session && title && entity))
return PEP_ILLEGAL_VALUE;
_clean_log_value(title);
_clean_log_value(entity);
_clean_log_value(description);
_clean_log_value(comment);
sqlite3_reset(session->log);
sqlite3_bind_text(session->log, 1, title, -1, SQLITE_STATIC);
sqlite3_bind_text(session->log, 2, entity, -1, SQLITE_STATIC);
@ -1023,3 +1047,104 @@ DYNAMIC_API PEP_STATUS key_expired(
expired);
}
static char *_concat_string(char *str1, const char *str2, char delim)
{
assert(str2);
size_t len1 = str1 ? strlen(str1) : 0;
size_t len2 = strlen(str2);
size_t len = len1 + len2 + 3;
char * result = realloc(str1, len + 1);
if (result) {
result[len1] = '"';
strcpy(result + len1 + 1, str2);
_clean_log_value(result + len1 + 1);
result[len - 2] = '"';
result[len - 1] = delim;
result[len] = 0;
}
else {
free(str1);
}
return result;
}
DYNAMIC_API PEP_STATUS get_crashdump_log(
PEP_SESSION session,
int maxlines,
char **logdata
)
{
PEP_STATUS status = PEP_STATUS_OK;
char *_logdata= NULL;
assert(session);
assert(maxlines >= 0 && maxlines <= CRASHDUMP_MAX_LINES);
assert(logdata);
if (!(session && logdata && maxlines >= 0 && maxlines <=
CRASHDUMP_MAX_LINES))
return PEP_ILLEGAL_VALUE;
int limit = maxlines ? maxlines : CRASHDUMP_DEFAULT_LINES;
const char *title;
const char *entity;
const char *desc;
const char *comment;
sqlite3_reset(session->crashdump);
sqlite3_bind_int(session->crashdump, 1, limit);
int result;
do {
result = sqlite3_step(session->crashdump);
switch (result) {
case SQLITE_ROW:
title = (const char *) sqlite3_column_text(session->crashdump, 0);
entity = (const char *) sqlite3_column_text(session->crashdump, 1);
desc = (const char *) sqlite3_column_text(session->crashdump, 2);
comment = (const char *) sqlite3_column_text(session->crashdump, 3);
_logdata = _concat_string(_logdata, title, ',');
if (_logdata == NULL)
goto enomem;
_logdata = _concat_string(_logdata, entity, ',');
if (_logdata == NULL)
goto enomem;
_logdata = _concat_string(_logdata, desc, ',');
if (_logdata == NULL)
goto enomem;
_logdata = _concat_string(_logdata, comment, '\n');
if (_logdata == NULL)
goto enomem;
break;
case SQLITE_DONE:
break;
default:
status = PEP_UNKNOWN_ERROR;
result = SQLITE_DONE;
}
} while (result != SQLITE_DONE);
sqlite3_reset(session->crashdump);
if (status == PEP_STATUS_OK)
*logdata = _logdata;
goto the_end;
enomem:
status = PEP_OUT_OF_MEMORY;
the_end:
return status;
}

@ -213,8 +213,11 @@ DYNAMIC_API PEP_STATUS encrypt_and_sign(
// PEP_STATUS_OK log entry created
DYNAMIC_API PEP_STATUS log_event(
PEP_SESSION session, const char *title, const char *entity,
const char *description, const char *comment
PEP_SESSION session,
char *title,
char *entity,
char *description,
char *comment
);
@ -686,6 +689,20 @@ DYNAMIC_API PEP_STATUS key_expired(
);
// get_crashdump_log() - get the last log messages out
//
// parameters:
// session (in) session handle
// maxlines (in) maximum number of lines (0 for default)
// logdata (out) logdata
DYNAMIC_API PEP_STATUS get_crashdump_log(
PEP_SESSION session,
int maxlines,
char **logdata
);
#ifdef __cplusplus
}
#endif

@ -1,4 +1,4 @@
#define PEP_ENGINE_VERSION "0.5.0"
#define PEP_ENGINE_VERSION "0.6.0"
// this is 20 trustwords with 79 chars max
#define MAX_TRUSTWORDS_SPACE (20 * 80)
@ -13,7 +13,15 @@
#define MAX_LINELENGTH 1024
// default keyserver
#ifndef DEFAULT_KEYSERVER
#define DEFAULT_KEYSERVER "hkp://keys.gnupg.net"
#endif
// crashdump constants
#ifndef CRASHDUMP_DEFAULT_LINES
#define CRASHDUMP_DEFAULT_LINES 100
#endif
#define CRASHDUMP_MAX_LINES 32767
#include "platform.h"
@ -88,6 +96,7 @@ typedef struct _pEpSession {
sqlite3_stmt *least_trust;
sqlite3_stmt *mark_compromized;
sqlite3_stmt *reset_trust;
sqlite3_stmt *crashdump;
examine_identity_t examine_identity;
void *examine_management;

Loading…
Cancel
Save