Changeset f15553d for protocols/rpc
- Timestamp:
- 2015-04-12T15:04:55Z (10 years ago)
- Children:
- 531eabd
- Parents:
- c5a7b8d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/rpc/rpc.c
rc5a7b8d rf15553d 155 155 } 156 156 157 static char *rpc_set_evaluator(set_t *set, char *value); 158 157 159 static void rpc_init(account_t *acc) { 158 160 struct rpc_plugin *pd = acc->prpl->data; … … 164 166 * terrible idea. As was JSON, but hey. */ 165 167 set->flags |= (int) json_object_get_number(o, "flags"); 166 const char *eval = json_object_get_string(o, "type"); 167 if (eval == NULL) { 168 } else if (strcmp(eval, "int") == 0) { 169 set->eval = set_eval_int; 170 } else if (strcmp(eval, "bool") == 0) { 171 set->eval = set_eval_bool; 172 } else { 173 /* Default is string which means no evaluator. */ 174 } 168 set->eval = rpc_set_evaluator; 169 set->eval_data = o; 175 170 /* eval_list turns out to be a memory leak so don't implement it 176 171 * for now. … … 184 179 185 180 acc->flags |= pd->account_flags; 181 } 182 183 static char *rpc_set_evaluator(set_t *set, char *value) { 184 JSON_Object *o = set->eval_data; 185 const char *type = json_object_get_string(o, "type"); 186 187 /* Just allow two simple int/bool evaluators with no protocol awareness. */ 188 set_eval type_eval = NULL; 189 if (type == NULL) { 190 } else if (strncmp(type, "int", 3) == 0) { 191 type_eval = set_eval_int; 192 } else if (strncmp(type, "bool", 4) == 0) { 193 type_eval = set_eval_bool; 194 } 195 196 if (type_eval) { 197 char *new = type_eval(set, value); 198 if (new == SET_INVALID) { 199 return SET_INVALID; 200 } 201 } 202 203 account_t *acc = set->data; 204 if (acc->ic) { 205 /* But do send RPCs to the plugin for each changed setting so 206 * it always has up-to-date values. */ 207 RPC_OUT_INIT("set_set"); 208 json_array_append_string(params, set->key); 209 if (type_eval == set_eval_int) { 210 int num = 0; 211 /* Evaluator already did validation so ignore retval. */ 212 sscanf(value, "%d", &num); 213 json_array_append_number(params, num); 214 } else if (type_eval == set_eval_bool) { 215 json_array_append_boolean(params, bool2int(value)); 216 } else { 217 json_array_append_string(params, value); 218 } 219 rpc_send(acc->ic, rpc); 220 } 221 222 return value; 186 223 } 187 224
Note: See TracChangeset
for help on using the changeset viewer.