mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Moved incoming display message
This commit is contained in:
parent
14f4478bea
commit
bbb0fbed4f
16
jabber.c
16
jabber.c
@ -12,24 +12,18 @@ extern WINDOW *main_win;
|
|||||||
int in_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
int in_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||||
void * const userdata)
|
void * const userdata)
|
||||||
{
|
{
|
||||||
char *intext;
|
char *message;
|
||||||
|
|
||||||
if(!xmpp_stanza_get_child_by_name(stanza, "body"))
|
if(!xmpp_stanza_get_child_by_name(stanza, "body"))
|
||||||
return 1;
|
return 1;
|
||||||
if(!strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error"))
|
if(!strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error"))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
|
message = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
|
||||||
|
|
||||||
char in_line[200];
|
|
||||||
char *from = xmpp_stanza_get_attribute(stanza, "from");
|
char *from = xmpp_stanza_get_attribute(stanza, "from");
|
||||||
|
|
||||||
char *short_from = strtok(from, "@");
|
char *short_from = strtok(from, "@");
|
||||||
|
show_incomming_msg(short_from, message);
|
||||||
sprintf(in_line, "%s: %s\n", short_from, intext);
|
|
||||||
|
|
||||||
wprintw(main_win, in_line);
|
|
||||||
wrefresh(main_win);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -42,7 +36,7 @@ void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
|
|||||||
|
|
||||||
if (status == XMPP_CONN_CONNECT) {
|
if (status == XMPP_CONN_CONNECT) {
|
||||||
xmpp_stanza_t* pres;
|
xmpp_stanza_t* pres;
|
||||||
fprintf(logp, "DEBUG: connected\n");
|
logmsg(CONN, "connected");
|
||||||
xmpp_handler_add(conn,in_message_handler, NULL, "message", NULL, ctx);
|
xmpp_handler_add(conn,in_message_handler, NULL, "message", NULL, ctx);
|
||||||
|
|
||||||
pres = xmpp_stanza_new(ctx);
|
pres = xmpp_stanza_new(ctx);
|
||||||
@ -51,7 +45,7 @@ void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
|
|||||||
xmpp_stanza_release(pres);
|
xmpp_stanza_release(pres);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(logp, "DEBUG: disconnected\n");
|
logmsg(CONN, "disconnected");
|
||||||
xmpp_stop(ctx);
|
xmpp_stop(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
log.c
7
log.c
@ -23,6 +23,11 @@ void xmpp_file_logger(void * const userdata, const xmpp_log_level_t level,
|
|||||||
|
|
||||||
void logmsg(const char * const area, const char * const msg)
|
void logmsg(const char * const area, const char * const msg)
|
||||||
{
|
{
|
||||||
fprintf(logp, "%s DEBUG %s\n", area, msg);
|
fprintf(logp, "%s DEBUG: %s\n", area, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void start_log(void)
|
||||||
|
{
|
||||||
|
logp = fopen("profanity.log", "a");
|
||||||
|
logmsg(PROF, "Starting Profanity...");
|
||||||
|
}
|
||||||
|
6
log.h
6
log.h
@ -1,9 +1,13 @@
|
|||||||
#ifndef LOG_H
|
#ifndef LOG_H
|
||||||
#define LOG_H
|
#define LOG_H
|
||||||
|
|
||||||
FILE *logp;
|
#define PROF "prof"
|
||||||
|
#define CONN "conn"
|
||||||
|
|
||||||
|
FILE *logp;
|
||||||
|
|
||||||
xmpp_log_t *xmpp_get_file_logger();
|
xmpp_log_t *xmpp_get_file_logger();
|
||||||
void logmsg(const char * const area, const char * const msg);
|
void logmsg(const char * const area, const char * const msg);
|
||||||
|
void start_log(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
10
profanity.c
10
profanity.c
@ -9,12 +9,9 @@
|
|||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#include "jabber.h"
|
#include "jabber.h"
|
||||||
|
|
||||||
// refernce to log
|
// reference to log
|
||||||
extern FILE *logp;
|
extern FILE *logp;
|
||||||
|
|
||||||
// area for log message in profanity
|
|
||||||
static const char *prof = "prof";
|
|
||||||
|
|
||||||
// window references
|
// window references
|
||||||
extern WINDOW *title_bar;
|
extern WINDOW *title_bar;
|
||||||
extern WINDOW *cmd_bar;
|
extern WINDOW *cmd_bar;
|
||||||
@ -32,8 +29,7 @@ int main(void)
|
|||||||
xmpp_conn_t *conn;
|
xmpp_conn_t *conn;
|
||||||
xmpp_log_t *log;
|
xmpp_log_t *log;
|
||||||
|
|
||||||
logp = fopen("profanity.log", "a");
|
start_log();
|
||||||
logmsg(prof, "Starting Profanity...");
|
|
||||||
|
|
||||||
// initialise curses, and create windows
|
// initialise curses, and create windows
|
||||||
initgui();
|
initgui();
|
||||||
@ -70,7 +66,7 @@ int main(void)
|
|||||||
|
|
||||||
char loginmsg[100];
|
char loginmsg[100];
|
||||||
sprintf(loginmsg, "User <%s> logged in", user);
|
sprintf(loginmsg, "User <%s> logged in", user);
|
||||||
logmsg(prof, loginmsg);
|
logmsg(PROF, loginmsg);
|
||||||
|
|
||||||
xmpp_initialize();
|
xmpp_initialize();
|
||||||
|
|
||||||
|
@ -80,3 +80,12 @@ static void create_main_window(void)
|
|||||||
main_win = newwin(rows-3, cols, 1, 0);
|
main_win = newwin(rows-3, cols, 1, 0);
|
||||||
scrollok(main_win, TRUE);
|
scrollok(main_win, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void show_incomming_msg(char *from, char *message)
|
||||||
|
{
|
||||||
|
char line[100];
|
||||||
|
sprintf(line, "%s: %s\n", from, message);
|
||||||
|
|
||||||
|
wprintw(main_win, line);
|
||||||
|
wrefresh(main_win);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user