ayttm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Ayttm-commits] CVS: ayttm/src tcp_util.c,NONE,1.1 tcp_util.h,NONE,1.1 u


From: Philip S Tellis <address@hidden>
Subject: [Ayttm-commits] CVS: ayttm/src tcp_util.c,NONE,1.1 tcp_util.h,NONE,1.1 util.c,1.43,1.44 chat_window.c,1.46,1.47 Makefile.am,1.22,1.23
Date: Fri, 07 Feb 2003 03:25:36 -0500

Update of /cvsroot/ayttm/ayttm/src
In directory subversions:/tmp/cvs-serv11196/src

Modified Files:
        util.c chat_window.c Makefile.am 
Added Files:
        tcp_util.c tcp_util.h 
Log Message:
fixed autotrans, and mem leaks in filters

--- NEW FILE: tcp_util.c ---
/*
 * Ayttm 
 *
 * Copyright (C) 2003, the Ayttm team
 * 
 * Ayttm is derivative of Everybuddy
 * Copyright (C) 1999-2002, Torrey Searle <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
 *
 */

/*
 * tcp_util.c
 * tcp/ip utilities
 *
 */

#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include "tcp_util.h"   /* so the compiler tells us about mismatches */
/* we should also use the proxy here */

/**
 * ay_socket_new
 * @host: The host to connect to
 * @port: The port to connect on
 *
 * Description: Connect a socket to the given host and port and
 * return a file descriptor to it.
 *
 * Returns:  File descriptor for the socket; -1 on error - errno is set
 **/
int ay_socket_new(const char * host, int port)
{
        struct sockaddr_in serv_addr;
        static struct hostent *server;
        static char last_host[256];
        int servfd;
        char **p;

        if(last_host[0] || strcasecmp(last_host, host)!=0) {
                if(!(server = gethostbyname(host))) {
                        /*WARNING(("failed to look up server (%s:%d)\n%d: %s", 
                                                host, port,
                                                h_errno, strerror(h_errno)));*/
                        errno=h_errno;
                        return -1;
                }
                strncpy(last_host, host, 255);
        }

        if((servfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
                /*WARNING(("Socket create error (%d): %s", errno, 
strerror(errno)));*/
                return -1;
        }

        /*LOG(("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);

                /*LOG(("trying %s", *p));*/
                if(connect(servfd, (struct sockaddr *) &serv_addr, 
                                        sizeof(serv_addr)) == -1) {
#ifdef __MINGW32__
                        int err = WSAGetLastError();
                        if(err!=WSAENETUNREACH && err != WSAECONNREFUSED && 
                                err != WSAETIMEDOUT)
#else
                        if(errno!=ECONNREFUSED && errno!=ETIMEDOUT && 
                                        errno!=ENETUNREACH) 
#endif
                        {
                                break;
                        }
                } else {
                        /*LOG(("connected"));*/
                        return servfd;
                }
        }

        /*WARNING(("Could not connect to %s:%d\n%d:%s", host, port, errno, 
                                strerror(errno)));*/
        close(servfd);
        return -1;
}

/**
 * ay_tcp_readline
 * @buff: A buffer to read bytes into
 * @maxlen: Maximum number of bytes to read
 * @fd: File descriptor to read from
 *
 * Description: Read a single line or as many bytes as were available
 * on the given file descriptor.
 * 
 * Returns: The number of bytes read; 0 on End of Stream;
 * -1 on error - errno is set
 **/
int ay_tcp_readline(char *buff, int maxlen, int fd)
{
        int n, rc;
        char c;

        for (n = 1; n < maxlen; n++) {

                do {
                        rc = read(fd, &c, 1);
                } while(rc == -1 && errno == EINTR);

                if (rc == 1) {
                        if(c == '\r')                   /* get rid of \r */
                                continue;
                        *buff = c;
                        if (c == '\n')
                                break;
                        buff++;
                } else if (rc == 0) {
                        if (n == 1)
                                return (0);             /* EOF, no data */
                        else
                                break;                  /* EOF, w/ data */
                } else {
                        return -1;
                }
        }

        *buff = 0;
        return (n);
}



--- NEW FILE: tcp_util.h ---
/*
 * Ayttm 
 *
 * Copyright (C) 2003, the Ayttm team
 * 
 * Ayttm is derivative of Everybuddy
 * Copyright (C) 1999-2002, Torrey Searle <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
 *
 */

/*
 *  tcp_util.h
 *  tcp/ip utilities
 *
 */

#ifndef __TCP_UTIL_H__
#define __TCP_UTIL_H__

int ay_socket_new(const char * host, int port);
int ay_tcp_readline(char * buff, int maxlen, int fd);

#endif

Index: util.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/util.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- util.c      6 Feb 2003 09:15:37 -0000       1.43
+++ util.c      7 Feb 2003 08:25:33 -0000       1.44
@@ -423,7 +423,7 @@
        int i;
        
        if (strstr (text, "\r\n") != NULL)
-               return text;
+               return g_strdup(text);
        
        data = g_strsplit(text,"\n",64);
        temp = g_strdup(data[0]);
@@ -1469,3 +1469,5 @@
 
        return l;
 }
+
+

Index: chat_window.c
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/chat_window.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- chat_window.c       6 Feb 2003 10:08:51 -0000       1.46
+++ chat_window.c       7 Feb 2003 08:25:33 -0000       1.47
@@ -477,6 +477,7 @@
                data->hist_pos=NULL;
        }
 
+       /* TODO make these two filters */
        if(RUN_SERVICE(data->local_user)->get_smileys)
                temp_message = eb_smilify(strdup(text), 
RUN_SERVICE(data->local_user)->get_smileys());
        else
@@ -486,33 +487,31 @@
 
        eb_update_window_title(data, FALSE);
 
-       /*  Outbound filters here - Meredydd */
-       filter_walk=outgoing_message_filters;
-
        eb_debug(DBG_CORE, "Starting to run outgoing filters\n");
 
-       while(filter_walk!=NULL) {
-               gchar * (*ifilter)(eb_local_account *, eb_account *, struct 
contact *, gchar *);
+       for(filter_walk = outgoing_message_filters; filter_walk; 
filter_walk=filter_walk->next) {
+               char * (*ifilter)(const eb_local_account *, const eb_account *, 
const struct contact *, const char *);
 
                eb_debug(DBG_CORE, "Running an outgoing filter\n");
 
-               ifilter=(gchar *(*)(eb_local_account *, eb_account *, struct 
contact *, gchar *))filter_walk->data;
+               ifilter=filter_walk->data;
 
-               text=ifilter(data->local_user, data->preferred, data->contact, 
text);
+               o_text=ifilter(data->local_user, data->preferred, 
data->contact, text);
+               free(text);
+               text=o_text;
 
                if(text==NULL) 
-                       return; /*  Urgh, no cleanup, but it does it on 
strlen(text)==0 too */
-
-               filter_walk=filter_walk->next;
+                       return;
        }
 
        eb_debug(DBG_CORE, "Finished outgoing filters\n");
 
        /*  end outbound filters */
 
-       o_text = text;
-       text = convert_eol(text);
-       g_free(o_text);
+       /* TODO: make this also a filter */
+       o_text = convert_eol(text);
+       g_free(text);
+       text=o_text;
 
 #ifdef HAVE_ICONV_H
        if(!eb_services[data->preferred->service_id].can_iconvert) {
@@ -1146,30 +1145,30 @@
                return;
 
        /* Inbound filters here - Meredydd */
-       filter_walk=incoming_message_filters;
 
        eb_debug(DBG_CORE, "Starting to run incoming filters\n");
 
        message=strdup(o_message);
 
-       while(filter_walk!=NULL)
-       {
-               gchar * (*ofilter)(eb_local_account *, eb_account *, struct 
contact *, gchar *);
+       for(filter_walk=incoming_message_filters; filter_walk; 
filter_walk=filter_walk->next) {
+               char * (*ofilter)(const eb_local_account *, const eb_account *, 
const struct contact *, const char *);
+               char *otext;
 
                eb_debug(DBG_CORE, "Running an incoming filter\n");
-               ofilter=(gchar *(*)(eb_local_account *, eb_account *, struct 
contact *, gchar *))filter_walk->data;
+               ofilter=filter_walk->data;
 
-               message=ofilter(account, remote, remote_contact, message);
+               otext=ofilter(account, remote, remote_contact, message);
+               free(message);
+               message = otext;
                if(message==NULL) 
-                       return; /* Nothing to clean up (I think...) */
-
-               filter_walk=filter_walk->next;
+                       return;
        }
 
        eb_debug(DBG_CORE, "Finished incoming filters\n");
 
        /* end inbound filters */
 
+       /* TODO make these filters */
        if(RUN_SERVICE(account)->get_smileys)
                temp_message = eb_smilify(message, 
RUN_SERVICE(account)->get_smileys());
        else

Index: Makefile.am
===================================================================
RCS file: /cvsroot/ayttm/ayttm/src/Makefile.am,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- Makefile.am 6 Feb 2003 08:52:42 -0000       1.22
+++ Makefile.am 7 Feb 2003 08:25:33 -0000       1.23
@@ -11,7 +11,7 @@
        plugin_api.c plugin.c file_select.c contact_actions.c \
        smileys.c help_menu.c crash.c account_parser.y account_scanner.l \
        contact_parser.y contact_scanner.l llist.c mem_util.c \
-       offline_queue_mgmt.c
+       offline_queue_mgmt.c tcp_util.c
 
 noinst_HEADERS = account.h service.h contact.h gtk_globals.h globals.h \
        status.h info_window.h chat_window.h util.h add_contact_window.h \
@@ -21,7 +21,7 @@
        browser.h input_list.h plugin.h plugin_api.h debug.h \
        nomodule.h file_select.h contact_actions.h \
        smileys.h intl.h account_parser.h contact_parser.h crash.h \
-       externs.h llist.h mem_util.h offline_queue_mgmt.h
+       externs.h llist.h mem_util.h offline_queue_mgmt.h tcp_util.h
 
 EXTRA_DIST = 
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]