Changeset 578e5b0
- Timestamp:
- 2015-05-14T16:08:06Z (10 years ago)
- Children:
- 600e09c
- Parents:
- 4225bec
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/misc.c
r4225bec r578e5b0 427 427 } 428 428 429 int is_bool(c har *value)429 int is_bool(const char *value) 430 430 { 431 431 if (*value == 0) { … … 453 453 } 454 454 455 int bool2int(c har *value)455 int bool2int(const char *value) 456 456 { 457 457 int i; -
lib/misc.h
r4225bec r578e5b0 137 137 G_MODULE_EXPORT void random_bytes(unsigned char *buf, int count); 138 138 139 G_MODULE_EXPORT int is_bool(c har *value);140 G_MODULE_EXPORT int bool2int(c har *value);139 G_MODULE_EXPORT int is_bool(const char *value); 140 G_MODULE_EXPORT int bool2int(const char *value); 141 141 142 142 G_MODULE_EXPORT struct ns_srv_reply **srv_lookup(char *service, char *protocol, char *domain); -
protocols/rpc/rpc.c
r4225bec r578e5b0 120 120 } 121 121 122 static JSON_Value *rpc_ser_settings(set_t **set) { 123 const set_t *s; 124 JSON_Value *ret = json_value_init_object(); 125 126 for (s = *set; s; s = s->next) { 127 json_object_set_string_or_null(json_object(ret), s->key, set_getstr(set, s->key)); 128 } 129 130 return ret; 131 } 122 static JSON_Value *rpc_ser_settings(set_t **set); 132 123 133 124 static JSON_Value *rpc_ser_account(account_t *acc) { … … 189 180 } 190 181 191 s tatic char *rpc_set_evaluator(set_t *set, char *value) {182 set_eval rpc_type_set_eval(const set_t *set) { 192 183 JSON_Object *o = set->eval_data; 193 184 const char *type = json_object_get_string(o, "type"); 194 185 195 /* Just allow two simple int/bool evaluators with no protocol awareness. */196 186 set_eval type_eval = NULL; 197 187 if (type == NULL) { 198 } else if (strncmp(type, "int", 3) == 0) { 188 /* Try to do something sane for settings that aren't ours. */ 189 if (set->eval == set_eval_int || set->eval == set_eval_bool) { 190 type_eval = set->eval; 191 } 192 } else if (g_str_has_prefix(type, "int")) { 199 193 type_eval = set_eval_int; 200 } else if ( strncmp(type, "bool", 4) == 0) {194 } else if (g_str_has_prefix(type, "bool")) { 201 195 type_eval = set_eval_bool; 202 196 } 203 197 198 return type_eval; 199 } 200 201 static JSON_Value *set_make_json_value(set_eval type, const char *value) { 202 JSON_Value *ret; 203 204 if (value == NULL) { 205 ret = json_value_init_null(); 206 } else if (type == set_eval_int) { 207 long long num = 0; 208 /* Evaluator already did validation so ignore retval. */ 209 sscanf(value, "%lld", &num); 210 ret = json_value_init_integer(num); 211 } else if (type == set_eval_bool) { 212 ret = json_value_init_boolean(bool2int(value)); 213 } else { 214 ret = json_value_init_string(value); 215 } 216 return ret; 217 } 218 219 static char *rpc_set_evaluator(set_t *set, char *value) { 220 set_eval type_eval = rpc_type_set_eval(set); 204 221 if (type_eval) { 205 222 char *new = type_eval(set, value); … … 215 232 RPC_OUT_INIT("set_set"); 216 233 json_array_append_string(params, set->key); 217 if (type_eval == set_eval_int) { 218 int num = 0; 219 /* Evaluator already did validation so ignore retval. */ 220 sscanf(value, "%d", &num); 221 json_array_append_integer(params, num); 222 } else if (type_eval == set_eval_bool) { 223 json_array_append_boolean(params, bool2int(value)); 224 } else { 225 json_array_append_string(params, value); 226 } 234 json_array_append_value(params, set_make_json_value(rpc_type_set_eval(set), value)); 227 235 rpc_send(acc->ic, rpc); 228 236 } 229 237 230 238 return value; 239 } 240 241 static JSON_Value *rpc_ser_settings(set_t **set) { 242 const set_t *s; 243 JSON_Value *ret = json_value_init_object(); 244 245 for (s = *set; s; s = s->next) { 246 JSON_Value *v = set_make_json_value(rpc_type_set_eval(s), set_value(s)); 247 json_object_set_value(json_object(ret), s->key, v); 248 } 249 250 return ret; 231 251 } 232 252 … … 239 259 struct rpc_connection *rd = ic->proto_data = g_new0(struct rpc_connection, 1); 240 260 struct rpc_plugin *pd = acc->prpl->data; 241 imcb_log(ic, " Connecting toRPC server");261 imcb_log(ic, "Logging in via RPC server"); 242 262 rd->fd = socket(pd->addr->sa_family, SOCK_STREAM, 0); 243 263 sock_make_nonblocking(rd->fd);
Note: See TracChangeset
for help on using the changeset viewer.