added url_escape from curl

SVN revision: 48223
This commit is contained in:
Hannes Janetzek 2010-04-22 18:11:20 +00:00
parent e80438d801
commit 9b861c788b
2 changed files with 120 additions and 49 deletions

View File

@ -420,6 +420,7 @@ EAPI Evas_Object *evry_icon_theme_get(const char *icon, Evas *e);
EAPI int evry_fuzzy_match(const char *str, const char *match);
EAPI Eina_List *evry_fuzzy_match_sort(Eina_List *items);
EAPI int evry_util_exec_app(const Evry_Item *it_app, const Evry_Item *it_file);
EAPI char *evry_util_url_escape(const char *string, int inlength);
EAPI char *evry_util_unescape(const char *string, int length);
EAPI void evry_util_file_detail_set(Evry_Item_File *file);
EAPI Eina_Bool evry_util_module_config_check(const char *module_name, int conf, int epoch, int version);

View File

@ -447,6 +447,61 @@ evry_util_exec_app(const Evry_Item *it_app, const Evry_Item *it_file)
return 1;
}
static int
_conf_timer(void *data)
{
/* e_util_dialog_internal(title, */
e_util_dialog_internal(_("Configuration Updated"), data);
return 0;
}
EAPI Eina_Bool
evry_util_module_config_check(const char *module_name, int conf, int epoch, int version)
{
if ((conf >> 16) < epoch)
{
char *too_old =
_("%s Configuration data needed "
"upgrading. Your old configuration<br> has been"
" wiped and a new set of defaults initialized. "
"This<br>will happen regularly during "
"development, so don't report a<br>bug. "
"This simply means the module needs "
"new configuration<br>data by default for "
"usable functionality that your old<br>"
"configuration simply lacks. This new set of "
"defaults will fix<br>that by adding it in. "
"You can re-configure things now to your<br>"
"liking. Sorry for the inconvenience.<br>");
char buf[4096];
snprintf(buf, sizeof(buf), too_old, module_name);
ecore_timer_add(1.0, _conf_timer, buf);
return EINA_FALSE;
}
else if (conf > version)
{
char *too_new =
_("Your %s Module configuration is NEWER "
"than the module version. This is "
"very<br>strange. This should not happen unless"
" you downgraded<br>the module or "
"copied the configuration from a place where"
"<br>a newer version of the module "
"was running. This is bad and<br>as a "
"precaution your configuration has been now "
"restored to<br>defaults. Sorry for the "
"inconvenience.<br>");
char buf[4096];
snprintf(buf, sizeof(buf), too_new, module_name);
ecore_timer_add(1.0, _conf_timer, buf);
return EINA_FALSE;
}
return EINA_TRUE;
}
/* taken from curl:
*
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et
@ -499,59 +554,74 @@ evry_util_unescape(const char *string, int length)
#undef ISXDIGIT
static int
_conf_timer(void *data)
static Eina_Bool
_isalnum(unsigned char in)
{
/* e_util_dialog_internal(title, */
e_util_dialog_internal(_("Configuration Updated"), data);
return 0;
switch (in) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
case 'K': case 'L': case 'M': case 'N': case 'O':
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
return EINA_TRUE;
default:
break;
}
return EINA_FALSE;
}
EAPI Eina_Bool
evry_util_module_config_check(const char *module_name, int conf, int epoch, int version)
EAPI char *
evry_util_url_escape(const char *string, int inlength)
{
if ((conf >> 16) < epoch)
{
char *too_old =
_("%s Configuration data needed "
"upgrading. Your old configuration<br> has been"
" wiped and a new set of defaults initialized. "
"This<br>will happen regularly during "
"development, so don't report a<br>bug. "
"This simply means the module needs "
"new configuration<br>data by default for "
"usable functionality that your old<br>"
"configuration simply lacks. This new set of "
"defaults will fix<br>that by adding it in. "
"You can re-configure things now to your<br>"
"liking. Sorry for the inconvenience.<br>");
size_t alloc = (inlength?(size_t)inlength:strlen(string))+1;
char *ns;
char *testing_ptr = NULL;
unsigned char in; /* we need to treat the characters unsigned */
size_t newlen = alloc;
int strindex=0;
size_t length;
char buf[4096];
snprintf(buf, sizeof(buf), too_old, module_name);
ecore_timer_add(1.0, _conf_timer, buf);
return EINA_FALSE;
}
else if (conf > version)
{
char *too_new =
_("Your %s Module configuration is NEWER "
"than the module version. This is "
"very<br>strange. This should not happen unless"
" you downgraded<br>the module or "
"copied the configuration from a place where"
"<br>a newer version of the module "
"was running. This is bad and<br>as a "
"precaution your configuration has been now "
"restored to<br>defaults. Sorry for the "
"inconvenience.<br>");
ns = malloc(alloc);
if(!ns)
return NULL;
char buf[4096];
snprintf(buf, sizeof(buf), too_new, module_name);
ecore_timer_add(1.0, _conf_timer, buf);
return EINA_FALSE;
}
length = alloc-1;
while(length--) {
in = *string;
return EINA_TRUE;
if (_isalnum(in)) {
/* just copy this */
ns[strindex++]=in;
}
else {
/* encode it */
newlen += 2; /* the size grows with two, since this'll become a %XX */
if(newlen > alloc) {
alloc *= 2;
testing_ptr = realloc(ns, alloc);
if(!testing_ptr) {
free( ns );
return NULL;
}
else {
ns = testing_ptr;
}
}
snprintf(&ns[strindex], 4, "%%%02X", in);
strindex+=3;
}
string++;
}
ns[strindex]=0; /* terminate it */
return ns;
}