|
@@ -32,6 +32,29 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
32
|
32
|
/** List of all parameter lists */
|
33
|
33
|
static LIST_HEAD ( parameters );
|
34
|
34
|
|
|
35
|
+/**
|
|
36
|
+ * Free form parameter list
|
|
37
|
+ *
|
|
38
|
+ * @v refcnt Reference count
|
|
39
|
+ */
|
|
40
|
+static void free_parameters ( struct refcnt *refcnt ) {
|
|
41
|
+ struct parameters *params =
|
|
42
|
+ container_of ( refcnt, struct parameters, refcnt );
|
|
43
|
+ struct parameter *param;
|
|
44
|
+ struct parameter *tmp;
|
|
45
|
+
|
|
46
|
+ DBGC ( params, "PARAMS \"%s\" destroyed\n", params->name );
|
|
47
|
+
|
|
48
|
+ /* Free all parameters */
|
|
49
|
+ list_for_each_entry_safe ( param, tmp, ¶ms->entries, list ) {
|
|
50
|
+ list_del ( ¶m->list );
|
|
51
|
+ free ( param );
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ /* Free parameter list */
|
|
55
|
+ free ( params );
|
|
56
|
+}
|
|
57
|
+
|
35
|
58
|
/**
|
36
|
59
|
* Find form parameter list by name
|
37
|
60
|
*
|
|
@@ -63,14 +86,17 @@ struct parameters * create_parameters ( const char *name ) {
|
63
|
86
|
|
64
|
87
|
/* Destroy any existing parameter list of this name */
|
65
|
88
|
params = find_parameters ( name );
|
66
|
|
- if ( params )
|
67
|
|
- destroy_parameters ( params );
|
|
89
|
+ if ( params ) {
|
|
90
|
+ claim_parameters ( params );
|
|
91
|
+ params_put ( params );
|
|
92
|
+ }
|
68
|
93
|
|
69
|
94
|
/* Allocate parameter list */
|
70
|
95
|
name_len = ( name ? ( strlen ( name ) + 1 /* NUL */ ) : 0 );
|
71
|
96
|
params = zalloc ( sizeof ( *params ) + name_len );
|
72
|
97
|
if ( ! params )
|
73
|
98
|
return NULL;
|
|
99
|
+ ref_init ( ¶ms->refcnt, free_parameters );
|
74
|
100
|
name_copy = ( ( void * ) ( params + 1 ) );
|
75
|
101
|
|
76
|
102
|
/* Populate parameter list */
|
|
@@ -125,41 +151,3 @@ struct parameter * add_parameter ( struct parameters *params,
|
125
|
151
|
params->name, param->key, param->value );
|
126
|
152
|
return param;
|
127
|
153
|
}
|
128
|
|
-
|
129
|
|
-/**
|
130
|
|
- * Destroy form parameter list
|
131
|
|
- *
|
132
|
|
- * @v params Parameter list
|
133
|
|
- */
|
134
|
|
-void destroy_parameters ( struct parameters *params ) {
|
135
|
|
- struct parameter *param;
|
136
|
|
- struct parameter *tmp;
|
137
|
|
-
|
138
|
|
- DBGC ( params, "PARAMS \"%s\" destroyed\n", params->name );
|
139
|
|
-
|
140
|
|
- /* Free all parameters */
|
141
|
|
- list_for_each_entry_safe ( param, tmp, ¶ms->entries, list ) {
|
142
|
|
- list_del ( ¶m->list );
|
143
|
|
- free ( param );
|
144
|
|
- }
|
145
|
|
-
|
146
|
|
- /* Free parameter list */
|
147
|
|
- list_del ( ¶ms->list );
|
148
|
|
- free ( params );
|
149
|
|
-}
|
150
|
|
-
|
151
|
|
-/**
|
152
|
|
- * Claim ownership of form parameter list
|
153
|
|
- *
|
154
|
|
- * @v params Parameter list
|
155
|
|
- */
|
156
|
|
-void claim_parameters ( struct parameters *params ) {
|
157
|
|
-
|
158
|
|
- DBGC ( params, "PARAMS \"%s\" claimed\n", params->name );
|
159
|
|
-
|
160
|
|
- /* Remove from list of parameter lists */
|
161
|
|
- list_del ( ¶ms->list );
|
162
|
|
-
|
163
|
|
- /* Reinitialise list to allow for subsequent destroy_parameters() */
|
164
|
|
- INIT_LIST_HEAD ( ¶ms->list );
|
165
|
|
-}
|