diff options
author | Goraf <22941576+Goraf@users.noreply.github.com> | 2018-01-18 17:57:36 +0100 |
---|---|---|
committer | Goraf <22941576+Goraf@users.noreply.github.com> | 2018-01-19 01:39:33 +0100 |
commit | fb40ed2b6385b9e3a85b35ba27f3a42207d22234 (patch) | |
tree | 9de6415c9c28c68d2fe750abe2c95c3a89ba08ca /protocols/Gadu-Gadu/src/libgadu/events.cpp | |
parent | 97bb7e79c15952e7f9bf47caef4e3c09dd63c8df (diff) |
Gadu-Gadu: update libgadu to 1.11.4
Diffstat (limited to 'protocols/Gadu-Gadu/src/libgadu/events.cpp')
-rw-r--r-- | protocols/Gadu-Gadu/src/libgadu/events.cpp | 162 |
1 files changed, 86 insertions, 76 deletions
diff --git a/protocols/Gadu-Gadu/src/libgadu/events.cpp b/protocols/Gadu-Gadu/src/libgadu/events.cpp index 9cfd036730..2374ade04c 100644 --- a/protocols/Gadu-Gadu/src/libgadu/events.cpp +++ b/protocols/Gadu-Gadu/src/libgadu/events.cpp @@ -178,6 +178,10 @@ void gg_event_free(struct gg_event *e) break;
}
+
+ case GG_EVENT_USERLIST100_REPLY:
+ free(e->event.userlist100_reply.reply);
+ break;
}
free(e);
@@ -268,9 +272,9 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() write() failed (errno=%d, %s)\n", errno, strerror(errno));
if (sess->state == GG_STATE_READING_REPLY)
- goto fail_connecting;
- else
- goto done;
+ e->event.failure = GG_FAILURE_CONNECTING;
+
+ goto fail;
}
if (res == sess->send_left) {
@@ -309,7 +313,7 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) if (failed) {
errno = errno2;
- goto fail_resolving;
+ goto fail_proxy_hub;
}
/* jeśli jesteśmy w resolverze i mamy ustawiony port
@@ -336,7 +340,7 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) /* jeśli w trybie asynchronicznym gg_connect()
* zwróci błąd, nie ma sensu próbować dalej. */
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection failed (errno=%d, %s), critical\n", errno, strerror(errno));
- goto fail_connecting;
+ goto fail_proxy_hub;
}
/* jeśli podano serwer i łączmy się przez proxy,
@@ -367,12 +371,8 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) /* jeśli asynchroniczne, sprawdzamy, czy nie wystąpił
* przypadkiem jakiś błąd. */
if (sess->async && (gg_getsockopt(sess->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) {
- if (sess->proxy_addr && sess->proxy_port)
- gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection to proxy failed (errno=%d, %s)\n", res, strerror(res));
- else
- gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection to hub failed (errno=%d, %s)\n", res, strerror(res));
-
- goto fail_connecting;
+ gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection to %s failed (errno=%d, %s)\n", (sess->proxy_addr && sess->proxy_port) ? "proxy" : "hub", res, strerror(res));
+ goto fail_proxy_hub;
}
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connected to hub, sending query\n");
@@ -384,7 +384,7 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) if (client == NULL) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() out of memory for client version\n");
- goto fail_connecting;
+ goto fail;
}
if (!gg_proxy_http_only && sess->proxy_addr && sess->proxy_port)
@@ -431,13 +431,7 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) * stało się coś złego. */
if (gg_sock_write(sess->fd, buf, (int)strlen(buf)) < (signed)strlen(buf)) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() sending query failed\n");
-
- e->type = GG_EVENT_CONN_FAILED;
- e->event.failure = GG_FAILURE_WRITING;
- sess->state = GG_STATE_IDLE;
- gg_sock_close(sess->fd);
- sess->fd = -1;
- break;
+ goto fail_proxy_hub;
}
sess->state = GG_STATE_READING_DATA;
@@ -463,7 +457,7 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) /* sprawdzamy, czy wszystko w porządku. */
if (strncmp(buf, "HTTP/1.", 7) || strncmp(buf + 9, "200", 3)) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() invalid http reply, connection failed\n");
- goto fail_connecting;
+ goto fail_proxy_hub;
}
/* ignorujemy resztę nagłówka. */
@@ -471,7 +465,10 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) gg_read_line(sess->fd, buf, sizeof(buf) - 1);
/* czytamy pierwszą linię danych. */
- gg_read_line(sess->fd, buf, sizeof(buf) - 1);
+ if (gg_read_line(sess->fd, buf, sizeof(buf) - 1) == NULL) {
+ gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() read error\n");
+ goto fail_proxy_hub;
+ }
gg_chomp(buf);
/* jeśli pierwsza liczba w linii nie jest równa zeru,
@@ -503,6 +500,7 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) }
gg_sock_close(sess->fd);
+ sess->fd = -1;
gg_debug_session(sess, GG_DEBUG_TRAFFIC, "// gg_watch_fd() received http data (%s)\n", buf);
@@ -527,10 +525,16 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) port = atoi(tmp + 1);
}
+ if (strcmp(host, "") == 0) {
+ gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() invalid response\n");
+ e->event.failure = GG_FAILURE_HUB;
+ goto fail;
+ }
+
if (!strcmp(host, "notoperating")) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() service unavailable\n", errno, strerror(errno));
- sess->fd = -1;
- goto fail_unavailable;
+ e->event.failure = GG_FAILURE_UNAVAILABLE;
+ goto fail;
}
addr.s_addr = inet_addr(host);
@@ -541,7 +545,8 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) if ((sess->fd = gg_connect(&sess->proxy_addr, sess->proxy_port, sess->async)) == -1) {
/* nie wyszło? trudno. */
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection to proxy failed (errno=%d, %s)\n", errno, strerror(errno));
- goto fail_connecting;
+ e->event.failure = GG_FAILURE_PROXY;
+ goto fail;
}
sess->state = GG_STATE_CONNECTING_GG;
@@ -557,7 +562,7 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) if (sess->server_addr == INADDR_NONE) {
if (sess->resolver_start(&sess->fd, &sess->resolver, host) == -1) {
gg_debug(GG_DEBUG_MISC, "// gg_login() resolving failed (errno=%d, %s)\n", errno, strerror(errno));
- goto fail_resolving;
+ goto fail;
}
sess->state = GG_STATE_RESOLVING_GG;
@@ -577,7 +582,8 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) /* ostatnia deska ratunku zawiodła?
* w takim razie zwijamy manatki. */
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection failed (errno=%d, %s)\n", errno, strerror(errno));
- goto fail_connecting;
+ e->event.failure = GG_FAILURE_CONNECTING;
+ goto fail;
}
}
@@ -609,7 +615,8 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) if (failed) {
errno = errno2;
- goto fail_resolving;
+ e->event.failure = GG_FAILURE_RESOLVING;
+ goto fail;
}
sess->server_addr = addr.s_addr;
@@ -625,7 +632,8 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) /* ostatnia deska ratunku zawiodła?
* w takim razie zwijamy manatki. */
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection failed (errno=%d, %s)\n", errno, strerror(errno));
- goto fail_connecting;
+ e->event.failure = GG_FAILURE_CONNECTING;
+ goto fail;
}
}
@@ -652,7 +660,8 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) * nie mamy czego próbować więcej. */
if (sess->proxy_addr && sess->proxy_port) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection to proxy failed (errno=%d, %s)\n", res, strerror(res));
- goto fail_connecting;
+ e->event.failure = GG_FAILURE_PROXY;
+ goto fail;
}
gg_sock_close(sess->fd);
@@ -672,21 +681,25 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) if (sess->ssl) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection failed (errno=%d, %s)\n", res, strerror(res));
- goto fail_connecting;
+ e->event.failure = GG_FAILURE_CONNECTING;
+ goto fail;
}
#endif
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection failed (errno=%d, %s), trying https\n", res, strerror(res));
- if (sess->port == GG_HTTPS_PORT)
- goto fail_connecting;
+ if (sess->port == GG_HTTPS_PORT) {
+ e->event.failure = GG_FAILURE_CONNECTING;
+ goto fail;
+ }
sess->port = GG_HTTPS_PORT;
/* próbujemy na port 443. */
if ((sess->fd = gg_connect(&sess->server_addr, sess->port, sess->async)) == -1) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() connection failed (errno=%d, %s)\n", errno, strerror(errno));
- goto fail_connecting;
+ e->event.failure = GG_FAILURE_CONNECTING;
+ goto fail;
}
sess->state = GG_STATE_CONNECTING_GG;
@@ -722,7 +735,8 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) if (gg_sock_write(sess->fd, buf, (int)strlen(buf)) < (signed)strlen(buf)) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() can't send proxy request\n");
free(auth);
- goto fail_connecting;
+ e->event.failure = GG_FAILURE_PROXY;
+ goto fail;
}
if (auth) {
@@ -730,7 +744,8 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) if (gg_sock_write(sess->fd, auth, (int)strlen(auth)) < (signed)strlen(auth)) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() can't send proxy request\n");
free(auth);
- goto fail_connecting;
+ e->event.failure = GG_FAILURE_PROXY;
+ goto fail;
}
free(auth);
@@ -738,7 +753,8 @@ struct gg_event *gg_watch_fd(struct gg_session *sess) if (gg_sock_write(sess->fd, "\r\n", 2) < 2) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd() can't send proxy request\n");
- goto fail_connecting;
+ e->event.failure = GG_FAILURE_PROXY;
+ goto fail;
}
}
@@ -850,14 +866,14 @@ gnutls_handshake_repeat: const gnutls_datum_t *peers;
gnutls_x509_crt_t cert;
- if (gnutls_x509_crt_init(&cert) >= 0) {
+ if (gnutls_x509_crt_init(&cert) == 0) {
peers = gnutls_certificate_get_peers(GG_SESSION_GNUTLS(sess), &peer_count);
if (peers != NULL) {
char buf[256];
size_t size;
- if (gnutls_x509_crt_import(cert, &peers[0], GNUTLS_X509_FMT_DER) >= 0) {
+ if (gnutls_x509_crt_import(cert, &peers[0], GNUTLS_X509_FMT_DER) == 0) {
size = sizeof(buf);
gnutls_x509_crt_get_dn(cert, buf, &size);
gg_debug_session(sess, GG_DEBUG_MISC, "// cert subject: %s\n", buf);
@@ -866,6 +882,8 @@ gnutls_handshake_repeat: gg_debug_session(sess, GG_DEBUG_MISC, "// cert issuer: %s\n", buf);
}
}
+
+ gnutls_x509_crt_deinit(cert);
}
}
@@ -999,23 +1017,17 @@ gnutls_handshake_repeat: if (gh == NULL) {
gg_debug_session(sess, GG_DEBUG_MISC, "// gg_watch_fd_connected() gg_recv_packet failed (errno=%d, %s)\n", errno, strerror(errno));
- if (errno == EAGAIN) {
- e->type = GG_EVENT_NONE;
- res = 0;
- } else {
- res = -1;
- }
-
- goto done;
- }
- if (gg_session_handle_packet(sess, gh->type, (const char *) gh + sizeof(struct gg_header), gh->length, e) == -1) {
- free(gh);
- res = -1;
- goto done;
- }
+ if (errno != EAGAIN)
+ goto fail;
+ } else {
+ if (gg_session_handle_packet(sess, gh->type, (const char *) gh + sizeof(struct gg_header), gh->length, e) == -1) {
+ free(gh);
+ goto fail;
+ }
free(gh);
+ }
sess->check = GG_CHECK_READ;
@@ -1023,40 +1035,38 @@ gnutls_handshake_repeat: }
}
-done:
- if (res == -1) {
- free(e);
- e = NULL;
- } else {
- if (sess->send_buf && (sess->state == GG_STATE_READING_REPLY || sess->state == GG_STATE_CONNECTED))
- sess->check |= GG_CHECK_WRITE;
- }
+ if (sess->send_buf && (sess->state == GG_STATE_READING_REPLY || sess->state == GG_STATE_CONNECTED))
+ sess->check |= GG_CHECK_WRITE;
return e;
-fail_connecting:
+fail_proxy_hub:
+ if (sess->proxy_port)
+ e->event.failure = GG_FAILURE_PROXY;
+ else
+ e->event.failure = GG_FAILURE_HUB;
+
+fail:
+ sess->resolver_cleanup(&sess->resolver, 1);
+
+ sess->state = GG_STATE_IDLE;
+
if (sess->fd != -1) {
+ int errno2;
+
errno2 = errno;
gg_sock_close(sess->fd);
errno = errno2;
sess->fd = -1;
}
- e->type = GG_EVENT_CONN_FAILED;
- e->event.failure = GG_FAILURE_CONNECTING;
- sess->state = GG_STATE_IDLE;
- goto done;
-
-fail_resolving:
- e->type = GG_EVENT_CONN_FAILED;
- e->event.failure = GG_FAILURE_RESOLVING;
- sess->state = GG_STATE_IDLE;
- goto done;
-fail_unavailable:
- e->type = GG_EVENT_CONN_FAILED;
- e->event.failure = GG_FAILURE_UNAVAILABLE;
- sess->state = GG_STATE_IDLE;
- goto done;
+ if (e->event.failure != 0) {
+ e->type = GG_EVENT_CONN_FAILED;
+ return e;
+ } else {
+ free(e);
+ return NULL;
+ }
}
/*
|