00001
00002
00003
00004
00005
00006 #include <stdlib.h>
00007 #include <stdio.h>
00008 #include <strings.h>
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 int get_domain (char *address, char *login, char *domain)
00024 {
00025 char *pt, c;
00026
00027 pt = strstr(address, "@");
00028 if (pt == NULL) { return 1; }
00029
00030 c = *pt;
00031
00032 strcpy (domain, pt+1);
00033
00034 *pt = 0;
00035
00036 strcpy (login, address);
00037
00038 *pt = c;
00039
00040 return 0;
00041 }
00042
00043
00044
00045
00046
00047
00048
00049
00050 char* url_escape(char *string)
00051 {
00052 int alloc;
00053 char *ns;
00054 unsigned char in;
00055 int newlen;
00056 int index;
00057
00058
00059
00060 newlen = alloc = strlen(string)+1;
00061 ns = (char*) malloc((size_t)alloc);
00062 if (ns == NULL) { return NULL; }
00063 index = 0;
00064
00065 while((*string) != 0)
00066 {
00067 in = *string;
00068 if(' ' == in) { ns[index++] = '+'; }
00069 else if(!(in >= 'a' && in <= 'z') &&
00070 !(in >= 'A' && in <= 'Z') &&
00071 !(in >= '0' && in <= '9'))
00072 {
00073
00074
00075
00076
00077
00078
00079 newlen += 2;
00080
00081 if(newlen > alloc)
00082 {
00083 alloc *= 2;
00084 ns = realloc(ns, alloc);
00085 if (ns == NULL) { return NULL; }
00086 }
00087
00088 sprintf(&ns[index], "%%%02X", in);
00089 index+=3;
00090 }
00091 else
00092 { ns[index++]=in; }
00093
00094 string++;
00095 }
00096
00097 ns[index]=0;
00098 return ns;
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 char* url_unescape(char *string, int length)
00113 {
00114 int alloc;
00115 char *ns;
00116 unsigned char in;
00117 int index;
00118 int hex;
00119 char querypart;
00120
00121
00122
00123 alloc = (length?length:strlen(string))+1;
00124 ns = malloc(alloc);
00125 if (ns == NULL) { return NULL; }
00126 index = 0;
00127 querypart = 0;
00128
00129 while(--alloc > 0)
00130 {
00131 in = *string;
00132 if ((querypart == 1) && ('+' == in)) { in = ' '; }
00133 else if ((querypart == 0) && ('?' == in))
00134 {
00135
00136 querypart = 1;
00137 }
00138 else if('%' == in)
00139 {
00140
00141 if(sscanf(string+1, "%02X", &hex))
00142 {
00143 in = hex;
00144 string+=2;
00145 alloc-=2;
00146 }
00147 }
00148
00149 ns[index++] = in;
00150 string++;
00151 }
00152
00153 ns[index]=0;
00154 return ns;
00155 }
00156
00157
00158
00159
00160
00161