Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 78314fb523f2b936f1d51ffa7f29c3fa1eaed0eb 1 parent c0b6ae3
authored July 03, 2009
1  adhoc_commands.c
@@ -4,7 +4,6 @@
4 4
 #include <string.h>
5 5
 #include <assert.h>
6 6
 
7  
-#include "alarm.h"
8 7
 #include "conflate.h"
9 8
 #include "conflate_internal.h"
10 9
 #include "conflate_convenience.h"
108  alarm.c
@@ -6,68 +6,68 @@
6 6
 /* read alarm from queue, if there is none simply return an empty alert with ->open = 0 */
7 7
 alarm_t get_alarm(alarm_queue_t *queue)
8 8
 {
9  
-	pthread_mutex_lock(&(queue->mutex));
10  
-	alarm_t alarm;
11  
-	//while (queue->size == 0)
12  
-			//pthread_cond_wait(&(queue->empty), &(queue->mutex));
13  
-	if(queue->size == 0)
14  
-	{
15  
-		alarm.open = 0;
16  
-		strcpy(alarm.msg, "");
17  
-	} else {
18  
-		alarm = *queue->queue[queue->out];
19  
-		queue->size--;
20  
-		queue->out++;
21  
-		queue->out %= 100;
22  
-	}
23  
-	pthread_mutex_unlock(&(queue->mutex));
24  
-	pthread_cond_broadcast(&(queue->full));
25  
-	return alarm;
  9
+    pthread_mutex_lock(&(queue->mutex));
  10
+    alarm_t alarm;
  11
+    //while (queue->size == 0)
  12
+            //pthread_cond_wait(&(queue->empty), &(queue->mutex));
  13
+    if(queue->size == 0)
  14
+    {
  15
+        alarm.open = 0;
  16
+        strncpy(alarm.msg, "", 255);
  17
+    } else {
  18
+        alarm = *queue->queue[queue->out];
  19
+        queue->size--;
  20
+        queue->out++;
  21
+        queue->out %= 100;
  22
+    }
  23
+    pthread_mutex_unlock(&(queue->mutex));
  24
+    pthread_cond_broadcast(&(queue->full));
  25
+    return alarm;
26 26
 }
27 27
 
28 28
 /* add an alarm to the queue */
29 29
 void add_alarm(alarm_queue_t *queue, int runonce, int level, int freq, int escfreq, char msg[256])
30 30
 {
31  
-	pthread_mutex_lock(&(queue->mutex));
32  
-	while (queue->size == 100)
33  
-		pthread_cond_wait(&(queue->full), &(queue->mutex));
34  
-	printf("Added message: %s\n", msg);
35  
-	alarm_t *alarm = queue->queue[queue->in];
36  
-	alarm->open = 1;
37  
-	alarm->runonce = runonce;
38  
-	alarm->level = level;
39  
-	alarm->levelmax = 5;
40  
-	memcpy((int *)alarm->num, (int *)queue->num, sizeof(queue->num));
41  
-	alarm->freq = freq;
42  
-	alarm->escfreq = escfreq;
43  
-	strcpy(alarm->msg, msg);
44  
-	queue->size++;
45  
-	queue->in++;
46  
-	queue->num++;
47  
-	queue->in %= 100;
48  
-	pthread_mutex_unlock(&(queue->mutex));
49  
-	pthread_cond_broadcast(&(queue->empty));
  31
+    pthread_mutex_lock(&(queue->mutex));
  32
+    while (queue->size == 100)
  33
+        pthread_cond_wait(&(queue->full), &(queue->mutex));
  34
+    printf("Added message: %s\n", msg);
  35
+    alarm_t *alarm = queue->queue[queue->in];
  36
+    alarm->open = 1;
  37
+    alarm->runonce = runonce;
  38
+    alarm->level = level;
  39
+    alarm->levelmax = 5;
  40
+    memcpy((int *)alarm->num, (int *)queue->num, sizeof(queue->num));
  41
+    alarm->freq = freq;
  42
+    alarm->escfreq = escfreq;
  43
+    strncpy(alarm->msg, msg, 255);
  44
+    queue->size++;
  45
+    queue->in++;
  46
+    queue->num++;
  47
+    queue->in %= 100;
  48
+    pthread_mutex_unlock(&(queue->mutex));
  49
+    pthread_cond_broadcast(&(queue->empty));
50 50
 }
51 51
 
52 52
 /* set up thread safe FIFO queue for alarm structs */
53 53
 void init_alarmqueue(alarm_queue_t *queue)
54 54
 {
55  
-	alarm_t *alarmbuffer[100];
56  
-	alarm_queue_t *alarmqueue;
57  
-	/* init all 100 available alarms */
58  
-	int i;
59  
-	for (i = 0; i < 100; i++)
60  
-	{
61  
-		alarmbuffer[i] = malloc(sizeof(alarm_t));
62  
-	}
63  
-	alarmqueue = malloc(sizeof(alarm_queue_t) * 100);
64  
-	alarmqueue->num = 0;
65  
-	alarmqueue->in = 0;
66  
-	alarmqueue->out = 0;
67  
-	alarmqueue->size = 0;
68  
-	//alarmqueue->empty = PTHREAD_COND_INITIALIZER();
69  
-	//alarmqueue->full = PTHREAD_COND_INITIALIZER();
70  
-	//alarmqueue->mutex = PTHREAD_MUTEX_INITIALIZER();
71  
-	/* add the buffer to the alarmqueue */
72  
-	memcpy(alarmqueue->queue, alarmbuffer, sizeof(alarmbuffer));
  55
+    alarm_t *alarmbuffer[100];
  56
+    alarm_queue_t *alarmqueue;
  57
+    /* init all 100 available alarms */
  58
+    int i;
  59
+    for (i = 0; i < 100; i++)
  60
+    {
  61
+        alarmbuffer[i] = malloc(sizeof(alarm_t));
  62
+    }
  63
+    alarmqueue = malloc(sizeof(alarm_queue_t) * 100);
  64
+    alarmqueue->num = 0;
  65
+    alarmqueue->in = 0;
  66
+    alarmqueue->out = 0;
  67
+    alarmqueue->size = 0;
  68
+    //alarmqueue->empty = PTHREAD_COND_INITIALIZER();
  69
+    //alarmqueue->full = PTHREAD_COND_INITIALIZER();
  70
+    //alarmqueue->mutex = PTHREAD_MUTEX_INITIALIZER();
  71
+    /* add the buffer to the alarmqueue */
  72
+    memcpy(alarmqueue->queue, alarmbuffer, sizeof(alarmbuffer));
73 73
 }
1  conflate.h
@@ -5,6 +5,7 @@
5 5
 #include <sys/types.h>
6 6
 #include <pthread.h>
7 7
 
  8
+#include "alarm.h"
8 9
 #include <strophe.h>
9 10
 
10 11
 /*! \mainpage libconflate
1  kvpair.c
@@ -3,7 +3,6 @@
3 3
 #include <string.h>
4 4
 #include <assert.h>
5 5
 
6  
-#include "alarm.h"
7 6
 #include "conflate.h"
8 7
 
9 8
 kvpair_t* mk_kvpair(const char* k, char** v)
1  logging.c
@@ -8,7 +8,6 @@
8 8
 
9 9
 #include <syslog.h>
10 10
 
11  
-#include "alarm.h"
12 11
 #include "conflate.h"
13 12
 #include "conflate_internal.h"
14 13
 #include "conflate_convenience.h"
1  persist.c
@@ -5,7 +5,6 @@
5 5
 
6 6
 #include <sqlite3.h>
7 7
 
8  
-#include "alarm.h"
9 8
 #include "conflate.h"
10 9
 #include "conflate_internal.h"
11 10
 #include "conflate_convenience.h"
1  util.c
@@ -3,7 +3,6 @@
3 3
 #include <assert.h>
4 4
 #include <string.h>
5 5
 
6  
-#include "alarm.h"
7 6
 #include "conflate.h"
8 7
 
9 8
 char* safe_strdup(const char* in) {
23  xmpp.c
@@ -5,7 +5,6 @@
5 5
 #include <sys/utsname.h>
6 6
 #include <assert.h>
7 7
 
8  
-#include "alarm.h"
9 8
 #include "conflate.h"
10 9
 #include "conflate_internal.h"
11 10
 #include "conflate_convenience.h"
@@ -490,7 +489,7 @@ static int alarmqueue_handler(xmpp_conn_t * const conn, void * const userdata)
490 489
     conflate_handle_t *handle = (conflate_handle_t*) userdata;
491 490
 	alarm_t alarm;
492 491
     const char* myjid = xmpp_conn_get_bound_jid(conn);
493  
-	char id[256];
  492
+	char id[262];
494 493
 	char open[2];
495 494
 	char runonce[2];
496 495
 	char level[2];
@@ -503,18 +502,18 @@ static int alarmqueue_handler(xmpp_conn_t * const conn, void * const userdata)
503 502
 	while (handle->alarms->size > 0)
504 503
 	{
505 504
 		alarm = get_alarm(handle->alarms);
506  
-		sprintf(open, "%d", alarm.open);
507  
-		sprintf(runonce, "%d", alarm.runonce);
508  
-		sprintf(level, "%d", alarm.level);
509  
-		sprintf(levelmax, "%d", alarm.levelmax);
510  
-		sprintf(num, "%d", alarm.num);
511  
-		sprintf(freq, "%ld", alarm.freq);
512  
-		sprintf(escfreq, "%ld", alarm.escfreq);
513  
-		sprintf(amsg, "%s", alarm.msg);
  505
+		snprintf(open, 2, "%d", alarm.open);
  506
+		snprintf(runonce, 2, "%d", alarm.runonce);
  507
+		snprintf(level, 2, "%d", alarm.level);
  508
+		snprintf(levelmax, 2, "%d", alarm.levelmax);
  509
+		snprintf(num, 256, "%d", alarm.num);
  510
+		snprintf(freq, 256, "%ld", alarm.freq);
  511
+		snprintf(escfreq, 256, "%ld", alarm.escfreq);
  512
+		snprintf(amsg, 256, "%s", alarm.msg);
514 513
 		/* if we got a legitimate alarm, send off alert */
515 514
 		if(alarm.open == 1)
516 515
 		{
517  
-			sprintf(id, "_alarm%d", alarm.num);
  516
+			snprintf(id, 262, "_alarm%d", alarm.num);
518 517
 			//handler_add_id(conn, alarm_response_handler, id, handle);
519 518
 			//handler_add_timed(conn, alarm_missing_handler, 120000, handle);
520 519
 			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)
530 529
 			xmpp_stanza_t* mbody = xmpp_stanza_new(handle->ctx);
531 530
 			assert(mbody);
532 531
 			xmpp_stanza_set_name(mbody, "body");
533  
-			sprintf(body, "Alert\nRun once: %s\nLevel: %s\n%s", runonce, level, amsg);
  532
+			snprintf(body, 1500, "Alert\nRun once: %s\nLevel: %s\n%s", runonce, level, amsg);
534 533
 			xmpp_stanza_set_text(mbody, body);
535 534
 			add_and_release(msg, mbody);
536 535
 

0 notes on commit 78314fb

Please sign in to comment.
Something went wrong with that request. Please try again.