Actually encrypt passwords before storing them
[claws.git] / src / plugins / vcalendar / libical / libical / icalderivedparameter.c.in
1 /* -*- Mode: C -*-
2   ======================================================================
3   FILE: icalderivedparameters.{c,h}
4   CREATOR: eric 09 May 1999
5   
6   $Id$
7   $Locker$
8     
9
10  (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
11
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of either: 
14
15     The LGPL as published by the Free Software Foundation, version
16     2.1, available at: http://www.fsf.org/copyleft/lesser.html
17
18   Or:
19
20     The Mozilla Public License Version 1.0. You may obtain a copy of
21     the License at http://www.mozilla.org/MPL/
22
23   The original code is icalderivedparameters.{c,h}
24
25   Contributions from:
26      Graham Davison (g.m.davison@computer.org)
27
28  ======================================================================*/
29 /*#line 29 "icalparameter.c.in"*/
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33
34
35 #include "icalparameter.h"
36 #include "icalparameterimpl.h"
37
38 #include "icalproperty.h"
39 #include "icalerror.h"
40 #include "icalmemory.h"
41
42 #include <stdlib.h> /* for malloc() */
43 #include <errno.h>
44 #include <string.h> /* for memset() */
45
46 icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value);
47
48 struct icalparameter_impl* icalparameter_new_impl(icalparameter_kind kind);
49
50 /* This map associates each of the parameters with the string
51    representation of the paramter's name */
52 struct icalparameter_kind_map {
53     icalparameter_kind kind;
54     char *name;
55     
56 };
57
58 static struct icalparameter_kind_map parameter_map[];
59
60
61 const char* icalparameter_kind_to_string(icalparameter_kind kind)
62 {
63     int i;
64
65     for (i=0; parameter_map[i].kind != ICAL_NO_PARAMETER; i++) {
66         if (parameter_map[i].kind == kind) {
67             return parameter_map[i].name;
68         }
69     }
70
71     return 0;
72
73 }
74
75 icalparameter_kind icalparameter_string_to_kind(const char* string)
76 {
77     int i;
78
79     if (string ==0 ) { 
80         return ICAL_NO_PARAMETER;
81     }
82
83     for (i=0; parameter_map[i].kind  != ICAL_NO_PARAMETER; i++) {
84
85         if (strcmp(parameter_map[i].name, string) == 0) {
86             return parameter_map[i].kind;
87         }
88     }
89
90     if(strncmp(string,"X-",2)==0){
91         return ICAL_X_PARAMETER;
92     }
93
94     return ICAL_NO_PARAMETER;
95 }
96
97 /* This map associates the enumerations for the VALUE parameter with
98    the kinds of VALUEs. */
99
100 struct icalparameter_value_kind_map {
101     icalparameter_value value; 
102     icalvalue_kind kind; 
103 };
104
105 static struct icalparameter_value_kind_map value_kind_map[];
106
107
108 icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value)
109 {
110     int i;
111
112     for (i=0; value_kind_map[i].kind  != ICAL_NO_VALUE; i++) {
113
114         if (value_kind_map[i].value == value) {
115             return value_kind_map[i].kind;
116         }
117     }
118
119     return ICAL_NO_VALUE;
120 }
121
122
123 /* This map associates the parameter enumerations with a specific parameter and the string representation of the enumeration */
124
125 struct icalparameter_map {
126     icalparameter_kind kind;
127     int enumeration;
128     const char* str;
129 };
130
131
132 static struct icalparameter_map icalparameter_map[];
133
134
135 const char* icalparameter_enum_to_string(int e) 
136 {
137     int i;
138
139     icalerror_check_arg_rz(e >= ICALPARAMETER_FIRST_ENUM,"e");
140     icalerror_check_arg_rz(e <= ICALPARAMETER_LAST_ENUM,"e");
141
142     for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
143         if(e == icalparameter_map[i].enumeration){
144             return icalparameter_map[i].str;
145         }
146     }
147
148     return 0;
149 }
150
151 int icalparameter_string_to_enum(const char* str)
152 {
153     int i;
154
155     icalerror_check_arg_rz(str != 0,"str");
156
157     for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
158         if(strcmp(str,icalparameter_map[i].str) == 0) {
159             return icalparameter_map[i].enumeration;
160         }
161     }
162
163     return 0;
164 }
165
166 icalparameter* icalparameter_new_from_value_string(icalparameter_kind kind,const  char* val)
167 {
168
169     struct icalparameter_impl* param=0;
170     int found_kind = 0;
171     int i;
172
173     icalerror_check_arg_rz((val!=0),"val");
174
175     /* Search through the parameter map to find a matching kind */
176
177     param = icalparameter_new_impl(kind);
178
179     for (i=0; icalparameter_map[i].kind != ICAL_NO_PARAMETER; i++){
180         if(kind == icalparameter_map[i].kind) {
181             char *raw_val = strdup(val);
182             char *value = raw_val;
183             found_kind = 1;
184             if(value[0] == '\"' && value[strlen(value) - 1] == '\"') {
185                 value++;
186                 value[strlen(value) - 1] = '\0';
187             }
188             if(strcmp(value,icalparameter_map[i].str) == 0) {
189                 free(raw_val);
190                 param->data = (int)icalparameter_map[i].enumeration;
191                 return param;
192             }
193             free(raw_val);
194         }
195     }
196     
197     if(found_kind == 1){
198         /* The kind was in the parameter map, but the string did not
199            match, so assume that it is an alternate value, like an
200            X-value.*/
201         
202         icalparameter_set_xvalue(param, val);
203
204     } else {
205  
206         /* If the kind was not found, then it must be a string type */
207         
208         ((struct icalparameter_impl*)param)->string = icalmemory_strdup(val);
209
210     }
211
212    return param;
213 }
214
215
216
217
218 /* Everything below this line is machine generated. Do not edit. */