Permalink
Browse files

removed extra includes of alarm.h, fixed string formatting issues

  • Loading branch information...
1 parent c0b6ae3 commit 78314fb523f2b936f1d51ffa7f29c3fa1eaed0eb Nathan Fritz committed Jul 3, 2009
Showing with 66 additions and 71 deletions.
  1. +0 −1 adhoc_commands.c
  2. +54 −54 alarm.c
  3. +1 −0 conflate.h
  4. +0 −1 kvpair.c
  5. +0 −1 logging.c
  6. +0 −1 persist.c
  7. +0 −1 util.c
  8. +11 −12 xmpp.c
View
1 adhoc_commands.c
@@ -4,7 +4,6 @@
#include <string.h>
#include <assert.h>
-#include "alarm.h"
#include "conflate.h"
#include "conflate_internal.h"
#include "conflate_convenience.h"
View
108 alarm.c
@@ -6,68 +6,68 @@
/* read alarm from queue, if there is none simply return an empty alert with ->open = 0 */
alarm_t get_alarm(alarm_queue_t *queue)
{
- pthread_mutex_lock(&(queue->mutex));
- alarm_t alarm;
- //while (queue->size == 0)
- //pthread_cond_wait(&(queue->empty), &(queue->mutex));
- if(queue->size == 0)
- {
- alarm.open = 0;
- strcpy(alarm.msg, "");
- } else {
- alarm = *queue->queue[queue->out];
- queue->size--;
- queue->out++;
- queue->out %= 100;
- }
- pthread_mutex_unlock(&(queue->mutex));
- pthread_cond_broadcast(&(queue->full));
- return alarm;
+ pthread_mutex_lock(&(queue->mutex));
+ alarm_t alarm;
+ //while (queue->size == 0)
+ //pthread_cond_wait(&(queue->empty), &(queue->mutex));
+ if(queue->size == 0)
+ {
+ alarm.open = 0;
+ strncpy(alarm.msg, "", 255);
+ } else {
+ alarm = *queue->queue[queue->out];
+ queue->size--;
+ queue->out++;
+ queue->out %= 100;
+ }
+ pthread_mutex_unlock(&(queue->mutex));
+ pthread_cond_broadcast(&(queue->full));
+ return alarm;
}
/* add an alarm to the queue */
void add_alarm(alarm_queue_t *queue, int runonce, int level, int freq, int escfreq, char msg[256])
{
- pthread_mutex_lock(&(queue->mutex));
- while (queue->size == 100)
- pthread_cond_wait(&(queue->full), &(queue->mutex));
- printf("Added message: %s\n", msg);
- alarm_t *alarm = queue->queue[queue->in];
- alarm->open = 1;
- alarm->runonce = runonce;
- alarm->level = level;
- alarm->levelmax = 5;
- memcpy((int *)alarm->num, (int *)queue->num, sizeof(queue->num));
- alarm->freq = freq;
- alarm->escfreq = escfreq;
- strcpy(alarm->msg, msg);
- queue->size++;
- queue->in++;
- queue->num++;
- queue->in %= 100;
- pthread_mutex_unlock(&(queue->mutex));
- pthread_cond_broadcast(&(queue->empty));
+ pthread_mutex_lock(&(queue->mutex));
+ while (queue->size == 100)
+ pthread_cond_wait(&(queue->full), &(queue->mutex));
+ printf("Added message: %s\n", msg);
+ alarm_t *alarm = queue->queue[queue->in];
+ alarm->open = 1;
+ alarm->runonce = runonce;
+ alarm->level = level;
+ alarm->levelmax = 5;
+ memcpy((int *)alarm->num, (int *)queue->num, sizeof(queue->num));
+ alarm->freq = freq;
+ alarm->escfreq = escfreq;
+ strncpy(alarm->msg, msg, 255);
+ queue->size++;
+ queue->in++;
+ queue->num++;
+ queue->in %= 100;
+ pthread_mutex_unlock(&(queue->mutex));
+ pthread_cond_broadcast(&(queue->empty));
}
/* set up thread safe FIFO queue for alarm structs */
void init_alarmqueue(alarm_queue_t *queue)
{
- alarm_t *alarmbuffer[100];
- alarm_queue_t *alarmqueue;
- /* init all 100 available alarms */
- int i;
- for (i = 0; i < 100; i++)
- {
- alarmbuffer[i] = malloc(sizeof(alarm_t));
- }
- alarmqueue = malloc(sizeof(alarm_queue_t) * 100);
- alarmqueue->num = 0;
- alarmqueue->in = 0;
- alarmqueue->out = 0;
- alarmqueue->size = 0;
- //alarmqueue->empty = PTHREAD_COND_INITIALIZER();
- //alarmqueue->full = PTHREAD_COND_INITIALIZER();
- //alarmqueue->mutex = PTHREAD_MUTEX_INITIALIZER();
- /* add the buffer to the alarmqueue */
- memcpy(alarmqueue->queue, alarmbuffer, sizeof(alarmbuffer));
+ alarm_t *alarmbuffer[100];
+ alarm_queue_t *alarmqueue;
+ /* init all 100 available alarms */
+ int i;
+ for (i = 0; i < 100; i++)
+ {
+ alarmbuffer[i] = malloc(sizeof(alarm_t));
+ }
+ alarmqueue = malloc(sizeof(alarm_queue_t) * 100);
+ alarmqueue->num = 0;
+ alarmqueue->in = 0;
+ alarmqueue->out = 0;
+ alarmqueue->size = 0;
+ //alarmqueue->empty = PTHREAD_COND_INITIALIZER();
+ //alarmqueue->full = PTHREAD_COND_INITIALIZER();
+ //alarmqueue->mutex = PTHREAD_MUTEX_INITIALIZER();
+ /* add the buffer to the alarmqueue */
+ memcpy(alarmqueue->queue, alarmbuffer, sizeof(alarmbuffer));
}
View
1 conflate.h
@@ -5,6 +5,7 @@
#include <sys/types.h>
#include <pthread.h>
+#include "alarm.h"
#include <strophe.h>
/*! \mainpage libconflate
View
1 kvpair.c
@@ -3,7 +3,6 @@
#include <string.h>
#include <assert.h>
-#include "alarm.h"
#include "conflate.h"
kvpair_t* mk_kvpair(const char* k, char** v)
View
1 logging.c
@@ -8,7 +8,6 @@
#include <syslog.h>
-#include "alarm.h"
#include "conflate.h"
#include "conflate_internal.h"
#include "conflate_convenience.h"
View
1 persist.c
@@ -5,7 +5,6 @@
#include <sqlite3.h>
-#include "alarm.h"
#include "conflate.h"
#include "conflate_internal.h"
#include "conflate_convenience.h"
View
1 util.c
@@ -3,7 +3,6 @@
#include <assert.h>
#include <string.h>
-#include "alarm.h"
#include "conflate.h"
char* safe_strdup(const char* in) {
View
23 xmpp.c
@@ -5,7 +5,6 @@
#include <sys/utsname.h>
#include <assert.h>
-#include "alarm.h"
#include "conflate.h"
#include "conflate_internal.h"
#include "conflate_convenience.h"
@@ -490,7 +489,7 @@ static int alarmqueue_handler(xmpp_conn_t * const conn, void * const userdata)
conflate_handle_t *handle = (conflate_handle_t*) userdata;
alarm_t alarm;
const char* myjid = xmpp_conn_get_bound_jid(conn);
- char id[256];
+ char id[262];
char open[2];
char runonce[2];
char level[2];
@@ -503,18 +502,18 @@ static int alarmqueue_handler(xmpp_conn_t * const conn, void * const userdata)
while (handle->alarms->size > 0)
{
alarm = get_alarm(handle->alarms);
- sprintf(open, "%d", alarm.open);
- sprintf(runonce, "%d", alarm.runonce);
- sprintf(level, "%d", alarm.level);
- sprintf(levelmax, "%d", alarm.levelmax);
- sprintf(num, "%d", alarm.num);
- sprintf(freq, "%ld", alarm.freq);
- sprintf(escfreq, "%ld", alarm.escfreq);
- sprintf(amsg, "%s", alarm.msg);
+ snprintf(open, 2, "%d", alarm.open);
+ snprintf(runonce, 2, "%d", alarm.runonce);
+ snprintf(level, 2, "%d", alarm.level);
+ snprintf(levelmax, 2, "%d", alarm.levelmax);
+ snprintf(num, 256, "%d", alarm.num);
+ snprintf(freq, 256, "%ld", alarm.freq);
+ snprintf(escfreq, 256, "%ld", alarm.escfreq);
+ snprintf(amsg, 256, "%s", alarm.msg);
/* if we got a legitimate alarm, send off alert */
if(alarm.open == 1)
{
- sprintf(id, "_alarm%d", alarm.num);
+ snprintf(id, 262, "_alarm%d", alarm.num);
//handler_add_id(conn, alarm_response_handler, id, handle);
//handler_add_timed(conn, alarm_missing_handler, 120000, handle);
xmpp_stanza_t* msg = xmpp_stanza_new(handle->ctx);
@@ -530,7 +529,7 @@ static int alarmqueue_handler(xmpp_conn_t * const conn, void * const userdata)
xmpp_stanza_t* mbody = xmpp_stanza_new(handle->ctx);
assert(mbody);
xmpp_stanza_set_name(mbody, "body");
- sprintf(body, "Alert\nRun once: %s\nLevel: %s\n%s", runonce, level, amsg);
+ snprintf(body, 1500, "Alert\nRun once: %s\nLevel: %s\n%s", runonce, level, amsg);
xmpp_stanza_set_text(mbody, body);
add_and_release(msg, mbody);

0 comments on commit 78314fb

Please sign in to comment.