mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-24 11:55:43 +00:00
mboxscan: convert to generic object payload
This commit is contained in:
parent
dd36fc4caa
commit
4b0c1d3226
@ -1682,9 +1682,7 @@ void generate_text_internal(char *p, int p_max_size,
|
||||
print_trashed_mails(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(mboxscan) {
|
||||
mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
|
||||
text_buffer_size);
|
||||
snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
|
||||
print_mboxscan(obj, p, p_max_size);
|
||||
}
|
||||
OBJ(nodename) {
|
||||
snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
|
||||
|
@ -698,11 +698,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
||||
END OBJ(trashed_mails, 0)
|
||||
parse_local_mail_args(obj, arg);
|
||||
END OBJ(mboxscan, 0)
|
||||
obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
|
||||
obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
|
||||
/* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
|
||||
obj->data.mboxscan.output[0] = 1;
|
||||
strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
|
||||
parse_mboxscan_arg(obj, arg);
|
||||
END OBJ(mem, &update_meminfo)
|
||||
END OBJ(memeasyfree, &update_meminfo)
|
||||
END OBJ(memfree, &update_meminfo)
|
||||
@ -1379,8 +1375,7 @@ void free_text_objects(struct text_object *root, int internal)
|
||||
free_tztime(obj);
|
||||
break;
|
||||
case OBJ_mboxscan:
|
||||
free(data.mboxscan.args);
|
||||
free(data.mboxscan.output);
|
||||
free_mboxscan(obj);
|
||||
break;
|
||||
case OBJ_mails:
|
||||
case OBJ_new_mails:
|
||||
|
@ -31,10 +31,10 @@
|
||||
#include "conky.h"
|
||||
#include "logging.h"
|
||||
#include "mail.h"
|
||||
#include "text_object.h"
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include "mboxscan.h"
|
||||
|
||||
#define FROM_WIDTH 10
|
||||
#define SUBJECT_WIDTH 22
|
||||
@ -60,7 +60,7 @@ static int time_delay;
|
||||
|
||||
static char mbox_mail_spool[DEFAULT_TEXT_BUFFER_SIZE];
|
||||
|
||||
void mbox_scan(char *args, char *output, size_t max_len)
|
||||
static void mbox_scan(char *args, char *output, size_t max_len)
|
||||
{
|
||||
int i, u, flag;
|
||||
int force_rescan = 0;
|
||||
@ -365,3 +365,49 @@ void mbox_scan(char *args, char *output, size_t max_len)
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
struct mboxscan_data {
|
||||
char *args;
|
||||
char *output;
|
||||
};
|
||||
|
||||
void parse_mboxscan_arg(struct text_object *obj, const char *arg)
|
||||
{
|
||||
struct mboxscan_data *msd;
|
||||
|
||||
msd = malloc(sizeof(struct mboxscan_data));
|
||||
memset(msd, 0, sizeof(struct mboxscan_data));
|
||||
|
||||
msd->args = strndup(arg, text_buffer_size);
|
||||
msd->output = (char *) malloc(text_buffer_size);
|
||||
/* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
|
||||
msd->output[0] = 1;
|
||||
|
||||
obj->data.opaque = msd;
|
||||
}
|
||||
|
||||
void print_mboxscan(struct text_object *obj, char *p, int p_max_size)
|
||||
{
|
||||
struct mboxscan_data *msd = obj->data.opaque;
|
||||
|
||||
if (!msd)
|
||||
return;
|
||||
|
||||
mbox_scan(msd->args, msd->output, text_buffer_size);
|
||||
snprintf(p, p_max_size, "%s", msd->output);
|
||||
}
|
||||
|
||||
void free_mboxscan(struct text_object *obj)
|
||||
{
|
||||
struct mboxscan_data *msd = obj->data.opaque;
|
||||
|
||||
if (!msd)
|
||||
return;
|
||||
if (msd->args)
|
||||
free(msd->args);
|
||||
if (msd->output)
|
||||
free(msd->output);
|
||||
free(obj->data.opaque);
|
||||
obj->data.opaque = NULL;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,8 @@
|
||||
#ifndef _MBOXSCAN_H_
|
||||
#define _MBOXSCAN_H_
|
||||
|
||||
void mbox_scan(char *args, char *output, size_t max_len);
|
||||
void parse_mboxscan_arg(struct text_object *, const char *);
|
||||
void print_mboxscan(struct text_object *, char *, int);
|
||||
void free_mboxscan(struct text_object *);
|
||||
|
||||
#endif /* _MBOXSCAN_H_ */
|
||||
|
@ -449,11 +449,6 @@ struct text_object {
|
||||
unsigned int cpu_index;
|
||||
struct mail_s *mail;
|
||||
|
||||
struct {
|
||||
char *args;
|
||||
char *output;
|
||||
} mboxscan;
|
||||
|
||||
struct {
|
||||
void *opaque; /* temporary workaround to not blow stuff */
|
||||
struct text_object *next;
|
||||
|
Loading…
Reference in New Issue
Block a user