Deleted Added
full compact
http_client.c (281806) http_client.c (289549)
1/*
2 * http_client - HTTP client
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8

--- 71 unchanged lines hidden (view full) ---

80 }
81}
82
83
84static void http_client_tx_ready(int sock, void *eloop_ctx, void *sock_ctx)
85{
86 struct http_client *c = eloop_ctx;
87 int res;
1/*
2 * http_client - HTTP client
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8

--- 71 unchanged lines hidden (view full) ---

80 }
81}
82
83
84static void http_client_tx_ready(int sock, void *eloop_ctx, void *sock_ctx)
85{
86 struct http_client *c = eloop_ctx;
87 int res;
88 size_t send_len;
88
89
90 send_len = wpabuf_len(c->req) - c->req_pos;
89 wpa_printf(MSG_DEBUG, "HTTP: Send client request to %s:%d (%lu of %lu "
90 "bytes remaining)",
91 inet_ntoa(c->dst.sin_addr), ntohs(c->dst.sin_port),
92 (unsigned long) wpabuf_len(c->req),
91 wpa_printf(MSG_DEBUG, "HTTP: Send client request to %s:%d (%lu of %lu "
92 "bytes remaining)",
93 inet_ntoa(c->dst.sin_addr), ntohs(c->dst.sin_port),
94 (unsigned long) wpabuf_len(c->req),
93 (unsigned long) wpabuf_len(c->req) - c->req_pos);
95 (unsigned long) send_len);
94
96
95 res = send(c->sd, wpabuf_head_u8(c->req) + c->req_pos,
96 wpabuf_len(c->req) - c->req_pos, 0);
97 res = send(c->sd, wpabuf_head_u8(c->req) + c->req_pos, send_len, 0);
97 if (res < 0) {
98 wpa_printf(MSG_DEBUG, "HTTP: Failed to send buffer: %s",
99 strerror(errno));
100 eloop_unregister_sock(c->sd, EVENT_TYPE_WRITE);
101 c->cb(c->cb_ctx, c, HTTP_CLIENT_FAILED);
102 return;
103 }
104
98 if (res < 0) {
99 wpa_printf(MSG_DEBUG, "HTTP: Failed to send buffer: %s",
100 strerror(errno));
101 eloop_unregister_sock(c->sd, EVENT_TYPE_WRITE);
102 c->cb(c->cb_ctx, c, HTTP_CLIENT_FAILED);
103 return;
104 }
105
105 if ((size_t) res < wpabuf_len(c->req) - c->req_pos) {
106 if ((size_t) res < send_len) {
106 wpa_printf(MSG_DEBUG, "HTTP: Sent %d of %lu bytes; %lu bytes "
107 "remaining",
108 res, (unsigned long) wpabuf_len(c->req),
107 wpa_printf(MSG_DEBUG, "HTTP: Sent %d of %lu bytes; %lu bytes "
108 "remaining",
109 res, (unsigned long) wpabuf_len(c->req),
109 (unsigned long) wpabuf_len(c->req) - c->req_pos -
110 res);
110 (unsigned long) send_len - res);
111 c->req_pos += res;
112 return;
113 }
114
115 wpa_printf(MSG_DEBUG, "HTTP: Full client request sent to %s:%d",
116 inet_ntoa(c->dst.sin_addr), ntohs(c->dst.sin_port));
117 eloop_unregister_sock(c->sd, EVENT_TYPE_WRITE);
118 wpabuf_free(c->req);

--- 22 unchanged lines hidden (view full) ---

141 return NULL;
142 c->sd = -1;
143 c->dst = *dst;
144 c->max_response = max_response;
145 c->cb = cb;
146 c->cb_ctx = cb_ctx;
147
148 c->sd = socket(AF_INET, SOCK_STREAM, 0);
111 c->req_pos += res;
112 return;
113 }
114
115 wpa_printf(MSG_DEBUG, "HTTP: Full client request sent to %s:%d",
116 inet_ntoa(c->dst.sin_addr), ntohs(c->dst.sin_port));
117 eloop_unregister_sock(c->sd, EVENT_TYPE_WRITE);
118 wpabuf_free(c->req);

--- 22 unchanged lines hidden (view full) ---

141 return NULL;
142 c->sd = -1;
143 c->dst = *dst;
144 c->max_response = max_response;
145 c->cb = cb;
146 c->cb_ctx = cb_ctx;
147
148 c->sd = socket(AF_INET, SOCK_STREAM, 0);
149 if (c->sd < 0) {
150 http_client_free(c);
151 return NULL;
152 }
149 if (c->sd < 0)
150 goto fail;
153
154 if (fcntl(c->sd, F_SETFL, O_NONBLOCK) != 0) {
155 wpa_printf(MSG_DEBUG, "HTTP: fnctl(O_NONBLOCK) failed: %s",
156 strerror(errno));
151
152 if (fcntl(c->sd, F_SETFL, O_NONBLOCK) != 0) {
153 wpa_printf(MSG_DEBUG, "HTTP: fnctl(O_NONBLOCK) failed: %s",
154 strerror(errno));
157 http_client_free(c);
158 return NULL;
155 goto fail;
159 }
160
161 if (connect(c->sd, (struct sockaddr *) dst, sizeof(*dst))) {
162 if (errno != EINPROGRESS) {
163 wpa_printf(MSG_DEBUG, "HTTP: Failed to connect: %s",
164 strerror(errno));
156 }
157
158 if (connect(c->sd, (struct sockaddr *) dst, sizeof(*dst))) {
159 if (errno != EINPROGRESS) {
160 wpa_printf(MSG_DEBUG, "HTTP: Failed to connect: %s",
161 strerror(errno));
165 http_client_free(c);
166 return NULL;
162 goto fail;
167 }
168
169 /*
170 * Continue connecting in the background; eloop will call us
171 * once the connection is ready (or failed).
172 */
173 }
174
175 if (eloop_register_sock(c->sd, EVENT_TYPE_WRITE, http_client_tx_ready,
163 }
164
165 /*
166 * Continue connecting in the background; eloop will call us
167 * once the connection is ready (or failed).
168 */
169 }
170
171 if (eloop_register_sock(c->sd, EVENT_TYPE_WRITE, http_client_tx_ready,
176 c, NULL)) {
177 http_client_free(c);
178 return NULL;
179 }
172 c, NULL) ||
173 eloop_register_timeout(HTTP_CLIENT_TIMEOUT_SEC, 0,
174 http_client_timeout, c, NULL))
175 goto fail;
180
176
181 if (eloop_register_timeout(HTTP_CLIENT_TIMEOUT_SEC, 0,
182 http_client_timeout, c, NULL)) {
183 http_client_free(c);
184 return NULL;
185 }
186
187 c->req = req;
188
189 return c;
177 c->req = req;
178
179 return c;
180
181fail:
182 http_client_free(c);
183 return NULL;
190}
191
192
193char * http_client_url_parse(const char *url, struct sockaddr_in *dst,
194 char **ret_path)
195{
196 char *u, *addr, *port, *path;
197

--- 171 unchanged lines hidden ---
184}
185
186
187char * http_client_url_parse(const char *url, struct sockaddr_in *dst,
188 char **ret_path)
189{
190 char *u, *addr, *port, *path;
191

--- 171 unchanged lines hidden ---