Advertisement
Guest User

parse_url2.c

a guest
Nov 25th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <curl/curl.h>
  5. #include <alloca.h>  // some times i think, use alloca is a good idea...
  6.  
  7.  
  8. static char endref[] = "\"'";
  9.  
  10. void parse_href(char *p, char *tmp){
  11.     size_t len;
  12.    
  13.     if(!p)
  14.         return;
  15.    
  16.     p += 4;
  17.     //descarta todos os espaços até o próximo caracteres
  18.     while(*p == ' ')
  19.         p++;
  20.    
  21.     //verifica se o próximo caractere é '='
  22.     if(*p != '=')
  23.         return;
  24.    
  25.    
  26.     p++;
  27.     //descarta todos os espaços até o próximo caracteres
  28.     while(*p == ' ')
  29.         p++;
  30.    
  31.     //verifica se o próximo caractere é '"'
  32.     if(*p == '"'){     
  33.         p++;
  34.         len = (int)(strstr(p, "\"") - p);
  35.         memcpy(tmp, p, len);
  36.     }
  37.    
  38.     else if(*p == '\''){
  39.         p++;
  40.         len = (int)(strstr(p, "'") - p);
  41.         memcpy(tmp, p, len);
  42.     }
  43. }
  44.  
  45. void extract_urls(char *inputBuffer, char *domain){
  46.     char *s = NULL;
  47.     char *ptr = inputBuffer;
  48.     char *tmp = ptr;
  49.    
  50.     size_t slen = strlen(inputBuffer);
  51.     s = malloc(sizeof(char) * slen);
  52.     if(!s){
  53.         fprintf(stderr, "malloc falhou\n");
  54.         exit(1);
  55.     }
  56.    
  57.     //identifica todos href
  58.     while((tmp = strstr(ptr, "href"))){
  59.         bzero(s, slen);
  60.        
  61.         parse_href(tmp, s);
  62.         printf("href = %s\n", s);
  63.         ptr = tmp + 4;
  64.     }
  65.    
  66.    
  67.     free(tmp);
  68. }
  69.  
  70.  
  71. int main(void){
  72.     char *response="<a href =\"/test/algo\" >   \n<a href = \"/abra/cadabra/site.php\"> \n < href='teste/5003'> \n <form action = 'kaboom.php?remove'> ";
  73.    
  74.     extract_urls(response,"http://www.vulcan.com.br");
  75.    
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement