Back to index

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

Go to the source code of this file.

Functions

PHPAPI ulong mysqlnd_cset_escape_quotes (const MYSQLND_CHARSET *const charset, char *newstr, const char *escapestr, size_t escapestr_len TSRMLS_DC)
PHPAPI ulong mysqlnd_cset_escape_slashes (const MYSQLND_CHARSET *const cset, char *newstr, const char *escapestr, size_t escapestr_len TSRMLS_DC)

Function Documentation

PHPAPI ulong mysqlnd_cset_escape_quotes ( const MYSQLND_CHARSET *const  charset,
char *  newstr,
const char *  escapestr,
size_t escapestr_len  TSRMLS_DC 
)

Definition at line 648 of file mysqlnd_charset.c.

{
       const char    *newstr_s = newstr;
       const char    *newstr_e = newstr + 2 * escapestr_len;
       const char    *end = escapestr + escapestr_len;
       zend_bool     escape_overflow = FALSE;

       DBG_ENTER("mysqlnd_cset_escape_quotes");

       for (;escapestr < end; escapestr++) {
              unsigned int len = 0;
              /* check unicode characters */

              if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) {

                     /* check possible overflow */
                     if ((newstr + len) > newstr_e) {
                            escape_overflow = TRUE;
                            break;
                     }
                     /* copy mb char without escaping it */
                     while (len--) {
                            *newstr++ = *escapestr++;
                     }
                     escapestr--;
                     continue;
              }
              if (*escapestr == '\'') {
                     if (newstr + 2 > newstr_e) {
                            escape_overflow = TRUE;
                            break;
                     }
                     *newstr++ = '\'';
                     *newstr++ = '\'';
              } else {
                     if (newstr + 1 > newstr_e) {
                            escape_overflow = TRUE;
                            break;
                     }
                     *newstr++ = *escapestr;
              }
       }
       *newstr = '\0';

       if (escape_overflow) {
              DBG_RETURN((ulong)~0);
       }
       DBG_RETURN((ulong)(newstr - newstr_s));
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI ulong mysqlnd_cset_escape_slashes ( const MYSQLND_CHARSET *const  cset,
char *  newstr,
const char *  escapestr,
size_t escapestr_len  TSRMLS_DC 
)

Definition at line 702 of file mysqlnd_charset.c.

{
       const char    *newstr_s = newstr;
       const char    *newstr_e = newstr + 2 * escapestr_len;
       const char    *end = escapestr + escapestr_len;
       zend_bool     escape_overflow = FALSE;

       DBG_ENTER("mysqlnd_cset_escape_slashes");
       DBG_INF_FMT("charset=%s", cset->name);

       for (;escapestr < end; escapestr++) {
              char esc = '\0';
              unsigned int len = 0;

              /* check unicode characters */
              if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) {
                     /* check possible overflow */
                     if ((newstr + len) > newstr_e) {
                            escape_overflow = TRUE;
                            break;
                     }
                     /* copy mb char without escaping it */
                     while (len--) {
                            *newstr++ = *escapestr++;
                     }
                     escapestr--;
                     continue;
              }
              if (cset->char_maxlen > 1 && cset->mb_charlen(*escapestr) > 1) {
                     esc = *escapestr;
              } else {
                     switch (*escapestr) {
                            case 0:
                                   esc = '0';
                                   break;
                            case '\n':
                                   esc = 'n';
                                   break;
                            case '\r':
                                   esc = 'r';
                                   break;
                            case '\\':
                            case '\'':
                            case '"':
                                   esc = *escapestr;
                                   break;
                            case '\032':
                                   esc = 'Z';
                                   break;
                     }
              }
              if (esc) {
                     if (newstr + 2 > newstr_e) {
                            escape_overflow = TRUE;
                            break;
                     }
                     /* copy escaped character */
                     *newstr++ = '\\';
                     *newstr++ = esc;
              } else {
                     if (newstr + 1 > newstr_e) {
                            escape_overflow = TRUE;
                            break;
                     }
                     /* copy non escaped character */
                     *newstr++ = *escapestr;
              }
       }
       *newstr = '\0';

       if (escape_overflow) {
              DBG_RETURN((ulong)~0);
       }
       DBG_RETURN((ulong)(newstr - newstr_s));
}

Here is the call graph for this function:

Here is the caller graph for this function: