Exemple #1
0
void pair_array_free(pair_array_t* array)
{
    str_array_free(array->keys, array->count);
    str_array_free(array->vals, array->count);
    free(array->keys);
    free(array->vals);
    array->keys = array->vals = NULL;
    array->count = 0;
}
Exemple #2
0
END_TEST





START_TEST (test_str_array)
{
    str_array * l = str_array_create(3);
    fail_if( l == NULL );

    fail_if( FALSE == str_array_append(l, strdup("abc") ) );
    fail_if( l->len != 1 );

    fail_if( FALSE == str_array_append(l, strdup("foo") ) );
    fail_if( l->len != 2 );

    fail_if( FALSE == str_array_append(l, strdup("bar") ) );
    fail_if( l->len != 3 );

    fail_if( FALSE == str_array_append(l, strdup("zoo") ) );
    fail_if( l->len != 4 );

    fail_if( FALSE == str_array_resize(l, l->cap * 2) );

    str_array_free(l);
}
Exemple #3
0
static void conf_module_exit()
{
    size_t i;

    for (i = 0; i < robot.conf.count; ++i)
    {
        str_free(robot.conf.keys[i]);
        switch (robot.conf.vals[i].type)
        {
        case CONF_VALUE_TYPE_STRING:
            str_free(robot.conf.vals[i].string);
            break;
        case CONF_VALUE_TYPE_ARRAY:
            str_array_free(robot.conf.vals[i].array.array, robot.conf.vals[i].array.count);
            free(robot.conf.vals[i].array.array);
            break;
        default:
            break;
        }
    }
    free(robot.conf.keys);
    free(robot.conf.vals);
    robot.conf.keys = NULL;
    robot.conf.vals = NULL;
    robot.conf.count = 0;
}
Exemple #4
0
static int login_step1(const unsigned char password[MD5_DIGEST_LENGTH << 1])
{
    curl_data_t data_login = empty_curl_data;
    curl_header_t header_login = empty_curl_header;
    str_t number = conf_lookup(&robot.conf, str_from("QQ")).string;
    str_t cookie_str;
    char* url = malloc(sizeof("https://ssl.ptlogin2.qq.com/login?u=&p=&verifycode=&webqq_type=10&remember_uin=1&login2qq=1&aid=1003903&u1=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&h=1&ptredirect=0&ptlang=2052&daid=164&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=6-53-32873&mibao_css=m_webqq&t=4&g=1&js_type=0&js_ver=10077&login_sig=qBpuWCs9dlR9awKKmzdRhV8TZ8MfupdXF6zyHmnGUaEzun0bobwOhMh6m7FQjvWA") + (MD5_DIGEST_LENGTH << 1) + VERIFY_LEN + number.len);
    str_t* login_response = NULL;
    int rc = 1;
    size_t login_response_count = 0;

    url[0] = 0;
    strcpy(url, "https://ssl.ptlogin2.qq.com/login?u=");
    strncat(url, number.ptr, number.len);
    strcat(url, "&p=");
    strncat(url, (char*)password, MD5_DIGEST_LENGTH << 1);
    strcat(url, "&verifycode=");
    strncat(url, robot.verify_code, VERIFY_LEN);
    strcat(url, "&webqq_type=10&remember_uin=1&login2qq=1&aid=1003903&u1=http%3A%2F%2Fweb2.qq.com%2Floginproxy.html%3Flogin2qq%3D1%26webqq_type%3D10&h=1&ptredirect=0&ptlang=2052&daid=164&from_ui=1&pttype=1&dumy=&fp=loginerroralert&action=6-53-32873&mibao_css=m_webqq&t=4&g=1&js_type=0&js_ver=10077&login_sig=qBpuWCs9dlR9awKKmzdRhV8TZ8MfupdXF6zyHmnGUaEzun0bobwOhMh6m7FQjvWA");

    cookie_str = cookie_to_str(&robot.cookie);

    rc = get_request_with_cookie(url, 1, "./pems/ssl.ptlogin2.qq.com.pem", cookie_str.ptr, &data_login, &header_login);
    if (!rc)
    {
        fprintf(stderr, "Call login error!!!!\n");
        goto end;
    }

    merge_cookie_to_robot(&header_login);
    robot.ptwebqq = pair_array_lookup(&robot.cookie, str_from("ptwebqq"));

    login_response = fetch_response(data_login.data, &login_response_count);
    if (strcmp(login_response[4].ptr, "登录成功!") != 0)
    {
        rc = 0;
        goto end;
    }

    rc = login_proxy(login_response[2].ptr);
end:
    curl_data_free(&data_login);
    pair_array_free(&header_login);
    str_free(cookie_str);
    free(url);
    str_array_free(login_response, login_response_count);
    return rc;
}
t_ui	ft_strsplit_list(char const *str, char c, t_list *results)
{
	char	**temp_array;
	char	**it;
	t_ui	i;

	temp_array = ft_strsplit(str, c);
	it = temp_array;
	i = 0;
	while (it && *it)
	{
		list_push_back(results, (void *)ft_strdup(*it));
		++it;
		++i;
	}
	str_array_free(temp_array);
	return (i);
}
Exemple #6
0
/**
 * Run a test in given context and analyze the results.
 *
 * @param t     test to be run
 * @param tc    test context
 */
static void test_context_run_test(Test *t, TestContext *tc)
{
    int in_fd, out_fd, err_fd;
    char out_file[] = "/tmp/stest-stdout-XXXXXX";
    char err_file[] = "/tmp/stest-stderr-XXXXXX";
    int status = 0;
    char **args = NULL, *mem_file = NULL;

    if (!test_context_prepare_outfiles(out_file, &out_fd, err_file, &err_fd)) {
        test_context_skip(tc, t, "can not open temporary files");
        goto out;
    }
    if ((in_fd = test_get_input_fd(t)) < 0) {
        test_context_skip(tc, t, "can not open input file");
        goto out;
    }
    if ((args = test_context_get_args(tc, t)) == NULL) {
        test_context_skip(tc, t, "can not read arguments");
        goto out;
    }

    if (tc->use_valgrind) {
        mem_file = prepare_for_valgrind(&args);
        if (!mem_file) {
            test_context_skip(tc, t, "can not open memory output file");
            goto out;
        }
    }
    execute_test(in_fd, out_fd, err_fd, args);

    wait(&status);

    test_context_analyze_test_run(tc, t, out_file, err_file, mem_file, status);
out:
    str_array_free(args);

    unlink(out_file);
    unlink(err_file);
    if (mem_file) {
        unlink(mem_file);
        free(mem_file);
    }
}
Exemple #7
0
static int want_image(int* want)
{
    curl_data_t data_check = empty_curl_data;
    curl_header_t header_check = empty_curl_header;
    str_t number = conf_lookup(&robot.conf, str_from("QQ")).string;
    char* url = malloc(sizeof("https://ssl.ptlogin2.qq.com/check?uin=&appid=1003903&r=0.14233942252344134") + number.len);
    str_t* check_response = NULL;
    int rc = 1;
    size_t check_response_count = 0;

    url[0] = 0;
    strcpy(url, "https://ssl.ptlogin2.qq.com/check?uin=");
    strncat(url, number.ptr, number.len);
    strcat(url, "&appid=1003903&r=0.14233942252344134");
    rc = get_request(url, 1, "./pems/ssl.ptlogin2.qq.com.pem", &data_check, &header_check);
    if (!rc)
    {
        fprintf(stderr, "Call check error!!!!\n");
        goto end;
    }

    merge_cookie_to_robot(&header_check);

    check_response = fetch_response(data_check.data, &check_response_count);
    if (strcmp(check_response[0].ptr, "0") == 0) *want = 0;
    else if (strcmp(check_response[0].ptr, "2") == 0)
    {
        fprintf(stderr, "Invalid QQ Number!!!!\n");
        goto end;
    }
    else *want = 1;
    memcpy(robot.verify_code, check_response[1].ptr, VERIFY_LEN);
    bits_from_str(check_response[2], robot.bits);

end:
    curl_data_free(&data_check);
    pair_array_free(&header_check);
    free(url);
    str_array_free(check_response, check_response_count);
    return rc;
}
Exemple #8
0
Fichier : node.c Projet : SciTeX/r3
void match_entry_free(match_entry * entry) {
    str_array_free(entry->vars);
    free(entry);
}
Exemple #9
0
static Boolean
search(char *const query)
{
    const config_t *conf = config();

    Boolean resp = True;
    results_not_found = True;

    if (query_len < conf->section_main->min_query_len) {
        return False;
    }

    if (query[0] == ' ')
        return False;

    GQueue *cache = get_cache();

    int current_query_len = 1;
    str_array_t *query_parts = NULL;

    if (conf->section_main->allow_spaces) {
        query_parts = str_array_new(strdup(query), " ");

        if (
            (query_len > 0 && query[query_len - 1] == ' ')
            || query_parts == NULL
        ) {
            resp = False;
            goto free_query_parts;
        }

        current_query_len = query_parts->length;
    }

    g_list_free(results);
    results = NULL;

    for (int i = 0; i < g_queue_get_length(cache); i++) {
        char *path = g_queue_peek_nth(cache, i);
        Boolean found = True;

        if (current_query_len == 1) {
            char *name = g_path_get_basename(path);

            if (strcasestr(name, query) != NULL) {
                results = g_list_prepend(results, path);
            }

            free(name);
        } else if (current_query_len > 1) {
            for (int i = 0; i < current_query_len; i++) {
                if (strcmp(query_parts->data[i], " ") == 0)
                    continue;

                char *name = g_path_get_basename(
                    path
                );

                if (strstr(name, query_parts->data[i]) == NULL) {
                    found = False;
                    goto finish;
                }

            finish:
                free(name);

                if (! found)
                    break;
            }

            if (found)
                results = g_list_prepend(results, path);
        }
    }

    results_not_found = (g_list_length(results) > 0 ? False : True);

    recent_apps_on_top();

free_query_parts:
    str_array_free(query_parts);

    return resp;
}