~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/imap/cmd-genurlauth.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "imap-common.h"
 
4
#include "str.h"
 
5
#include "imap-commands.h"
 
6
#include "imap-quote.h"
 
7
#include "imap-urlauth.h"
 
8
 
 
9
bool cmd_genurlauth(struct client_command_context *cmd)
 
10
{
 
11
        const struct imap_arg *args;
 
12
        string_t *response;
 
13
        int ret;
 
14
 
 
15
        if (cmd->client->urlauth_ctx == NULL) {
 
16
                client_send_command_error(cmd, "URLAUTH disabled.");
 
17
                return TRUE;
 
18
        }
 
19
 
 
20
        if (!client_read_args(cmd, 0, 0, &args))
 
21
                return FALSE;
 
22
 
 
23
        response = t_str_new(1024);
 
24
        str_append(response, "* GENURLAUTH");
 
25
        for (;;) {
 
26
                const char *url_rump, *mechanism, *url, *error;
 
27
 
 
28
                if (IMAP_ARG_IS_EOL(args))
 
29
                        break;
 
30
                if (!imap_arg_get_astring(args++, &url_rump) ||
 
31
                    !imap_arg_get_atom(args++, &mechanism)) {
 
32
                        client_send_command_error(cmd, "Invalid arguments.");
 
33
                        return FALSE;
 
34
                }
 
35
 
 
36
                ret = imap_urlauth_generate(cmd->client->urlauth_ctx,
 
37
                                            mechanism, url_rump, &url, &error);
 
38
                if (ret <= 0) {
 
39
                        if (ret < 0)
 
40
                                client_send_internal_error(cmd);
 
41
                        else
 
42
                                client_send_command_error(cmd, error);
 
43
                        return TRUE;
 
44
                }
 
45
 
 
46
                str_append_c(response, ' ');
 
47
                imap_append_astring(response, url);
 
48
        }
 
49
 
 
50
        client_send_line(cmd->client, str_c(response));
 
51
        client_send_tagline(cmd, "OK GENURLAUTH completed.");
 
52
        return TRUE;
 
53
}