[prev in list] [next in list] [prev in thread] [next in thread] 

List:       proftpd-committers
Subject:    [ProFTPD-committers] CVS: proftpd/src utf8.c,NONE,1.1 data.c,1.90,1.91 help.c,1.1,1.2 main.c,1.281,1
From:       TJ Saunders <castaglia () users ! sourceforge ! net>
Date:       2006-05-25 16:55:36
Message-ID: E1FjJ7Y-0001TJ-Lx () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/proftp/proftpd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4276/src

Modified Files:
	data.c help.c main.c 
Added Files:
	utf8.c 
Log Message:

Adding UTF8 encoding/decoding functions.  Marking source, preparing it
for use with the gettext utilities.

Part of the work towards making the proftpd source i18n/l10n ready.


--- NEW FILE ---
/*
 * ProFTPD - FTP server daemon
 * Copyright (c) 2006 The ProFTPD Project team
 *
 * 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.
 *
 * As a special exemption, The ProFTPD Project team and other respective
 * copyright holders give permission to link this program with OpenSSL, and
 * distribute the resulting executable, without including the source code for
 * OpenSSL in the source distribution.
 */

/* UTF8 encoding/decoding
 * $Id: utf8.c,v 1.1 2006/05/25 16:55:34 castaglia Exp $
 */

#include "conf.h"

#ifdef PR_USE_NLS

#ifdef HAVE_ICONV_H
# include <iconv.h>
#endif

#ifdef HAVE_LANGINFO_H
# include <langinfo.h>
#endif

static iconv_t decode_conv = (iconv_t) -1;
static iconv_t encode_conv = (iconv_t) -1;

static int utf8_convert(iconv_t conv, char *inbuf, size_t *inbuflen,
    char *outbuf, size_t *outbuflen) {
#ifdef HAVE_ICONV
  char *start = inbuf;

  while (inbuflen > 0) {
    size_t nconv = iconv(conv, &inbuf, inbuflen, &outbuf, outbuflen);

    if (nconv == (size_t) -1) {
      if (errno == EINVAL) {
        memmove(start, inbuf, *inbuflen);
        continue;

      } else
        return -1;
    }

    break;
  }
  return 0;
#else
  errno = ENOSYS;
  return -1;
#endif /* HAVE_ICONV */
}

int utf8_free(void) {
#ifdef HAVE_ICONV
  int res;

  /* Close the iconv handles. */
  res = iconv_close(encode_conv);
  if (res < 0) 
    return -1;

  res = iconv_close(decode_conv);
  if (res < 0)
    return -1;

  return 0;
#else
  errno = ENOSYS;
  return -1;
#endif
}

int utf8_init(void) {
  const char *local_charset;

  /* Look up the current charset.  If there's a problem, default to
   * UCS-2.
   */
#ifdef HAVE_NL_LANGINFO
  local_charset = nl_langinfo(CODESET);
  if (!local_charset)
    local_charset = "UCS-2";
#endif /* HAVE_NL_LANGINFO */

#ifdef HAVE_ICONV
  /* Get the iconv handles. */
  encode_conv = iconv_open(local_charset, "UTF-8");
  if (encode_conv == (iconv_t) -1)
    return -1;
 
  decode_conv = iconv_open("UTF-8", local_charset);
  if (decode_conv == (iconv_t) -1)
    return -1;

  return 0;
#else
  errno = ENOSYS;
  return -1;
#endif /* HAVE_ICONV */
}

char *pr_utf8_decode(pool *p, const char *in, size_t inlen, size_t *outlen) {
  size_t inbuflen, outbuflen;
  char *inbuf, outbuf[PR_TUNABLE_PATH_MAX*2], *res = NULL;

  if (!p || !in || !outlen) {
    errno = EINVAL;
    return NULL;
  }

  if (decode_conv == (iconv_t) -1) {
    errno = EPERM;
    return NULL;
  }

  inbuf = pcalloc(p, inlen);
  memcpy(inbuf, in, inlen);
  inbuflen = inlen;

  outbuflen = sizeof(outbuf);

  if (utf8_convert(decode_conv, inbuf, &inbuflen, outbuf, &outbuflen) < 0)
    return NULL;

  *outlen = sizeof(outbuf) - outbuflen;
  res = pcalloc(p, *outlen);
  memcpy(res, outbuf, *outlen);

  return res;
}

char *pr_utf8_encode(pool *p, const char *in, size_t inlen, size_t *outlen) {
  size_t inbuflen, outbuflen;
  char *inbuf, outbuf[PR_TUNABLE_PATH_MAX*2], *res;

  if (!p || !in || !outlen) {
    errno = EINVAL;
    return NULL;
  }

  if (encode_conv == (iconv_t) -1) {
    errno = EPERM;
    return NULL;
  }

  inbuf = pcalloc(p, inlen);
  memcpy(inbuf, in, inlen);
  inbuflen = inlen;

  outbuflen = sizeof(outbuf);

  if (utf8_convert(encode_conv, inbuf, &inbuflen, outbuf, &outbuflen) < 0)
    return NULL;

  *outlen = sizeof(outbuf) - outbuflen;
  res = pcalloc(p, *outlen);
  memcpy(res, outbuf, *outlen);

  return res;
}

#endif /* PR_USE_NLS */

Index: data.c
===================================================================
RCS file: /cvsroot/proftp/proftpd/src/data.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- data.c	20 Apr 2006 01:46:38 -0000	1.90
+++ data.c	25 May 2006 16:55:34 -0000	1.91
@@ -277,10 +277,10 @@
 
     if (session.xfer.xfer_type != STOR_UNIQUE) {
       if (size)
-        pr_response_send(R_150, "Opening %s mode data connection for %s "
-          "(%" PR_LU " bytes)", MODE_STRING, reason, (pr_off_t) size);
+        pr_response_send(R_150, _("Opening %s mode data connection for %s "
+          "(%" PR_LU " bytes)"), MODE_STRING, reason, (pr_off_t) size);
       else
-        pr_response_send(R_150, "Opening %s mode data connection for %s",
+        pr_response_send(R_150, _("Opening %s mode data connection for %s"),
           MODE_STRING, reason);
 
     } else {
@@ -315,7 +315,7 @@
     pr_log_pri(PR_LOG_ERR, "Error: unable to accept an incoming data "
       "connection (%s)", strerror(c->xerrno));
 
-  pr_response_add_err(R_425, "Unable to build data connection: %s",
+  pr_response_add_err(R_425, _("Unable to build data connection: %s"),
     strerror(session.d->xerrno));
   destroy_pool(session.d->pool);
   session.d = NULL;
@@ -357,7 +357,7 @@
 
   if (pr_inet_connect(session.d->pool, session.d, &session.data_addr,
       session.data_port) == -1) {
-    pr_response_add_err(R_425, "Unable to build data connection: %s",
+    pr_response_add_err(R_425, _("Unable to build data connection: %s"),
       strerror(session.d->xerrno));
     destroy_pool(session.d->pool);
     session.d = NULL;
@@ -377,10 +377,10 @@
 
     if (session.xfer.xfer_type != STOR_UNIQUE) {
       if (size)
-        pr_response_send(R_150, "Opening %s mode data connection for %s "
-          "(%" PR_LU " bytes)", MODE_STRING, reason, (pr_off_t) size);
+        pr_response_send(R_150, _("Opening %s mode data connection for %s "
+          "(%" PR_LU " bytes)"), MODE_STRING, reason, (pr_off_t) size);
       else
-        pr_response_send(R_150, "Opening %s mode data connection for %s",
+        pr_response_send(R_150, _("Opening %s mode data connection for %s"),
           MODE_STRING, reason);
 
     } else {
@@ -413,7 +413,7 @@
     return 0;
   }
 
-  pr_response_add_err(R_425, "Unable to build data connection: %s",
+  pr_response_add_err(R_425, _("Unable to build data connection: %s"),
     strerror(session.d->xerrno));
   destroy_pool(session.d->pool);
   session.d = NULL;
@@ -565,7 +565,7 @@
   session_set_idle();
 
   if (!quiet)
-    pr_response_add(R_226, "Transfer complete.");
+    pr_response_add(R_226, _("Transfer complete"));
 }
 
 /* Note: true_abort may be false in real abort situations, because
@@ -633,13 +633,13 @@
 
     case 0:
       respcode = R_426;
-      msg = "Data connection closed.";
+      msg = _("Data connection closed");
       break;
 
 #ifdef ENXIO
     case ENXIO:
       respcode = R_451;
-      msg = "Unexpected streams hangup.";
+      msg = _("Unexpected streams hangup");
       break;
 
 #endif
@@ -652,7 +652,7 @@
 #endif
 #if defined(EAGAIN) || defined(ENOMEM)
       respcode = R_451;
-      msg = "Insufficient memory or file locked.";
+      msg = _("Insufficient memory or file locked");
       break;
 #endif
 
@@ -758,7 +758,7 @@
 	|| defined(ENOLINK) || defined(ENOLCK) || defined(ENETRESET) \
 	|| defined(ECONNABORTED) || defined(ECONNRESET) || defined(ETIMEDOUT)
       respcode = R_450;
-      msg = "Link to file server lost.";
+      msg = _("Link to file server lost");
       break;
 #endif
     }
@@ -767,7 +767,7 @@
         (msg = strerror(err)) == NULL ) {
 
       if (snprintf(msgbuf, sizeof(msgbuf),
-          "Unknown or out of range errno [%d]", err) > 0)
+          _("Unknown or out of range errno [%d]"), err) > 0)
 	msg = msgbuf;
     }
 
@@ -778,7 +778,7 @@
      * and we don't want to add another to the error queue.
      */
     if (!true_abort)
-      pr_response_add_err(respcode, "Transfer aborted. %s", msg ? msg : "");
+      pr_response_add_err(respcode, _("Transfer aborted. %s"), msg ? msg : "");
   }
 
   if (true_abort)

Index: help.c
===================================================================
RCS file: /cvsroot/proftp/proftpd/src/help.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- help.c	17 Feb 2004 02:16:00 -0000	1.1
+++ help.c	25 May 2006 16:55:34 -0000	1.2
@@ -85,7 +85,7 @@
 
     if (!target) {
       pr_response_add(R_214,
-        "The following commands are recognized (* =>'s unimplemented):");
+        _("The following commands are recognized (* =>'s unimplemented):"));
 
       memset(outa, '\0', sizeof(outa));
 
@@ -120,7 +120,7 @@
         }
       }
 
-      pr_response_add(R_DUP, "Direct comments to %s",
+      pr_response_add(R_DUP, _("Direct comments to %s"),
         cmd->server->ServerAdmin ? cmd->server->ServerAdmin : "ftp-admin");
 
     } else {

Index: main.c
===================================================================
RCS file: /cvsroot/proftp/proftpd/src/main.c,v
retrieving revision 1.281
retrieving revision 1.282
diff -u -r1.281 -r1.282
--- main.c	18 May 2006 15:38:44 -0000	1.281
+++ main.c	25 May 2006 16:55:34 -0000	1.282
@@ -488,7 +488,7 @@
 		   "%V", main_server->ServerName,
                    NULL );
 
-    pr_response_send_async(R_421, "FTP server shutting down - %s", msg);
+    pr_response_send_async(R_421, _("FTP server shutting down - %s"), msg);
 
     session_exit(PR_LOG_NOTICE, msg, 0, NULL);
   }
@@ -626,7 +626,7 @@
   }
 
   if (!c && !success && validate) {
-    pr_response_add_err(R_500, "%s not understood", cmd->argv[0]);
+    pr_response_add_err(R_500, _("%s not understood"), cmd->argv[0]);
     success = -1;
   }
 
@@ -754,9 +754,9 @@
 
   pr_event_generate("core.timeout-idle", NULL);
 
-  pr_response_send_async(R_421, "Idle Timeout (%d seconds): closing control "
-    "connection.", TimeoutIdle);
-  session_exit(PR_LOG_INFO, "FTP session idle timeout, disconnected.", 0, NULL);
+  pr_response_send_async(R_421, _("Idle Timeout (%d seconds): closing control "
+    "connection"), TimeoutIdle);
+  session_exit(PR_LOG_INFO, "FTP session idle timeout, disconnected", 0, NULL);
 
   pr_timer_remove(TIMER_LOGIN, ANY_MODULE);
   pr_timer_remove(TIMER_NOXFER, ANY_MODULE);
@@ -892,7 +892,7 @@
         destroy_pool(cmd->pool);
 
       } else
-	pr_response_send(R_500, "Invalid command: try being more creative");
+	pr_response_send(R_500, _("Invalid command: try being more creative"));
     }
 
     /* release any working memory allocated in inet */
@@ -954,6 +954,10 @@
 
     free_bindings();
 
+#ifdef PR_USE_NLS
+    utf8_free();
+#endif /* PR_USE_NLS */
+
     /* Run through the list of registered rehash callbacks. */
     pr_event_generate("core.restart", NULL);
 
@@ -963,6 +967,11 @@
     init_log();
     init_class();
     init_config();
+
+#ifdef PR_USE_NLS
+    utf8_init();
+#endif /* PR_USE_NLS */
+
     pr_parser_prepare(NULL, NULL);
 
     PRIVS_ROOT
@@ -1316,8 +1325,8 @@
                reason, session.c->remote_name,
                pr_netaddr_get_ipstr(session.c->remote_addr));
 
-      pr_response_send(R_500, "FTP server shut down (%s) -- please try again "
-        "later", reason);
+      pr_response_send(R_500, _("FTP server shut down (%s) -- please try again "
+        "later"), reason);
       exit(0);
     }
   }
@@ -1326,8 +1335,8 @@
    * connected to, drop them.
    */
   if (!main_server) {
-    pr_response_send(R_500, "Sorry, no server available to handle request on "
-      "%s", pr_netaddr_get_dnsstr(conn->local_addr));
+    pr_response_send(R_500, _("Sorry, no server available to handle request on "
+      "%s"), pr_netaddr_get_dnsstr(conn->local_addr));
     exit(0);
   }
 
@@ -2543,6 +2552,12 @@
   printf("    - Largefile support\n");
 #endif /* PR_USE_LARGEFILES */
 
+#ifdef PR_USE_NLS
+  printf("    + NLS support\n");
+#else
+  printf("    - NLS support\n");
+#endif /* PR_USE_NLS */
+
 #ifdef PR_USE_NCURSES
   printf("    + ncurses support\n");
 #else
@@ -2894,6 +2909,10 @@
   init_ctrls();
 #endif /* PR_USE_CTRLS */
 
+#ifdef PR_USE_NLS
+  utf8_init();
+#endif /* PR_USE_NLS */
+
   var_init();
   modules_init();
 



-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
ProFTPD Committers Mailing List
proftpd-committers@proftpd.org
https://lists.sourceforge.net/lists/listinfo/proftp-committers
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic