1 |
/* common-status.c |
2 |
* Copyright (C) 2004 Timo Schulz |
3 |
* |
4 |
* This file is part of MyGPGME. |
5 |
* |
6 |
* MyGPGME is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* MyGPGME is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
20 |
|
21 |
#include <stdlib.h> |
22 |
#include <stdio.h> |
23 |
|
24 |
#include "types.h" |
25 |
#include "context.h" |
26 |
#include "common-status.h" |
27 |
#include "util.h" |
28 |
|
29 |
|
30 |
gpgme_error_t |
31 |
_gpgme_nodata_status_handler (gpg_status_code_t code, |
32 |
const char * args, int * ret) |
33 |
{ |
34 |
*ret = 0; |
35 |
|
36 |
switch (code) { |
37 |
case STATUS_NODATA: |
38 |
if (args) |
39 |
*ret = atoi (args); |
40 |
else |
41 |
*ret = -1; |
42 |
break; |
43 |
|
44 |
case STATUS_UNEXPECTED: |
45 |
*ret = 1; |
46 |
break; |
47 |
} |
48 |
|
49 |
return 0; |
50 |
} |
51 |
|
52 |
|
53 |
gpgme_error_t |
54 |
_gpgme_sigtrust_status_handler (gpg_status_code_t code, |
55 |
const char * args, |
56 |
int * retval) |
57 |
{ |
58 |
*retval = 0; |
59 |
|
60 |
switch (code) { |
61 |
case STATUS_TRUST_UNDEFINED: |
62 |
*retval = GPGME_VALIDITY_UNDEFINED; |
63 |
break; |
64 |
|
65 |
case STATUS_TRUST_NEVER: |
66 |
*retval = GPGME_VALIDITY_NEVER; |
67 |
break; |
68 |
|
69 |
case STATUS_TRUST_MARGINAL: |
70 |
*retval = GPGME_VALIDITY_MARGINAL; |
71 |
break; |
72 |
|
73 |
case STATUS_TRUST_FULLY: |
74 |
*retval = GPGME_VALIDITY_FULL; |
75 |
break; |
76 |
|
77 |
case STATUS_TRUST_ULTIMATE: |
78 |
*retval = GPGME_VALIDITY_ULTIMATE; |
79 |
break; |
80 |
} |
81 |
|
82 |
return 0; |
83 |
} |
84 |
|
85 |
|
86 |
gpgme_error_t |
87 |
_gpgme_pass_status_handler (gpg_status_code_t code, |
88 |
const char * args, |
89 |
int * r_bad_pass, int * r_no_pass, |
90 |
char ** r_info) |
91 |
{ |
92 |
int bad_pass = *r_bad_pass; |
93 |
int no_pass = *r_no_pass; |
94 |
char * p; |
95 |
|
96 |
switch (code) { |
97 |
case STATUS_BAD_PASSPHRASE: |
98 |
bad_pass++; |
99 |
break; |
100 |
|
101 |
case STATUS_GOOD_PASSPHRASE: |
102 |
bad_pass = 0; |
103 |
break; |
104 |
|
105 |
case STATUS_NEED_PASSPHRASE: |
106 |
case STATUS_NEED_PASSPHRASE_SYM: |
107 |
safe_free (*r_info); |
108 |
p = *r_info = strdup (args); |
109 |
if (!p) |
110 |
return GPGME_Out_Of_Core; |
111 |
break; |
112 |
|
113 |
case STATUS_MISSING_PASSPHRASE: |
114 |
DEBUG0 ("missing passphrase - stop\n"); |
115 |
no_pass = 1; |
116 |
break; |
117 |
} |
118 |
|
119 |
*r_bad_pass = bad_pass; |
120 |
*r_no_pass = no_pass; |
121 |
|
122 |
return 0; |
123 |
} |