Ejemplo n.º 1
0
char *
soup_uri_decoded_copy (const char *part, int length, int *decoded_length)
{
    unsigned char *s, *d;
    char *decoded;

    g_return_val_if_fail (part != NULL, NULL);

    decoded = g_strndup (part, length);
    s = d = (unsigned char *)decoded;
    do {
        if (*s == '%') {
            if (!g_ascii_isxdigit (s[1]) ||
                    !g_ascii_isxdigit (s[2])) {
                *d++ = *s;
                continue;
            }
            *d++ = HEXCHAR (s);
            s += 2;
        } else
            *d++ = *s;
    } while (*s++);

    if (decoded_length)
        *decoded_length = d - (unsigned char *)decoded - 1;

    return decoded;
}
Ejemplo n.º 2
0
QByteArray TransformAbstract::fromHex(QByteArray in)
{

    QString invalid;
    QString HEXCHAR("abcdefABCDEF0123456789");
    for (int i = 0; i < in.size(); i++) {
        if (!HEXCHAR.contains(in.at(i))) {
            if (!invalid.contains(in.at(i)))
                invalid.append(in.at(i));
        }
    }

    if (!invalid.isEmpty()) {
        emit error(tr("Invalid character(s) found in the hexadecimal stream: '%1', they will be skipped").arg(invalid),name());
    }

    in.replace(invalid,"");

    if (in.size()%2 != 0) {
        in.chop(1);
        emit error(tr("Invalid size for a hexadecimal stream, skipping the last byte."),name());
    }

    return QByteArray::fromHex(in);
}
Ejemplo n.º 3
0
static char *
uri_normalized_copy (const char *part, int length,
		     const char *unescape_extra)
{
	unsigned char *s, *d, c;
	char *normalized = g_strndup (part, length);
	gboolean need_fixup = FALSE;

	s = d = (unsigned char *)normalized;
	do {
		if (*s == '%') {
			if (!g_ascii_isxdigit (s[1]) ||
			    !g_ascii_isxdigit (s[2])) {
				*d++ = *s;
				continue;
			}

			c = HEXCHAR (s);
			if (soup_char_is_uri_unreserved (c) ||
			    (unescape_extra && strchr (unescape_extra, c))) {
				*d++ = c;
				s += 2;
			} else {
				/* We leave it unchanged. We used to uppercase percent-encoded
				 * triplets but we do not do it any more as RFC3986 Section 6.2.2.1
				 * says that they only SHOULD be case normalized.
				 */
				*d++ = *s++;
				*d++ = *s++;
				*d++ = *s;
			}
		} else {
			if (*s == ' ')
				need_fixup = TRUE;
			*d++ = *s;
		}
	} while (*s++);

	if (need_fixup) {
		GString *fixed;
		char *sp, *p;

		fixed = g_string_new (NULL);
		p = normalized;
		while ((sp = strchr (p, ' '))) {
			g_string_append_len (fixed, p, sp - p);
			g_string_append (fixed, "%20");
			p = sp + 1;
		}
		g_string_append (fixed, p);
		g_free (normalized);
		normalized = g_string_free (fixed, FALSE);
	}

	return normalized;
}
Ejemplo n.º 4
0
static char *
uri_normalized_copy (const char *part, int length,
		     const char *unescape_extra, gboolean fixup)
{
	unsigned char *s, *d, c;
	char *normalized = g_strndup (part, length);
	gboolean need_fixup = FALSE;

	s = d = (unsigned char *)normalized;
	do {
		if (*s == '%') {
			if (!g_ascii_isxdigit (s[1]) ||
			    !g_ascii_isxdigit (s[2])) {
				g_free (normalized);
				return NULL;
			}

			c = HEXCHAR (s);
			if (uri_encoded_char[c] == SOUP_URI_UNRESERVED ||
			    (unescape_extra && strchr (unescape_extra, c))) {
				*d++ = c;
				s += 2;
			} else {
				*d++ = *s++;
				*d++ = g_ascii_toupper (*s++);
				*d++ = g_ascii_toupper (*s);
			}
		} else {
			if (*s == ' ')
				need_fixup = TRUE;
			*d++ = *s;
		}
	} while (*s++);

	if (fixup && need_fixup) {
		char *tmp, *sp;
		/* This code is lame, but so are people who put
		 * unencoded spaces in URLs!
		 */
		while ((sp = strchr (normalized, ' '))) {
			tmp = g_strdup_printf ("%.*s%%20%s",
					       (int)(sp - normalized),
					       normalized, sp + 1);
			g_free (normalized);
			normalized = tmp;
		};
	}

	return normalized;
}
Ejemplo n.º 5
0
Archivo: digest.c Proyecto: cktan/tool2
void
cram_md5_digest (const char *challenge,
		 size_t challengelen,
		 const char *secret,
		 size_t secretlen, char response[CRAM_MD5_DIGEST_LEN])
{
  char hash[GC_MD5_DIGEST_SIZE];
  size_t i;

  gc_hmac_md5 (secret, secretlen ? secretlen : strlen (secret),
	       challenge, challengelen ? challengelen : strlen (challenge),
	       hash);

  for (i = 0; i < GC_MD5_DIGEST_SIZE; i++)
    {
      *response++ = HEXCHAR (hash[i] >> 4);
      *response++ = HEXCHAR (hash[i]);
    }
}
Ejemplo n.º 6
0
static gboolean
form_decode (char *part)
{
	unsigned char *s, *d;

	s = d = (unsigned char *)part;
	do {
		if (*s == '%') {
			if (!g_ascii_isxdigit (s[1]) ||
			    !g_ascii_isxdigit (s[2]))
				return FALSE;
			*d++ = HEXCHAR (s);
			s += 2;
		} else if (*s == '+')
			*d++ = ' ';
		else
			*d++ = *s;
	} while (*s++);

	return TRUE;
}
Ejemplo n.º 7
0
static char *
uri_decoded_copy (const char *part, int length)
{
	unsigned char *s, *d;
	char *decoded = g_strndup (part, length);

	s = d = (unsigned char *)decoded;
	do {
		if (*s == '%') {
			if (!g_ascii_isxdigit (s[1]) ||
			    !g_ascii_isxdigit (s[2])) {
				*d++ = *s;
				continue;
			}
			*d++ = HEXCHAR (s);
			s += 2;
		} else
			*d++ = *s;
	} while (*s++);

	return decoded;
}
Ejemplo n.º 8
0
static char *
uri_normalized_copy (const char *part, int length,
                     const char *unescape_extra)
{
    unsigned char *s, *d, c;
    char *normalized = g_strndup (part, length);
    gboolean need_fixup = FALSE;

    if (!unescape_extra)
        unescape_extra = "";

    s = d = (unsigned char *)normalized;
    while (*s) {
        if (*s == '%') {
            if (!g_ascii_isxdigit (s[1]) ||
                    !g_ascii_isxdigit (s[2])) {
                *d++ = *s++;
                continue;
            }

            c = HEXCHAR (s);
            if (soup_char_is_uri_unreserved (c) ||
                    (c && strchr (unescape_extra, c))) {
                *d++ = c;
                s += 3;
            } else {
                /* We leave it unchanged. We used to uppercase percent-encoded
                 * triplets but we do not do it any more as RFC3986 Section 6.2.2.1
                 * says that they only SHOULD be case normalized.
                 */
                *d++ = *s++;
                *d++ = *s++;
                *d++ = *s++;
            }
        } else {
            if (!g_ascii_isgraph (*s) &&
                    !strchr (unescape_extra, *s))
                need_fixup = TRUE;
            *d++ = *s++;
        }
    }
    *d = '\0';

    if (need_fixup) {
        GString *fixed;

        fixed = g_string_new (NULL);
        s = (guchar *)normalized;
        while (*s) {
            if (g_ascii_isgraph (*s) ||
                    strchr (unescape_extra, *s))
                g_string_append_c (fixed, *s);
            else
                g_string_append_printf (fixed, "%%%02X", (int)*s);
            s++;
        }
        g_free (normalized);
        normalized = g_string_free (fixed, FALSE);
    }

    return normalized;
}