Enlightenment CVS committal

Author  : raster
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_con


Modified Files:
        Ecore_Con.h ecore_con.c ecore_con_private.h 


Log Message:


add calls to get ip addr of client or server (NULL for created servers of
course) and comments/docs

===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_con/Ecore_Con.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -3 -r1.16 -r1.17
--- Ecore_Con.h 13 Mar 2006 08:50:26 -0000      1.16
+++ Ecore_Con.h 20 Mar 2006 07:45:58 -0000      1.17
@@ -151,12 +151,14 @@
    EAPI int               ecore_con_server_connected_get(Ecore_Con_Server 
*svr);
    EAPI int               ecore_con_server_send(Ecore_Con_Server *svr, void 
*data, int size);
    EAPI void              ecore_con_server_client_limit_set(Ecore_Con_Server 
*svr, int client_limit, char reject_excess_clients);
+   EAPI char             *ecore_con_server_ip_get(Ecore_Con_Server *svr);
    
    EAPI int               ecore_con_client_send(Ecore_Con_Client *cl, void 
*data, int size);
    EAPI Ecore_Con_Server *ecore_con_client_server_get(Ecore_Con_Client *cl);
    EAPI void             *ecore_con_client_del(Ecore_Con_Client *cl);
    EAPI void              ecore_con_client_data_set(Ecore_Con_Client *cl, 
const void *data);
    EAPI void             *ecore_con_client_data_get(Ecore_Con_Client *cl);
+   EAPI char             *ecore_con_client_ip_get(Ecore_Con_Client *cl);
    
    EAPI int               ecore_con_ssl_available_get(void);
 
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_con/ecore_con.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -3 -r1.61 -r1.62
--- ecore_con.c 20 Mar 2006 05:59:20 -0000      1.61
+++ ecore_con.c 20 Mar 2006 07:45:58 -0000      1.62
@@ -338,6 +338,7 @@
    if (svr->fd >= 0) close(svr->fd);
    if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
    if (svr->write_buf) free(svr->write_buf);
+   if (svr->ip) free(svr->ip);
 #if USE_OPENSSL
    if (svr->ssl) SSL_free(svr->ssl);
    if (svr->ssl_ctx) SSL_CTX_free(svr->ssl_ctx);
@@ -627,6 +628,28 @@
 }
 
 /**
+ * Gets the IP address of a server that has been connected to.
+ * 
+ * @param   svr           The given server.
+ * @return  A pointer to an internal string that contains the IP address of
+ *          the connected server in the form "XXX.YYY.ZZZ.AAA" IP notation.
+ *          This string should not be modified or trusted to stay valid after
+ *          deletion for the @p svr object. If no IP is known NULL is returned.
+ * @ingroup Ecore_Con_Server_Group
+ */
+EAPI char *
+ecore_con_server_ip_get(Ecore_Con_Server *svr)
+{
+   if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
+     {
+       ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
+                        "ecore_con_server_ip_get");
+       return NULL;
+     }
+   return svr->ip;
+}
+
+/**
  * @defgroup Ecore_Con_Client_Group Ecore Connection Client Functions
  *
  * Functions that operate on Ecore connection client objects.
@@ -761,6 +784,28 @@
 }
 
 /**
+ * Gets the IP address of a cleint that has connected.
+ * 
+ * @param   cl            The given client.
+ * @return  A pointer to an internal string that contains the IP address of
+ *          the connected client in the form "XXX.YYY.ZZZ.AAA" IP notation.
+ *          This string should not be modified or trusted to stay valid after
+ *          deletion for the @p cl object. If no IP is known NULL is returned.
+ * @ingroup Ecore_Con_Client_Group
+ */
+EAPI char *
+ecore_con_client_ip_get(Ecore_Con_Client *cl)
+{
+   if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
+     {
+       ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
+                        "ecore_con_client_ip_get");
+       return NULL;
+     }
+   return cl->ip;
+}
+
+/**
  * Returns if SSL support is available
  * @return  1 if SSL is available, 0 if it is not.
  * @ingroup Ecore_Con_Client_Group
@@ -796,6 +841,7 @@
 #endif
    if (svr->name) free(svr->name);
    if (svr->path) free(svr->path);
+   if (svr->ip) free(svr->ip);
    if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
    free(svr);
 }
@@ -808,6 +854,7 @@
    if (cl->buf) free(cl->buf);
    if (cl->fd >= 0) close(cl->fd);
    if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
+   if (cl->ip) free(cl->ip);
    free(cl);
 }
 
@@ -831,7 +878,9 @@
    if (new_fd >= 0)
      {
        Ecore_Con_Client *cl;
-
+       char buf[64];
+       uint32_t ip;
+       
        if ((svr->client_limit >= 0) && (svr->reject_excess_clients))
          {
             close(new_fd);
@@ -854,6 +903,14 @@
                                                   cl, NULL, NULL);
        ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
        ecore_list_append(svr->clients, cl);
+       ip = incoming.sin_addr.s_addr;
+       snprintf(buf, sizeof(buf),
+                "%i.%i.%i.%i",
+                (ip      ) & 0xff,
+                (ip >> 8 ) & 0xff,
+                (ip >> 16) & 0xff,
+                (ip >> 24) & 0xff);
+       cl->ip = strdup(buf);
          {
             Ecore_Con_Event_Client_Add *e;
             
@@ -925,6 +982,8 @@
    Ecore_Con_Server   *svr;
    struct sockaddr_in  socket_addr;
    int                 curstate = 0;
+   char                buf[64];
+   uint32_t            ip;
 
    svr = data;
 
@@ -955,6 +1014,14 @@
                                                 NULL, NULL);
 
    if (!svr->fd_handler) goto error;
+   ip = socket_addr.sin_addr.s_addr;
+   snprintf(buf, sizeof(buf),
+           "%i.%i.%i.%i",
+           (ip      ) & 0xff,
+           (ip >> 8 ) & 0xff,
+           (ip >> 16) & 0xff,
+           (ip >> 24) & 0xff);
+   svr->ip = strdup(buf);
 
 #if USE_OPENSSL
    if (svr->type & ECORE_CON_USE_SSL)
===================================================================
RCS file: 
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_con/ecore_con_private.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -3 -r1.13 -r1.14
--- ecore_con_private.h 20 Mar 2006 05:53:12 -0000      1.13
+++ ecore_con_private.h 20 Mar 2006 07:45:58 -0000      1.14
@@ -44,6 +44,7 @@
    int               buf_size;
    int               buf_offset;
    unsigned char    *buf;
+   char             *ip;
    int               event_count;
    char              dead : 1;
    char              delete_me : 1;
@@ -71,6 +72,7 @@
    SSL_CTX          *ssl_ctx;
    SSL              *ssl;
 #endif
+   char             *ip;
    char              dead : 1;
    char              created : 1;
    char              connecting : 1;




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to