void string_array_copy(string_array_t *dst, char **src, int srclen) { int i; /* Use string_array_add(), to make copies of strings. */ for (i = 0; i < srclen; i++) string_array_add(dst, src[i]); }
string_array *mk_broken_string_using_seppers(const char *string, const char *seppers) { string_array *sa = mk_string_array(0); int i = 0; while ( string != NULL && string[i] != '\0' ) { int j = 0; while ( is_sepper(string[i],seppers) ) i += 1; if ( string[i] != '\0' ) { int part_size,backslashcount = 0; char *part,stopchar = ' '; int k; while ( string[i+j] != '\0' ) { if(stopchar == ' ') { if(is_sepper(string[i+j],seppers)) break; else if((string[i+j]=='\"') && !(backslashcount%2)) stopchar = '\"'; } else if(stopchar == '\"') { /* bug fix? this used to say stopchar = '\n' which made it put the whole rest of the line into one string once it had seen a double quote. Now it only includes up to the next double quote. 8/24/99 JGS */ if((string[i+j] == '\"') && !(backslashcount %2)) stopchar = ' '; } if (string[i+j] == '\\') backslashcount++; else backslashcount=0; j++; } part_size = j+1; part = AM_MALLOC_ARRAY(char,part_size); for ( k = 0 ; k < j ; k++ ) part[k] = string[i+k]; if ( k != part_size-1 ) my_error("oaibxwibxpwibx"); part[k] = '\0'; string_array_add(sa,part); AM_FREE_ARRAY(part,char,part_size); } i = i+j; }
/** * @brief search for accounts in ettercap output. * @returns a ::message on success, NULL on error. */ message *parse_ettercap_account(char *line) { regmatch_t pmatch[6]; struct ettercap_account_info *account_info; message *m; int array_start; if(regexec(&account_pattern, line, 6, pmatch, 0)) return NULL; m = create_message(0, sizeof(struct ettercap_account_info), 0); if(!m) { print(ERROR, "cannot create messages"); return NULL; } // terminate lines for parsing single parts *(line + pmatch[1].rm_eo) = '\0'; *(line + pmatch[2].rm_eo) = '\0'; *(line + pmatch[3].rm_eo) = '\0'; *(line + pmatch[4].rm_eo) = '\0'; array_start = offsetof(struct ettercap_account_info, data); account_info = (struct ettercap_account_info *) m->data; account_info->ettercap_action = ACCOUNT; account_info->address = inet_addr(line + pmatch[2].rm_so); if(string_array_add(m, array_start, line + pmatch[1].rm_so) || string_array_add(m, array_start, line + pmatch[3].rm_so) || string_array_add(m, array_start, line + pmatch[4].rm_so)) { print( ERROR, "cannot add string to message"); free_message(m); return NULL; } return m; }