** **
\*****************************************************************************/
-#include <stdio.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/resource.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-//#include <poll.h>
#include "main.h"
-static char *months[] = {
+static const char *months[] = {
"January", "February", "March", "April", "Mai", "June", "July",
"August", "September", "October", "November", "December"
};
PDEBUG(DEBUG_EPOINT, "child process started for sending a mail\n");
/* lower priority to keep pbx running fluently */
- if (options.schedule > 0)
- {
+ if (options.schedule > 0) {
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = 0;
ret = sched_setscheduler(0, SCHED_OTHER, &schedp);
- if (ret < 0)
- {
+ if (ret < 0) {
PERROR("Scheduling to normal priority failed (errno = %d).\nExitting child process...\n", errno);
goto done;
}
/* open process */
SPRINT(command, "%s -f%s %s", SENDMAIL, options.email, email);
- if ((ph = popen(command, "w")) < 0)
- {
+ if ((ph = popen(command, "w")) < 0) {
PERROR("Cannot send mail using command '%s'\n", command);
goto done;
}
fprintf(ph, "\n * date: %s %d %d %d:%02d\n\n", months[mon], mday, year+1900, hour, min);
/* attach audio file */
- if (filename[0])
- if ((fh = open(filename, O_RDONLY)))
- {
+ if (filename[0]) {
+ if ((fh = open(filename, O_RDONLY))) {
while(strchr(filename, '/'))
filename = strchr(filename, '/')+1;
fprintf(ph, "--next_part\n");
fprintf(ph, "Content-Transfer-Encoding: base64\nContent-Disposition: inline;\n\tfilename=\"%s\"\n\n", filename);
/* stream from disk and encode */
- while(42)
- {
+ while(42) {
/* read exactly one line */
cnt = read(fh, rbuf, 54);
if (cnt <= 0)
break;
/* encode */
n = cnt;
- while (n%3)
- {
+ while (n%3) {
rbuf[n] = 0;
n++;
}
n = n/3;
i = 0;
- while(i<n)
- {
+ while(i<n) {
e1 = rbuf[i+i+i];
e2 = rbuf[i+i+i+1];
e3 = rbuf[i+i+i+2];
fprintf(ph, "\n\n");
close(fh);
- } else
- {
+ } else {
SPRINT(buffer, "-Error- Failed to read audio file: '%s'.\n\n", filename);
fprintf(ph, "%s", buffer);
PERROR("%s", buffer);
- }
+ }
+ }
/* finish mail */
fprintf(ph, ".\n");
PDEBUG(DEBUG_EPOINT, "child process done for sending a mail\n");
/* exit process */
- memset(args, 0, sizeof(struct mail_args));
- free(args);
+ FREE(args, sizeof(struct mail_args));
amemuse--;
return(NULL);
}
struct mail_args *arg;
pthread_t tid;
- arg = (struct mail_args *)calloc(1, sizeof(struct mail_args));
- if (!arg)
- {
- PERROR("failed to alloc memory.\n");
- return;
- }
+ arg = (struct mail_args *)MALLOC(sizeof(struct mail_args));
amemuse++;
SCPY(arg->email, vbox_email);
SCPY(arg->callername, callername);
SCPY(arg->terminal, terminal);
- if ((pthread_create(&tid, NULL, mail_child, arg)<0))
- {
+ if ((pthread_create(&tid, NULL, mail_child, arg)<0)) {
PERROR("failed to create mail-thread.\n");
return;
}