// sets a json value for a key int json_object_set_string(json_t *object, char *key, char *value, json_context_t *json_context) { int exit_code = 0; json_t *json_string_value = NULL; char *value_copied = NULL; check_not_null(object); check_not_null(key); check_not_null(json_context); if (value != NULL) { check_result(malloc_memcpy_string(&value_copied, value), 0); json_string_value = json_string(value_copied); check_not_null(json_string_value); check_result(json_object_set_new(object, key, json_string_value), 0); json_string_value = NULL; check_result( array_add_string( &(json_context->strings), &(json_context->strings_allocated_count), &(json_context->strings_used_count), value_copied), 0); value_copied = NULL; } else { check_result(json_object_set(object, key, json_null()), 0); } goto cleanup; error: exit_code = -1; cleanup: if (json_string_value != NULL) { json_free(json_string_value); } if (value_copied != NULL) { free(value_copied); } return exit_code; }
/** * Implementation of MUIM_DragDrop * * @param cl the class * @param obj the object * @param msg the parameter of the method * @return */ STATIC ULONG AddressGroupList_DragDrop(struct IClass *cl,Object *obj,struct MUIP_DragDrop *msg) { LONG pos; struct addressbook_entry_new *entry; struct addressbook_group *group; int need_refresh = 0; Object *address_list; if (!(address_list = msg->obj)) return 0; DoMethod(obj, MUIM_NList_GetEntry, xget(obj, MUIA_NList_DropMark), (ULONG)&group); if (!group) return 0; pos = MUIV_NList_NextSelected_Start; while (1) { DoMethod(address_list, MUIM_NList_NextSelected, (ULONG)&pos); if (pos == MUIV_NList_NextSelected_End) break; DoMethod(address_list, MUIM_NList_GetEntry, pos, (ULONG)&entry); if (entry && !array_contains(entry->group_array,group->name)) { char **newarray = array_add_string(entry->group_array,group->name); if (newarray) { entry->group_array = newarray; need_refresh = 1; } } } if (need_refresh) { DoMethod(address_list, MUIM_NList_Redraw, MUIV_NList_Redraw_All); /* TODO: Do this via a notify */ addressbook_clear(); addressbookwnd_store(); } return 1; }
/** * ADDRNEW ARexx command * * @param rxmsg the message defining the ARexx context * @param args the command's arguments */ static void arexx_addrnew(struct RexxMsg *rxmsg, STRPTR args) { APTR arg_handle; struct { STRPTR type; STRPTR alias; STRPTR name; STRPTR email; } addrnew_arg; memset(&addrnew_arg,0,sizeof(addrnew_arg)); if ((arg_handle = ParseTemplate("TYPE,ALIAS,NAME,EMAIL",args,&addrnew_arg))) { if (addrnew_arg.type && (toupper((unsigned char)(*addrnew_arg.type)) == 'G')) { addressbook_add_group(addrnew_arg.alias); } else { struct addressbook_entry_new *entry; char *name; name = utf8create(addrnew_arg.name, user.config.default_codeset?user.config.default_codeset->name:NULL); if ((entry = addressbook_add_entry(name))) { entry->alias = mystrdup(addrnew_arg.alias); entry->email_array = array_add_string(entry->email_array,addrnew_arg.email); } free(name); } main_build_addressbook(); addressbookwnd_refresh(); FreeTemplate(arg_handle); } }