/[winpt]/trunk/MyGPGME/recipient.c
ViewVC logotype

Contents of /trunk/MyGPGME/recipient.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File MIME type: text/plain
File size: 4393 byte(s)
WinPT initial checkin.


1 /* recipient.c - mainatin recipient sets
2 * Copyright (C) 2000 Werner Koch (dd9jn)
3 * Copyright (C) 2002, 2003, 2005 Timo Schulz
4 *
5 * This file is part of MyGPGME.
6 *
7 * MyGPGME is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * MyGPGME is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <assert.h>
25 #include <string.h>
26
27 #include "util.h"
28 #include "context.h"
29 #include "rungpg.h"
30 #include "ops.h"
31
32 gpgme_error_t
33 gpgme_recipients_new (gpgme_recipients_t * r_rset)
34 {
35 gpgme_recipients_t rset;
36
37 if (!r_rset)
38 return mk_error (Invalid_Value);
39 *r_rset = NULL;
40 rset = calloc (1, sizeof *rset);
41 if (!rset)
42 return mk_error (Out_Of_Core);
43 *r_rset = rset;
44 return 0;
45 }
46
47
48 void
49 gpgme_recipients_release( gpgme_recipients_t rset )
50 {
51 struct user_id_s * u, * u2;
52
53 if (!rset)
54 return;
55 for (u = rset->list; u; u = u2) {
56 u2 = u->next;
57 safe_free (u);
58 }
59 rset->count = 0;
60 safe_free (rset);
61 }
62
63
64 gpgme_error_t
65 gpgme_recipients_add_name (gpgme_recipients_t rset, const char *name)
66 {
67 int val = GPGME_VALIDITY_UNKNOWN;
68 return gpgme_recipients_add_name_with_validity( rset, name, val );
69 }
70
71
72 gpgme_error_t
73 gpgme_recipients_add_name_with_validity( gpgme_recipients_t rset,
74 const char * name,
75 gpgme_validity_t val )
76 {
77 struct user_id_s * r;
78
79 if (!name || !rset)
80 return mk_error (Invalid_Value);
81 r = malloc (sizeof *r + strlen (name) + 1);
82 if (!r)
83 return mk_error (Out_Of_Core);
84 r->validity = val;
85 r->name_part = "";
86 r->email_part = "";
87 r->comment_part = "";
88 strcpy (r->name, name);
89 r->next = rset->list;
90 rset->list = r;
91 rset->count++;
92 return 0;
93 }
94
95
96
97 unsigned int
98 gpgme_recipients_count (const gpgme_recipients_t rset)
99 {
100 struct user_id_s * r;
101 unsigned int count = 0;
102
103 if (rset) {
104 for (r = rset->list ; r; r = r->next)
105 count++;
106 }
107 return count;
108 }
109
110
111 const char*
112 gpgme_recipients_get_name (const gpgme_recipients_t rset, int pos)
113 {
114 struct user_id_s *r;
115
116 if (!rset || pos > rset->count)
117 return NULL;
118 for (r = rset->list; r && pos > 0; r = r->next)
119 pos--;
120 return r->name;
121 }
122
123
124 gpgme_error_t
125 gpgme_recipients_enum_open( const gpgme_recipients_t rset, void **ctx )
126 {
127 if( !rset || !ctx )
128 return mk_error( Invalid_Value );
129 *ctx = rset->list;
130 return 0;
131 }
132
133
134 const char *
135 gpgme_recipients_enum_read( const gpgme_recipients_t rset, void **ctx )
136 {
137 struct user_id_s *r;
138
139 if( !rset || !ctx )
140 return NULL; /* oops */
141
142 r = *ctx;
143 if( r ) {
144 const char *s = r->name;
145 r = r->next;
146 *ctx = r;
147 return s;
148 }
149
150 return NULL;
151 }
152
153
154 gpgme_error_t
155 gpgme_recipients_enum_close( const gpgme_recipients_t rset, void **ctx )
156 {
157 if( !rset || !ctx )
158 return mk_error (Invalid_Value);
159 *ctx = NULL;
160 return 0;
161 }
162
163
164 void
165 _gpgme_append_gpg_args_from_recipients (const gpgme_recipients_t rset,
166 _gpg_object_t gpg)
167 {
168 struct user_id_s *r;
169
170 assert (rset);
171 for (r = rset->list ; r; r = r->next) {
172 _gpgme_gpg_add_arg (gpg, "-r");
173 _gpgme_gpg_add_arg (gpg, r->name);
174 }
175 }
176
177
178 int
179 _gpgme_recipients_all_valid( const gpgme_recipients_t rset )
180 {
181 struct user_id_s *r;
182
183 assert( rset );
184 for ( r = rset->list ; r; r = r->next ) {
185 if( r->validity != GPGME_VALIDITY_FULL
186 && r->validity != GPGME_VALIDITY_ULTIMATE )
187 return 0; /*no*/
188 }
189 return 1; /*yes*/
190 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26