[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Ayttm-commits] CVS: ayttm/modules/smtp .cvsignore,NONE,1.1 Makefile.am
From: |
Philip S Tellis <address@hidden> |
Subject: |
[Ayttm-commits] CVS: ayttm/modules/smtp .cvsignore,NONE,1.1 Makefile.am,NONE,1.1 smtp.c,NONE,1.1 smtp_away.xpm,NONE,1.1 smtp_online.xpm,NONE,1.1 |
Date: |
Thu, 30 Jan 2003 00:30:12 -0500 |
Update of /cvsroot/ayttm/ayttm/modules/smtp
In directory subversions:/tmp/cvs-serv22732/smtp
Added Files:
.cvsignore Makefile.am smtp.c smtp_away.xpm smtp_online.xpm
Log Message:
renamed sms module to smtp module
--- NEW FILE: .cvsignore ---
.deps
.libs
Makefile
Makefile.in
*.la
*.lo
--- NEW FILE: Makefile.am ---
libdir = $(pkgdatadir)/modules
AM_CFLAGS = $(GTK_CFLAGS) -I$(top_srcdir)/src
lib_LTLIBRARIES = smtp.la
smtp_la_SOURCES = smtp.c
smtp_la_LDFLAGS = -module -avoid-version
noinst_HEADERS = smtp_online.xpm smtp_away.xpm
--- NEW FILE: smtp.c ---
/*
* smtp.c
*/
/*
* SMTP Extension for everybuddy
*
* Copyright (C) 2002, Philip Tellis <address@hidden>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "intl.h"
#include <string.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <ctype.h>
#include <fcntl.h>
#include "service.h"
#include "plugin_api.h"
#include "dialog.h" /* MAX_PREF_LEN */
#include "input_list.h"
#include "value_pair.h"
#include "util.h"
#include "message_parse.h" /* eb_parse_incoming_message */
#include "status.h" /* buddy_login, */
/* buddy_logoff, */
/* buddy_update_status */
/*******************************************************************************
* Begin Module Code
******************************************************************************/
/* Module defines */
#define plugin_info smtp_LTX_plugin_info
#define SERVICE_INFO smtp_LTX_SERVICE_INFO
/* Function Prototypes */
static int plugin_init();
static int plugin_finish();
struct service_callbacks * query_callbacks();
static int is_setting_state = 0;
static int ref_count = 0;
static char smtp_host[MAX_PREF_LEN] = "127.0.0.1";
static char smtp_port[MAX_PREF_LEN] = "25";
static int do_smtp_debug = 0;
/* Module Exports */
PLUGIN_INFO plugin_info =
{
PLUGIN_SERVICE,
"SMTP Service",
"SMTP Service Module",
"$Revision: 1.1 $",
"$Date: 2003/01/30 05:30:09 $",
&ref_count,
plugin_init,
plugin_finish,
NULL
};
struct service SERVICE_INFO = {
"SMTP",
-1,
TRUE, /* all messages are offline */
FALSE,
TRUE, /* true so i can prevent file transfer altogether */
FALSE,
NULL
};
/* End Module Exports */
static int plugin_init()
{
input_list *il = calloc(1, sizeof(input_list));
ref_count = 0;
plugin_info.prefs = il;
il->widget.entry.value = smtp_host;
il->widget.entry.name = "smtp_host";
il->widget.entry.label = _("SMTP Server:");
il->type = EB_INPUT_ENTRY;
il->next = calloc(1, sizeof(input_list));
il = il->next;
il->widget.entry.value = smtp_port;
il->widget.entry.name = "smtp_port";
il->widget.entry.label = _("Port:");
il->type = EB_INPUT_ENTRY;
il->next = calloc(1, sizeof(input_list));
il = il->next;
il->widget.checkbox.value = &do_smtp_debug;
il->widget.checkbox.name = "do_smtp_debug";
il->widget.checkbox.label = _("Enable debugging");
il->type = EB_INPUT_CHECKBOX;
return (0);
}
static int plugin_finish()
{
eb_debug(DBG_MOD, "Returning the ref_count: %i\n", ref_count);
return (ref_count);
}
/*******************************************************************************
* End Module Code
******************************************************************************/
#ifdef __STDC__
int SMTP_DEBUGLOG(char *fmt,...)
#else
int SMTP_DEBUGLOG(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
va_list ap;
#ifdef __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
vfprintf(stderr, fmt, ap);
fflush(stderr);
va_end(ap);
return 0;
}
#define LOG(x) if(do_smtp_debug) { SMTP_DEBUGLOG("%s:%d: ", __FILE__,
__LINE__); \
SMTP_DEBUGLOG x; \
SMTP_DEBUGLOG("\n"); }
#define WARNING(x) if(do_smtp_debug) { SMTP_DEBUGLOG("%s:%d: warning: ",
__FILE__, __LINE__); \
SMTP_DEBUGLOG x; \
SMTP_DEBUGLOG("\n"); }
#define SMTP_MSG_COLOR "#2080d0"
static char *eb_smtp_get_color(void) { return SMTP_MSG_COLOR; }
enum smtp_status_code { SMTP_STATUS_ONLINE, SMTP_STATUS_OFFLINE };
typedef struct eb_smtp_account_data {
int status; /* always online */
} eb_smtp_account_data;
typedef struct eb_smtp_local_account_data {
char password[255]; /* in case of SMTP Auth? */
int status; /* always online */
} eb_smtp_local_account_data;
static LList * eb_smtp_buddies = NULL;
static int smtp_connect(char *host, int port)
{
struct sockaddr_in serv_addr;
struct hostent *server;
int servfd;
int res;
char **p;
if(!(server = gethostbyname(host)))
{
fprintf(stderr, "failed to look up server (%s:%d)\n", host,
port);
return -1;
}
if((servfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
return -2;
fprintf(stderr, "Created a local socket\n");
fprintf(stderr, "connecting to %s:%d\n", host, port);
for (p = server->h_addr_list; *p; p++)
{
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
memcpy(&serv_addr.sin_addr.s_addr, *p, server->h_length);
serv_addr.sin_port = htons(port);
res = -1;
res = connect(servfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr));
if(res >= 0)
return servfd;
}
fprintf(stderr, "Could not connect to %s:%d\n", host, port);
close(servfd);
return -3;
}
static int smtp_tcp_readline(char *ptr, int maxlen, int fd)
{
int n, rc;
char c;
for (n = 1; n < maxlen; n++)
{
again:
if ((rc = read(fd, &c, 1)) == 1)
{
if(c == '\r') /* get rid of \r */
continue;
*ptr = c;
if (c == '\n')
break;
ptr++;
}
else if (rc == 0)
{
if (n == 1)
return 0; /* EOF, no data */
else
break; /* EOF, w/ data */
}
else
{
if (errno == EINTR)
goto again;
return -1;
}
}
*ptr = 0;
return n;
}
static int smtp_tcp_writeline(char *ptr, int fd)
{
int i, n=0, count=0;
int len;
char eoln[2] = "\r\n";
len = strlen(ptr);
for(i=1; i<=2; i++)
if(ptr[len-i] == '\r' || ptr[len-1] == '\n')
ptr[len-i] = '\0';
len = strlen(ptr);
while((n=write(fd, ptr+count, len)) < len) {
if(n<=0) {
if (errno == EINTR)
continue;
return n;
}
len-=n;
count+=n;
}
write(fd, eoln, 2);
return count;
}
static int validate_or_die_gracefully(char *buff, char *valid, int fd)
{
if(strstr(buff, valid) == buff) {
return 1;
}
fprintf(stderr, "%s\n", buff);
smtp_tcp_writeline("QUIT", fd);
close(fd);
return 0;
}
static int send_message(char *from, char *to, char *msg)
{
int fd;
char buff[1024];
char localhost[255];
int n, len;
if(gethostname(localhost, sizeof(localhost)-1) == -1) {
strcpy(localhost, "localhost");
fprintf(stderr, "could not get localhost name: %s\n",
strerror(errno));
}
fd = smtp_connect(smtp_host, atoi(smtp_port));
if(smtp_tcp_readline(buff, sizeof(buff)-1, fd) <= 0) {
fprintf(stderr, "smtp server closed connection\n");
close(fd);
return 0;
};
if(!validate_or_die_gracefully(buff, "220", fd))
return 0;
snprintf(buff, sizeof(buff)-1, "HELO %s", localhost);
smtp_tcp_writeline(buff, fd);
smtp_tcp_readline(buff, sizeof(buff)-1, fd);
if(!validate_or_die_gracefully(buff, "250", fd))
return 0;
snprintf(buff, sizeof(buff)-1, "MAIL FROM: %s", from);
smtp_tcp_writeline(buff, fd);
smtp_tcp_readline(buff, sizeof(buff)-1, fd);
if(!validate_or_die_gracefully(buff, "250", fd))
return 0;
snprintf(buff, sizeof(buff)-1, "RCPT TO: %s", to);
smtp_tcp_writeline(buff, fd);
smtp_tcp_readline(buff, sizeof(buff)-1, fd);
if(!validate_or_die_gracefully(buff, "250", fd))
return 0;
smtp_tcp_writeline("DATA", fd);
smtp_tcp_readline(buff, sizeof(buff)-1, fd);
if(!validate_or_die_gracefully(buff, "354", fd))
return 0;
len = strlen(msg);
for(n=1; msg[len-n] == '\r' || msg[len-n] == '\n'; n++)
msg[len-n] = '\0';
if(strstr(msg, "Subject:") != msg)
smtp_tcp_writeline("", fd);
smtp_tcp_writeline(msg, fd);
smtp_tcp_writeline(".", fd);
smtp_tcp_readline(buff, sizeof(buff)-1, fd);
if(!validate_or_die_gracefully(buff, "250", fd))
return 0;
smtp_tcp_writeline("QUIT", fd);
smtp_tcp_readline(buff, sizeof(buff)-1, fd);
if(!validate_or_die_gracefully(buff, "221", fd))
return 1;
close(fd);
return 1;
}
static eb_local_account *eb_smtp_read_local_account_config(LList * pairs)
{
eb_local_account *ela;
eb_smtp_local_account_data *sla;
if(!pairs) {
WARNING(("eb_smtp_read_local_account_config: pairs == NULL"));
return NULL;
}
ela = calloc(1, sizeof(eb_local_account));
sla = calloc(1, sizeof(eb_smtp_local_account_data));
ela->handle = strdup(value_pair_get_value(pairs, "SCREEN_NAME"));
strncpy(ela->alias, ela->handle, sizeof(ela->alias));
strncpy(sla->password, value_pair_get_value(pairs, "PASSWORD"),
sizeof(sla->password));
sla->status = SMTP_STATUS_OFFLINE;
ela->service_id = SERVICE_INFO.protocol_id;
ela->protocol_local_account_data = sla;
return ela;
}
static LList *eb_smtp_write_local_config(eb_local_account * account)
{
eb_smtp_local_account_data *sla = account->protocol_local_account_data;
LList *list = NULL;
value_pair *vp;
vp = calloc(1, sizeof(value_pair));
strcpy(vp->key, "SCREEN_NAME");
strcpy(vp->value, account->handle);
list = l_list_append(list, vp);
vp = calloc(1, sizeof(value_pair));
strcpy(vp->key, "PASSWORD");
strcpy(vp->value, sla->password);
list = l_list_append(list, vp);
return list;
}
static void _buddy_change_state(void * data, void * user_data)
{
eb_account *ea = find_account_by_handle(data, SERVICE_INFO.protocol_id);
eb_smtp_account_data *sad;
int status = (int)user_data;
if(!ea)
return;
sad = ea->protocol_account_data;
sad->status = status;
if(status == SMTP_STATUS_ONLINE)
buddy_login(ea);
else
buddy_logoff(ea);
buddy_update_status(ea);
}
static void eb_smtp_login(eb_local_account *account)
{
/* we should always be logged in */
eb_smtp_local_account_data *sla = account->protocol_local_account_data;
if(account->status_menu) {
sla->status = SMTP_STATUS_ONLINE;
is_setting_state = 1;
eb_set_active_menu_status(account->status_menu,
SMTP_STATUS_ONLINE);
is_setting_state = 0;
}
account->connected = 1;
ref_count++;
l_list_foreach(eb_smtp_buddies, _buddy_change_state,
(void *)SMTP_STATUS_ONLINE);
}
static void eb_smtp_logout(eb_local_account *account)
{
/* cannot logout */
eb_smtp_local_account_data *sla = account->protocol_local_account_data;
account->connected = 0;
ref_count--;
if(account->status_menu) {
sla->status = SMTP_STATUS_OFFLINE;
is_setting_state = 1;
eb_set_active_menu_status(account->status_menu,
SMTP_STATUS_OFFLINE);
is_setting_state = 0;
}
l_list_foreach(eb_smtp_buddies, _buddy_change_state,
(void *)SMTP_STATUS_OFFLINE);
}
static LList *eb_smtp_get_states()
{
LList *states = NULL;
states = l_list_append(states, "Online");
states = l_list_append(states, "Offline");
return states;
}
static int eb_smtp_get_current_state(eb_local_account *account)
{
eb_smtp_local_account_data *sla = account->protocol_local_account_data;
return sla->status;
}
static void eb_smtp_set_current_state(eb_local_account *account, int state)
{
eb_smtp_local_account_data *sla = account->protocol_local_account_data;
if(is_setting_state)
return;
if(sla->status == SMTP_STATUS_OFFLINE && state == SMTP_STATUS_ONLINE)
eb_smtp_login(account);
else if(sla->status == SMTP_STATUS_ONLINE && state ==
SMTP_STATUS_OFFLINE)
eb_smtp_logout(account);
sla->status = state;
}
static void eb_smtp_set_idle(eb_local_account * account, int idle)
{
}
static void eb_smtp_set_away(eb_local_account * account, char * message)
{
}
static eb_account *eb_smtp_new_account(char * account)
{
eb_account *ea = calloc(1, sizeof(eb_account));
eb_smtp_account_data *sad = calloc(1, sizeof(eb_smtp_account_data));
ea->protocol_account_data = sad;
strncpy(ea->handle, account, 255);
ea->service_id = SERVICE_INFO.protocol_id;
sad->status = SMTP_STATUS_OFFLINE;
return ea;
}
static void eb_smtp_add_user(eb_account * account)
{
eb_smtp_buddies = l_list_append(eb_smtp_buddies, account->handle);
buddy_login(account);
}
static void eb_smtp_del_user(eb_account * account)
{
eb_smtp_buddies = l_list_remove(eb_smtp_buddies, account->handle);
}
static eb_account *eb_smtp_read_account_config(LList * config, struct contact *
contact)
{
eb_account *ea = calloc(1, sizeof(eb_account));
eb_smtp_account_data *sad = calloc(1, sizeof(eb_smtp_account_data));
sad->status = SMTP_STATUS_OFFLINE;
strncpy(ea->handle, value_pair_get_value(config, "NAME"),
sizeof(ea->handle));
ea->service_id = SERVICE_INFO.protocol_id;
ea->protocol_account_data = sad;
ea->account_contact = contact;
ea->icon_handler = -1;
ea->status_handler = -1;
eb_smtp_add_user(ea);
return ea;
}
static int eb_smtp_query_connected(eb_account * account)
{
eb_smtp_account_data *sad = account->protocol_account_data;
return (sad->status == SMTP_STATUS_ONLINE);
}
static char *status_strings[] = {
"",
"(Offline)"
};
static char *eb_smtp_get_status_string(eb_account * account)
{
eb_smtp_account_data *sad = account->protocol_account_data;
return status_strings[sad->status];
}
#include "smtp_online.xpm"
#include "smtp_away.xpm"
static char ** eb_smtp_get_status_pixmap(eb_account * account)
{
eb_smtp_account_data *sad;
sad = account->protocol_account_data;
if(sad->status == SMTP_STATUS_ONLINE)
return smtp_online_xpm;
else
return smtp_away_xpm;
}
static void eb_smtp_send_file(eb_local_account *from, eb_account *to, char
*file)
{
do_message_dialog(_("You cannot send files through SMTP... yet"),
_("SMTP send file"), 0);
}
/* TODO make this async */
static void eb_smtp_send_im(eb_local_account * account_from,
eb_account * account_to, char * message)
{
char reply[1024] = "<FONT COLOR=\"#a0a0a0\"><I>";
if(smtp_send_message(account_from->handle, account_to->handle, message))
strcat(reply, _("Message Sent"));
else
strcat(reply, _("Error Sending Message"));
strcat(reply, "</I></FONT>");
eb_parse_incoming_message(account_from, account_to, &SERVICE_INFO,
reply);
}
static char * eb_smtp_check_login(char * user, char * pass)
{
return NULL;
}
struct service_callbacks *query_callbacks()
{
struct service_callbacks *sc;
sc = calloc(1, sizeof(struct service_callbacks));
sc->query_connected = eb_smtp_query_connected;
sc->login = eb_smtp_login;
sc->logout = eb_smtp_logout;
sc->check_login = eb_smtp_check_login;
sc->send_im = eb_smtp_send_im;
sc->read_local_account_config = eb_smtp_read_local_account_config;
sc->write_local_config = eb_smtp_write_local_config;
sc->read_account_config = eb_smtp_read_account_config;
sc->get_states = eb_smtp_get_states;
sc->get_current_state = eb_smtp_get_current_state;
sc->set_current_state = eb_smtp_set_current_state;
sc->new_account = eb_smtp_new_account;
sc->add_user = eb_smtp_add_user;
sc->del_user = eb_smtp_del_user;
sc->get_status_string = eb_smtp_get_status_string;
sc->get_status_pixmap = eb_smtp_get_status_pixmap;
sc->set_idle = eb_smtp_set_idle;
sc->set_away = eb_smtp_set_away;
sc->send_file = eb_smtp_send_file;
sc->get_color = eb_smtp_get_color;
return sc;
}
--- NEW FILE: smtp_away.xpm ---
/* XPM */
static char * smtp_away_xpm[] = {
"12 13 24 1",
" c None",
". c #73A0C6",
"+ c #A4C5E2",
"@ c #A9C9E4",
"# c #A6C7E2",
"$ c #A8C8E3",
"% c #ACCBE5",
"& c #9DC0DE",
"* c #9FC2E0",
"= c #A2C4E0",
"- c #AACAE4",
"; c #AECCE6",
"> c #9BBFDD",
", c #9EC1DF",
"' c #99BEDD",
") c #A5C6E2",
"! c #97BCDB",
"~ c #96BBDB",
"{ c #94BADA",
"] c #92B8D8",
"^ c #A1C3E0",
"/ c #8FB6D7",
"( c #99BDDC",
"_ c #93B9D9",
" .. ",
" .+@@+. ",
" address@hidden ",
".&address@hidden;+.",
".>,address@hidden@.",
".'>,*=)address@hidden",
".!'&,*=)address@hidden",
".~!'&,*=)$+.",
".{~!'&**+)=.",
".]{~!'&*^+,.",
" ./{~!>&,(. ",
" .._~!~.. ",
" .... "};
--- NEW FILE: smtp_online.xpm ---
/* XPM */
static char * smtp_online_xpm[] = {
"12 13 52 1",
" c None",
". c #000102",
"+ c #38668D",
"@ c #43729A",
"# c #44739B",
"$ c #39678E",
"% c #3B6A91",
"& c #3F6E96",
"* c #47779F",
"= c #46759D",
"- c #2E597E",
"; c #315E84",
"> c #356288",
", c #3C6B92",
"' c #406F97",
") c #45749C",
"! c #4A7AA2",
"~ c #2B567A",
"{ c #2E5A7F",
"] c #366389",
"^ c #3D6C93",
"/ c #417098",
"( c #4878A0",
"_ c #285275",
": c #2F5B80",
"< c #325F85",
"[ c #3E6D94",
"} c #254E70",
"| c #295376",
"1 c #2C577B",
"2 c #37648A",
"3 c #3A688F",
"4 c #234B6D",
"5 c #264F71",
"6 c #305C81",
"7 c #336086",
"8 c #214767",
"9 c #2A5478",
"0 c #2D587C",
"a c #37658B",
"b c #3B6990",
"c c #1D4261",
"d c #244C6E",
"e c #275073",
"f c #315D82",
"g c #346187",
"h c #1B3E5C",
"i c #214869",
"j c #2B5579",
"k c #1F4565",
"l c #254D6F",
"m c #234A6B",
" .. ",
" address@hidden ",
" ..+%&#*=.. ",
".-;>+,')*!$.",
".~{;]$^/)('.",
"._~:<]$^/)[.",
".}|1:<23^/%.",
".45|16723[+.",
".8459067ab].",
".c8de90fga6.",
" .hidej-{e. ",
" ..kl5m.. ",
" .... "};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Ayttm-commits] CVS: ayttm/modules/smtp .cvsignore,NONE,1.1 Makefile.am,NONE,1.1 smtp.c,NONE,1.1 smtp_away.xpm,NONE,1.1 smtp_online.xpm,NONE,1.1,
Philip S Tellis <address@hidden> <=
- Prev by Date:
[Ayttm-commits] CVS: ayttm/modules/sms .cvsignore,1.1.1.1,NONE Makefile.am,1.4,NONE sms.c,1.6,NONE sms_smtp.c,1.1.1.1,NONE sms_smtp.h,1.1.1.1,NONE
- Next by Date:
[Ayttm-commits] CVS: ayttm/pixmaps Makefile.am,1.4,1.5 sms_away.xpm,1.1.1.1,NONE sms_online.xpm,1.1.1.1,NONE
- Previous by thread:
[Ayttm-commits] CVS: ayttm/modules/sms .cvsignore,1.1.1.1,NONE Makefile.am,1.4,NONE sms.c,1.6,NONE sms_smtp.c,1.1.1.1,NONE sms_smtp.h,1.1.1.1,NONE
- Next by thread:
[Ayttm-commits] CVS: ayttm/pixmaps Makefile.am,1.4,1.5 sms_away.xpm,1.1.1.1,NONE sms_online.xpm,1.1.1.1,NONE
- Index(es):