Commit cba719f0 authored by Claes Sjofors's avatar Claes Sjofors

Sev server, problem with storage of quotes in alarm texts fixed (refs #232)

parent c07431ea
...@@ -1911,6 +1911,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep) ...@@ -1911,6 +1911,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep)
{ {
char query[400]; char query[400];
char timstr[40]; char timstr[40];
char eventtext[100];
int rc; int rc;
*sts = time_AtoAscii( &ep->time, time_eFormat_NumDateAndTime, timstr, sizeof(timstr)); *sts = time_AtoAscii( &ep->time, time_eFormat_NumDateAndTime, timstr, sizeof(timstr));
...@@ -1973,6 +1974,9 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep) ...@@ -1973,6 +1974,9 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep)
if ( found) if ( found)
return 1; return 1;
// Replace " to \" in event text
string_to_mysqlstring( ep->eventtext, eventtext, sizeof(eventtext));
if ( m_items[item_idx].options & pwr_mSevOptionsMask_PosixTime) { if ( m_items[item_idx].options & pwr_mSevOptionsMask_PosixTime) {
if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution) { if ( m_items[item_idx].options & pwr_mSevOptionsMask_HighTimeResolution) {
// Posix time, high resolution // Posix time, high resolution
...@@ -1980,7 +1984,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep) ...@@ -1980,7 +1984,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep)
"eventid_idx, eventtext, eventname) values (%ld,%ld,%d,%d,%d,%d,%d,'%s','%s')", "eventid_idx, eventtext, eventname) values (%ld,%ld,%d,%d,%d,%d,%d,'%s','%s')",
m_items[item_idx].tablename, m_items[item_idx].tablename,
(long int)ep->time.tv_sec, (long int)ep->time.tv_nsec, (long int)ep->time.tv_sec, (long int)ep->time.tv_nsec,
ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, ep->eventtext, ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, eventtext,
ep->eventname); ep->eventname);
} }
else { else {
...@@ -1989,7 +1993,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep) ...@@ -1989,7 +1993,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep)
"eventid_idx, eventtext, eventname) values (%ld,%d,%d,%d,%d,%d,'%s','%s')", "eventid_idx, eventtext, eventname) values (%ld,%d,%d,%d,%d,%d,'%s','%s')",
m_items[item_idx].tablename, m_items[item_idx].tablename,
(long int)ep->time.tv_sec, (long int)ep->time.tv_sec,
ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, ep->eventtext, ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, eventtext,
ep->eventname); ep->eventname);
} }
} }
...@@ -2000,7 +2004,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep) ...@@ -2000,7 +2004,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep)
"eventid_idx, eventtext, eventname) values ('%s',%ld,%d,%d,%d,%d,%d,'%s','%s')", "eventid_idx, eventtext, eventname) values ('%s',%ld,%d,%d,%d,%d,%d,'%s','%s')",
m_items[item_idx].tablename, m_items[item_idx].tablename,
timstr, (long int)ep->time.tv_nsec, timstr, (long int)ep->time.tv_nsec,
ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, ep->eventtext, ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, eventtext,
ep->eventname); ep->eventname);
} }
else { else {
...@@ -2009,7 +2013,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep) ...@@ -2009,7 +2013,7 @@ int sev_dbms::store_event( pwr_tStatus *sts, int item_idx, sev_event *ep)
"eventid_idx, eventtext, eventname) values ('%s',%d,%d,%d,%d,%d,'%s','%s')", "eventid_idx, eventtext, eventname) values ('%s',%d,%d,%d,%d,%d,'%s','%s')",
m_items[item_idx].tablename, m_items[item_idx].tablename,
timstr, timstr,
ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, ep->eventtext, ep->type, ep->eventprio, ep->eventid.Nix, ep->eventid.BirthTime.tv_sec, ep->eventid.Idx, eventtext,
ep->eventname); ep->eventname);
} }
...@@ -4122,6 +4126,37 @@ int sev_dbms::commit_transaction() ...@@ -4122,6 +4126,37 @@ int sev_dbms::commit_transaction()
return 1; return 1;
} }
void sev_dbms::string_to_mysqlstring( char *in, char *out, int size)
{
char *s, *t;
for ( s = in, t = out; *s; s++,t++) {
if ( *s == '\"' || *s == '\'') {
*t = '\\';
t++;
}
*t = *s;
if ( t - out >= size - 1)
break;
}
*t = 0;
}
void sev_dbms::mysqlstring_to_string( char *in, char *out, int size)
{
char *s, *t;
for ( s = in, t = out; *s; s++,t++) {
if ( *s == '\\' && (*(s+1) == '\"' || *(s+1) == '\''))
s++;
*t = *s;
if ( t - out >= size - 1)
break;
}
*t = 0;
}
sev_dbms::~sev_dbms() sev_dbms::~sev_dbms()
{ {
printf("Freeing memory\n"); printf("Freeing memory\n");
......
...@@ -207,6 +207,8 @@ class sev_dbms : public sev_db { ...@@ -207,6 +207,8 @@ class sev_dbms : public sev_db {
int begin_transaction(); int begin_transaction();
int commit_transaction(); int commit_transaction();
int get_closest_time( char *tablename, unsigned int options, pwr_tTime *time, int before, int *id); int get_closest_time( char *tablename, unsigned int options, pwr_tTime *time, int before, int *id);
void string_to_mysqlstring( char *in, char *out, int size);
void mysqlstring_to_string( char *in, char *out, int size);
inline char* create_colName(unsigned int index, char *attributename) { inline char* create_colName(unsigned int index, char *attributename) {
static char colName[constMaxColNameLength]; static char colName[constMaxColNameLength];
strncpy(colName, attributename, constMaxColNameLength); strncpy(colName, attributename, constMaxColNameLength);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment