Back to index

php5  5.3.10
Functions
php_uuencode.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 PHP_FUNCTION (convert_uudecode)
 PHP_FUNCTION (convert_uuencode)
PHPAPI int php_uudecode (char *src, int src_len, char **dest)
PHPAPI int php_uuencode (char *src, int src_len, char **dest)

Function Documentation

PHP_FUNCTION ( convert_uudecode  )

Definition at line 207 of file uuencode.c.

{
       char *src, *dst;
       int src_len, dst_len;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &src, &src_len) == FAILURE || src_len < 1) {
              RETURN_FALSE;
       }

       dst_len = php_uudecode(src, src_len, &dst);
       if (dst_len < 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "The given parameter is not a valid uuencoded string");
              RETURN_FALSE;
       }

       RETURN_STRINGL(dst, dst_len, 0);
}

Here is the call graph for this function:

PHP_FUNCTION ( convert_uuencode  )

Definition at line 190 of file uuencode.c.

{
       char *src, *dst;
       int src_len, dst_len;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &src, &src_len) == FAILURE || src_len < 1) {
              RETURN_FALSE;
       }

       dst_len = php_uuencode(src, src_len, &dst);

       RETURN_STRINGL(dst, dst_len, 0);
}

Here is the call graph for this function:

PHPAPI int php_uudecode ( char *  src,
int  src_len,
char **  dest 
)

Definition at line 127 of file uuencode.c.

{
       int len, total_len=0;
       char *s, *e, *p, *ee;

       p = *dest = safe_emalloc((size_t) ceil(src_len * 0.75), 1, 1);
       s = src;
       e = src + src_len;

       while (s < e) {
              if ((len = PHP_UU_DEC(*s++)) <= 0) {
                     break;
              }
              /* sanity check */
              if (len > src_len) {
                     goto err;
              }

              total_len += len;

              ee = s + (len == 45 ? 60 : (int) floor(len * 1.33));
              /* sanity check */
              if (ee > e) {
                     goto err;
              }

              while (s < ee) {
                     *p++ = PHP_UU_DEC(*s) << 2 | PHP_UU_DEC(*(s + 1)) >> 4;
                     *p++ = PHP_UU_DEC(*(s + 1)) << 4 | PHP_UU_DEC(*(s + 2)) >> 2;
                     *p++ = PHP_UU_DEC(*(s + 2)) << 6 | PHP_UU_DEC(*(s + 3));
                     s += 4;
              }

              if (len < 45) {
                     break;
              }

              /* skip \n */
              s++;
       }

       if ((len = total_len > (p - *dest))) {
              *p++ = PHP_UU_DEC(*s) << 2 | PHP_UU_DEC(*(s + 1)) >> 4;
              if (len > 1) {
                     *p++ = PHP_UU_DEC(*(s + 1)) << 4 | PHP_UU_DEC(*(s + 2)) >> 2;
                     if (len > 2) {
                            *p++ = PHP_UU_DEC(*(s + 2)) << 6 | PHP_UU_DEC(*(s + 3));
                     }
              }
       }

       *(*dest + total_len) = '\0';

       return total_len;

err:
       efree(*dest);
       return -1;
}

Here is the caller graph for this function:

PHPAPI int php_uuencode ( char *  src,
int  src_len,
char **  dest 
)

Definition at line 68 of file uuencode.c.

{
       int len = 45;
       char *p, *s, *e, *ee;

       /* encoded length is ~ 38% greater then the original */
       p = *dest = safe_emalloc((size_t) ceil(src_len * 1.38), 1, 46);
       s = src;
       e = src + src_len;

       while ((s + 3) < e) {
              ee = s + len;
              if (ee > e) {
                     ee = e;
                     len = ee - s;
                     if (len % 3) {
                            ee = s + (int) (floor(len / 3) * 3);
                     }
              }
              *p++ = PHP_UU_ENC(len);

              while (s < ee) {
                     *p++ = PHP_UU_ENC(*s >> 2);
                     *p++ = PHP_UU_ENC_C2(s);
                     *p++ = PHP_UU_ENC_C3(s);
                     *p++ = PHP_UU_ENC(*(s + 2) & 077);

                     s += 3;
              }

              if (len == 45) {
                     *p++ = '\n';
              }
       }

       if (s < e) {
              if (len == 45) {
                     *p++ = PHP_UU_ENC(e - s);
                     len = 0;
              }

              *p++ = PHP_UU_ENC(*s >> 2);
              *p++ = PHP_UU_ENC_C2(s);
              *p++ = ((e - s) > 1) ? PHP_UU_ENC_C3(s) : PHP_UU_ENC('\0');
              *p++ = ((e - s) > 2) ? PHP_UU_ENC(*(s + 2) & 077) : PHP_UU_ENC('\0');
       }

       if (len < 45) {
              *p++ = '\n';
       }

       *p++ = PHP_UU_ENC('\0');
       *p++ = '\n';
       *p = '\0';

       return (p - *dest);
}

Here is the caller graph for this function: