mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-16 01:57:09 +00:00
enable persistent view of irc messages (#362)
* remove path from libirc-include * feature: irc: possibly show last n lines persistently instead of all lines said since last time * irc: add overflow-check, for case when no newmsg's ->next is NULL
This commit is contained in:
parent
c6ef3ba5e7
commit
e84ca1f966
@ -95,7 +95,7 @@ if(BUILD_ICAL)
|
|||||||
endif(BUILD_ICAL)
|
endif(BUILD_ICAL)
|
||||||
|
|
||||||
if(BUILD_IRC)
|
if(BUILD_IRC)
|
||||||
check_include_files(libircclient/libircclient.h IRC_H_)
|
check_include_files(libircclient.h IRC_H_)
|
||||||
if(NOT IRC_H_)
|
if(NOT IRC_H_)
|
||||||
message(FATAL_ERROR "Unable to find libircclient")
|
message(FATAL_ERROR "Unable to find libircclient")
|
||||||
endif(NOT IRC_H_)
|
endif(NOT IRC_H_)
|
||||||
|
@ -1758,11 +1758,12 @@
|
|||||||
<command>
|
<command>
|
||||||
<option>irc</option>
|
<option>irc</option>
|
||||||
</command>
|
</command>
|
||||||
<option>server(:port) #channel</option>
|
<option>server(:port) #channel (max_msg_lines)</option>
|
||||||
</term>
|
</term>
|
||||||
<listitem>Shows everything that's being told in #channel on IRCserver
|
<listitem>Shows everything that's being told in #channel on IRCserver
|
||||||
'server'. TCP-port 6667 is used for the connection unless 'port' is
|
'server'. TCP-port 6667 is used for the connection unless 'port' is
|
||||||
specified.
|
specified. Shows everything since the last time or the last
|
||||||
|
'max_msg_lines' entries if specified.
|
||||||
<para /></listitem>
|
<para /></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
34
src/irc.cc
34
src/irc.cc
@ -29,7 +29,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "text_object.h"
|
#include "text_object.h"
|
||||||
#include <libircclient/libircclient.h>
|
#include <libircclient.h>
|
||||||
|
|
||||||
struct ll_text {
|
struct ll_text {
|
||||||
char *text;
|
char *text;
|
||||||
@ -44,6 +44,7 @@ struct obj_irc {
|
|||||||
|
|
||||||
struct ctx {
|
struct ctx {
|
||||||
char *chan;
|
char *chan;
|
||||||
|
int max_msg_lines;
|
||||||
struct ll_text *messages;
|
struct ll_text *messages;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -61,14 +62,34 @@ void addmessage(struct ctx *ctxptr, char *nick, const char *text) {
|
|||||||
newmsg->text = (char*) malloc(strlen(nick) + strlen(text) + 4); //4 = ": \n"
|
newmsg->text = (char*) malloc(strlen(nick) + strlen(text) + 4); //4 = ": \n"
|
||||||
sprintf(newmsg->text, "%s: %s\n", nick, text);
|
sprintf(newmsg->text, "%s: %s\n", nick, text);
|
||||||
newmsg->next = NULL;
|
newmsg->next = NULL;
|
||||||
|
int msgcnt = 1;
|
||||||
if(!lastmsg) {
|
if(!lastmsg) {
|
||||||
ctxptr->messages = newmsg;
|
ctxptr->messages = newmsg;
|
||||||
} else {
|
} else {
|
||||||
|
msgcnt++;
|
||||||
while(lastmsg->next) {
|
while(lastmsg->next) {
|
||||||
lastmsg = lastmsg->next;
|
lastmsg = lastmsg->next;
|
||||||
|
msgcnt++;
|
||||||
|
if(msgcnt<0) {
|
||||||
|
NORM_ERR("irc: too many messages, discarding the last one.");
|
||||||
|
free(newmsg->text);
|
||||||
|
free(newmsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lastmsg->next = newmsg;
|
lastmsg->next = newmsg;
|
||||||
}
|
}
|
||||||
|
if(ctxptr->max_msg_lines>0) {
|
||||||
|
newmsg = ctxptr->messages;
|
||||||
|
msgcnt -= ctxptr->max_msg_lines;
|
||||||
|
while((msgcnt>0) && (ctxptr->messages)) {
|
||||||
|
msgcnt--;
|
||||||
|
newmsg = ctxptr->messages->next;
|
||||||
|
free(ctxptr->messages->text);
|
||||||
|
free(ctxptr->messages);
|
||||||
|
ctxptr->messages = newmsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ev_talkinchan(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count) {
|
void ev_talkinchan(irc_session_t *session, const char *event, const char *origin, const char **params, unsigned int count) {
|
||||||
@ -95,7 +116,7 @@ void ev_num(irc_session_t *session, unsigned int event, const char *origin, cons
|
|||||||
if(origin || count) {} //fix gcc warnings
|
if(origin || count) {} //fix gcc warnings
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IRCSYNTAX "The correct syntax is ${irc server(:port) #channel}"
|
#define IRCSYNTAX "The correct syntax is ${irc server(:port) #channel (max_msg_lines)}"
|
||||||
#define IRCPORT 6667
|
#define IRCPORT 6667
|
||||||
#define IRCNICK "conky"
|
#define IRCNICK "conky"
|
||||||
#define IRCSERVERPASS NULL
|
#define IRCSERVERPASS NULL
|
||||||
@ -108,6 +129,7 @@ void *ircclient(void *ptr) {
|
|||||||
irc_callbacks_t callbacks;
|
irc_callbacks_t callbacks;
|
||||||
char *server;
|
char *server;
|
||||||
char *strport;
|
char *strport;
|
||||||
|
char *str_max_msg_lines;
|
||||||
unsigned int port;
|
unsigned int port;
|
||||||
|
|
||||||
memset (&callbacks, 0, sizeof(callbacks));
|
memset (&callbacks, 0, sizeof(callbacks));
|
||||||
@ -120,6 +142,10 @@ void *ircclient(void *ptr) {
|
|||||||
if( ! ctxptr->chan) {
|
if( ! ctxptr->chan) {
|
||||||
NORM_ERR("irc: %s", IRCSYNTAX);
|
NORM_ERR("irc: %s", IRCSYNTAX);
|
||||||
}
|
}
|
||||||
|
str_max_msg_lines = strtok(NULL, " ");
|
||||||
|
if(str_max_msg_lines) {
|
||||||
|
ctxptr->max_msg_lines = strtol(str_max_msg_lines, NULL, 10);
|
||||||
|
}
|
||||||
ctxptr->messages = NULL;
|
ctxptr->messages = NULL;
|
||||||
irc_set_ctx(ircobj->session, ctxptr);
|
irc_set_ctx(ircobj->session, ctxptr);
|
||||||
server = strtok(server, ":");
|
server = strtok(server, ":");
|
||||||
@ -169,15 +195,19 @@ void print_irc(struct text_object *obj, char *p, int p_max_size) {
|
|||||||
while(curmsg) {
|
while(curmsg) {
|
||||||
nextmsg = curmsg->next;
|
nextmsg = curmsg->next;
|
||||||
strncat(p, curmsg->text, p_max_size - strlen(p) - 1);
|
strncat(p, curmsg->text, p_max_size - strlen(p) - 1);
|
||||||
|
if(!ctxptr->max_msg_lines) {
|
||||||
free(curmsg->text);
|
free(curmsg->text);
|
||||||
free(curmsg);
|
free(curmsg);
|
||||||
|
}
|
||||||
curmsg = nextmsg;
|
curmsg = nextmsg;
|
||||||
}
|
}
|
||||||
if(p[0] != 0) {
|
if(p[0] != 0) {
|
||||||
p[strlen(p) - 1] = 0;
|
p[strlen(p) - 1] = 0;
|
||||||
}
|
}
|
||||||
|
if(!ctxptr->max_msg_lines) {
|
||||||
ctxptr->messages = NULL;
|
ctxptr->messages = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void free_irc(struct text_object *obj) {
|
void free_irc(struct text_object *obj) {
|
||||||
struct obj_irc *ircobj = (struct obj_irc *) obj->data.opaque;
|
struct obj_irc *ircobj = (struct obj_irc *) obj->data.opaque;
|
||||||
|
Loading…
Reference in New Issue
Block a user