Skip to content

Commit

Permalink
lib-imap-urlauth & imap-urlauth: replace "if(mail_debug){i_debug}" wi…
Browse files Browse the repository at this point in the history
…th "e_debug(client->event)"
  • Loading branch information
Sergey-Kitov authored and cmouse committed Aug 7, 2018
1 parent 9db0b7b commit aef4bf6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 53 deletions.
12 changes: 4 additions & 8 deletions src/imap-urlauth/imap-urlauth-client.c
Expand Up @@ -81,15 +81,13 @@ int client_create(const char *service, const char *username,
if (username != NULL) {
if (set->imap_urlauth_submit_user != NULL &&
strcmp(set->imap_urlauth_submit_user, username) == 0) {
if (set->mail_debug)
i_debug("User %s has URLAUTH submit access", username);
e_debug(client->event, "User %s has URLAUTH submit access", username);
app = "submit+";
array_append(&client->access_apps, &app, 1);
}
if (set->imap_urlauth_stream_user != NULL &&
strcmp(set->imap_urlauth_stream_user, username) == 0) {
if (set->mail_debug)
i_debug("User %s has URLAUTH stream access", username);
e_debug(client->event, "User %s has URLAUTH stream access", username);
app = "stream";
array_append(&client->access_apps, &app, 1);
}
Expand Down Expand Up @@ -143,8 +141,7 @@ static int client_worker_connect(struct client *client)
socket_path = t_strconcat(client->set->base_dir,
"/"IMAP_URLAUTH_WORKER_SOCKET, NULL);

if (client->set->mail_debug)
i_debug("Connecting to worker socket %s", socket_path);
e_debug(client->event, "Connecting to worker socket %s", socket_path);

client->fd_ctrl = net_connect_unix_with_retries(socket_path, 1000);
if (client->fd_ctrl < 0) {
Expand Down Expand Up @@ -276,8 +273,7 @@ client_worker_input_line(struct client *client, const char *response)
return -1;
}

if (client->set->mail_debug)
i_debug("Worker finished successfully");
e_debug(client->event, "Worker finished successfully");

if (restart) {
/* connect to new worker for accessing different user */
Expand Down
12 changes: 4 additions & 8 deletions src/lib-imap-urlauth/imap-urlauth-backend.c
Expand Up @@ -70,10 +70,8 @@ imap_urlauth_backend_trans_get_mailbox_key(struct mailbox *box,
if (ret < 0)
return -1;

if (user->mail_debug) {
i_debug("imap-urlauth: %skey found for mailbox %s",
(ret > 0 ? "" : "no "), mailbox_get_vname(box));
}
e_debug(user->event, "imap-urlauth: %skey found for mailbox %s",
(ret > 0 ? "" : "no "), mailbox_get_vname(box));

if (ret == 0) {
if (!create)
Expand All @@ -86,10 +84,8 @@ imap_urlauth_backend_trans_get_mailbox_key(struct mailbox *box,

if (ret < 0)
return -1;
if (user->mail_debug) {
i_debug("imap-urlauth: created key for mailbox %s",
mailbox_get_vname(box));
}
e_debug(user->event, "imap-urlauth: created key for mailbox %s",
mailbox_get_vname(box));
} else {
/* read existing key */
buffer_create_from_data(&key_buf, mailbox_key_r,
Expand Down
60 changes: 27 additions & 33 deletions src/lib-imap-urlauth/imap-urlauth-connection.c
Expand Up @@ -194,8 +194,8 @@ imap_urlauth_connection_select_target(struct imap_urlauth_connection *conn)
if (target == NULL || conn->state != IMAP_URLAUTH_STATE_AUTHENTICATED)
return;

if (conn->user->mail_debug)
i_debug("imap-urlauth: Selecting target user `%s'", target->userid);
e_debug(conn->user->event,
"imap-urlauth: Selecting target user `%s'", target->userid);

conn->state = IMAP_URLAUTH_STATE_SELECTING_TARGET;
cmd = t_strdup_printf("USER\t%s\n", str_tabescape(target->userid));
Expand All @@ -217,8 +217,8 @@ imap_urlauth_connection_send_request(struct imap_urlauth_connection *conn)
(conn->targets_head->requests_head == NULL &&
conn->targets_head->next == NULL &&
conn->state == IMAP_URLAUTH_STATE_READY)) {
if (conn->user->mail_debug)
i_debug("imap-urlauth: No more requests pending; scheduling disconnect");
e_debug(conn->user->event,
"imap-urlauth: No more requests pending; scheduling disconnect");
timeout_remove(&conn->to_idle);
if (conn->idle_timeout_msecs > 0) {
conn->to_idle = timeout_add(conn->idle_timeout_msecs,
Expand Down Expand Up @@ -251,8 +251,8 @@ imap_urlauth_connection_send_request(struct imap_urlauth_connection *conn)
return;
}

if (conn->user->mail_debug)
i_debug("imap-urlauth: Fetching URL `%s'", urlreq->url);
e_debug(conn->user->event,
"imap-urlauth: Fetching URL `%s'", urlreq->url);

cmd = t_str_new(128);
str_append(cmd, "URL\t");
Expand Down Expand Up @@ -297,10 +297,9 @@ imap_urlauth_request_new(struct imap_urlauth_connection *conn,

timeout_remove(&conn->to_idle);

if (conn->user->mail_debug) {
i_debug("imap-urlauth: Added request for URL `%s' from user `%s'",
url, target_user);
}
e_debug(conn->user->event,
"imap-urlauth: Added request for URL `%s' from user `%s'",
url, target_user);

imap_urlauth_connection_send_request(conn);
return urlreq;
Expand Down Expand Up @@ -785,11 +784,12 @@ static int imap_urlauth_input_next(struct imap_urlauth_connection *conn)
return -1;
}

if (conn->user->mail_debug) {
if (conn->state == IMAP_URLAUTH_STATE_AUTHENTICATING)
i_debug("imap-urlauth: Successfully authenticated to service");
else
i_debug("imap-urlauth: Successfully unselected target user");
if (conn->state == IMAP_URLAUTH_STATE_AUTHENTICATING) {
e_debug(conn->user->event,
"imap-urlauth: Successfully authenticated to service");
} else {
e_debug(conn->user->event,
"imap-urlauth: Successfully unselected target user");
}

conn->state = IMAP_URLAUTH_STATE_AUTHENTICATED;
Expand All @@ -803,10 +803,9 @@ static int imap_urlauth_input_next(struct imap_urlauth_connection *conn)
i_assert(conn->targets_head != NULL);

if (strcasecmp(response, "NO") == 0) {
if (conn->user->mail_debug) {
i_debug("imap-urlauth: Failed to select target user %s",
conn->targets_head->userid);
}
e_debug(conn->user->event,
"imap-urlauth: Failed to select target user %s",
conn->targets_head->userid);
imap_urlauth_target_fail(conn, conn->targets_head, NULL);

conn->state = IMAP_URLAUTH_STATE_AUTHENTICATED;
Expand All @@ -821,10 +820,9 @@ static int imap_urlauth_input_next(struct imap_urlauth_connection *conn)
return -1;
}

if (conn->user->mail_debug) {
i_debug("imap-urlauth: Successfully selected target user %s",
conn->targets_head->userid);
}
e_debug(conn->user->event,
"imap-urlauth: Successfully selected target user %s",
conn->targets_head->userid);
conn->state = IMAP_URLAUTH_STATE_READY;
imap_urlauth_connection_send_request(conn);
return 0;
Expand Down Expand Up @@ -898,8 +896,7 @@ imap_urlauth_connection_do_connect(struct imap_urlauth_connection *conn)
return -1;
}

if (conn->user->mail_debug)
i_debug("imap-urlauth: Connecting to service at %s", conn->path);
e_debug(conn->user->event, "imap-urlauth: Connecting to service at %s", conn->path);

i_assert(conn->fd == -1);
fd = net_connect_unix(conn->path);
Expand Down Expand Up @@ -953,12 +950,10 @@ static void imap_urlauth_connection_disconnect
conn->state = IMAP_URLAUTH_STATE_DISCONNECTED;

if (conn->fd != -1) {
if (conn->user->mail_debug) {
if (reason == NULL)
i_debug("imap-urlauth: Disconnecting from service");
else
i_debug("imap-urlauth: Disconnected: %s", reason);
}
if (reason == NULL)
e_debug(conn->user->event, "imap-urlauth: Disconnecting from service");
else
e_debug(conn->user->event, "imap-urlauth: Disconnected: %s", reason);

io_remove(&conn->io);
i_stream_destroy(&conn->input);
Expand Down Expand Up @@ -992,8 +987,7 @@ imap_urlauth_connection_do_reconnect(struct imap_urlauth_connection *conn)
}

if (ioloop_time - conn->last_reconnect < IMAP_URLAUTH_RECONNECT_MIN_SECS) {
if (conn->user->mail_debug)
i_debug("imap-urlauth: Scheduling reconnect");
e_debug(conn->user->event, "imap-urlauth: Scheduling reconnect");
timeout_remove(&conn->to_reconnect);
conn->to_reconnect =
timeout_add(IMAP_URLAUTH_RECONNECT_MIN_SECS*1000,
Expand Down
6 changes: 2 additions & 4 deletions src/lib-imap-urlauth/imap-urlauth-fetch.c
Expand Up @@ -352,8 +352,7 @@ int imap_urlauth_fetch_url(struct imap_urlauth_fetch *ufetch, const char *url,
if (imap_url_parse(url, NULL, url_parse_flags, &imap_url, &error) < 0) {
errormsg = t_strdup_printf(
"Failed to fetch URLAUTH \"%s\": %s", url, error);
if (mail_user->mail_debug)
i_debug("%s", errormsg);
e_debug(mail_user->event, "%s", errormsg);
ufetch->pending_requests++;
imap_urlauth_fetch_ref(ufetch);
imap_urlauth_fetch_error(ufetch, url, url_flags, errormsg);
Expand Down Expand Up @@ -400,8 +399,7 @@ int imap_urlauth_fetch_url_parsed(struct imap_urlauth_fetch *ufetch,
} else if (!imap_urlauth_check(uctx, imap_url, TRUE, &error)) {
errormsg = t_strdup_printf(
"Failed to fetch URLAUTH \"%s\": %s", url, error);
if (mail_user->mail_debug)
i_debug("%s", errormsg);
e_debug(mail_user->event, "%s", errormsg);
imap_urlauth_fetch_error(ufetch, url, url_flags, errormsg);
imap_url = NULL;
}
Expand Down

0 comments on commit aef4bf6

Please sign in to comment.