예제 #1
0
파일: http.c 프로젝트: jing-git/rt-n56u
/* Set default TCP specififc params */
static int local_set_params(http_t *client)
{
	int timeout = 0;
	int port;

	http_get_remote_timeout(client, &timeout);
	if (timeout == 0)
		http_set_remote_timeout(client, HTTP_DEFAULT_TIMEOUT);

	http_get_port(client, &port);
	if (port == 0)
		http_set_port(client, HTTP_DEFAULT_PORT);

	return 0;
}
예제 #2
0
파일: freedns.c 프로젝트: dbruenig/inadyn
static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias)
{
	int           i, rc = 0;
	http_t        client;
	http_trans_t  trans;
	char         *buf, *tmp, *line, *hash = NULL;
	char          host[256], updateurl[256];
	char          buffer[256];
	char          digeststr[SHA1_DIGEST_BYTES * 2 + 1];
	unsigned char digestbuf[SHA1_DIGEST_BYTES];

	do {
		TRY(http_construct(&client));

		http_set_port(&client, info->server_name.port);
		http_set_remote_name(&client, info->server_name.name);
		http_set_bind_iface(&client, ctx->bind_interface);

		client.ssl_enabled = info->ssl_enabled;
		if (client.ssl_enabled)	/* XXX: Fix this better, possibly in http_init() */
			client.tcp.ip.port = 443;

		TRY(http_init(&client, "Sending update URL query"));

		snprintf(buffer, sizeof(buffer), "%s|%s",
			 info->creds.username, info->creds.password);
		sha1((unsigned char *)buffer, strlen(buffer), digestbuf);
		for (i = 0; i < SHA1_DIGEST_BYTES; i++)
			sprintf(&digeststr[i * 2], "%02x", digestbuf[i]);

		snprintf(buffer, sizeof(buffer), "/api/?action=getdyndns&sha=%s", digeststr);
		trans.req_len     = snprintf(ctx->request_buf, ctx->request_buflen,
					     GENERIC_HTTP_REQUEST, buffer, info->server_name.name);
		trans.p_req       = ctx->request_buf;
		trans.p_rsp       = ctx->work_buf;
		trans.max_rsp_len = ctx->work_buflen - 1;	/* Save place for a \0 at the end */

		rc  = http_transaction(&client, &trans);
		rc |= http_exit(&client);

		http_destruct(&client, 1);

		if (rc)
			break;

		TRY(http_status_valid(trans.status));

		tmp = buf = strdup(trans.p_rsp_body);
		for (line = strsep(&tmp, "\n"); line; line = strsep(&tmp, "\n")) {
			int num;

			num = sscanf(line, "%255[^|\r\n]|%*[^|\r\n]|%255[^|\r\n]", host, updateurl);
			if (*line && num == 2 && !strcmp(host, alias->name)) {
				hash = strstr(updateurl, "?");
				break;
			}
		}
		free(buf);

		if (!hash)
			rc = RC_DYNDNS_RSP_NOTOK;
		else
			hash++;
	}
	while (0);

	if (rc) {
		logit(LOG_INFO, "Update URL query failed");
		return 0;
	}

	return snprintf(ctx->request_buf, ctx->request_buflen,
		       FREEDNS_UPDATE_IP_REQUEST,
		       info->server_url,
		       hash, alias->address,
		       info->server_name.name);
}