Changeset f15553d
- Timestamp:
- 2015-04-12T15:04:55Z (10 years ago)
- Children:
- 531eabd
- Parents:
- c5a7b8d
- Files:
-
- 2 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 -
python/implugin.py
rc5a7b8d rf15553d 77 77 "oauth": { 78 78 "default": "off", 79 "type": "bool", 79 80 }, 80 81 "test": { 81 82 "default": "123", 83 "type": "int", 82 84 }, 85 "stringetje": { 86 "default": "testje", 87 "flags": 0x04, 88 } 83 89 }, 84 90 } … … 104 110 def set_away(self, state, message): 105 111 print "You're a slacker: %s (%r)" % (state, message) 112 113 def set_set(self, setting, value): 114 print "Setting %s changed to %r" % (setting, value) 106 115 107 116 def RunPlugin(plugin, debug=True):
Note: See TracChangeset
for help on using the changeset viewer.