properties.c (1848B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2018-2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #ifdef HAVE_CONFIG_H 24 #include <config.h> 25 #endif 26 27 #include <ell/ell.h> 28 29 #include "client/properties.h" 30 31 const char *properties_on_off_opts[3] = { "on", "off", NULL }; 32 const char *properties_yes_no_opts[3] = { "yes", "no", NULL }; 33 34 bool properties_builder_append_on_off_variant( 35 struct l_dbus_message_builder *builder, 36 const char *value_str) 37 { 38 bool value; 39 40 if (!builder || !value_str) 41 return false; 42 43 if (!strcmp(value_str, "on")) 44 value = true; 45 else if (!strcmp(value_str, "off")) 46 value = false; 47 else 48 return false; 49 50 return l_dbus_message_builder_append_basic(builder, 'b', &value); 51 } 52 53 bool properties_builder_append_yes_no_variant( 54 struct l_dbus_message_builder *builder, 55 const char *value_str) 56 { 57 bool value; 58 59 if (!builder || !value_str) 60 return false; 61 62 if (!strcmp(value_str, "yes")) 63 value = true; 64 else if (!strcmp(value_str, "no")) 65 value = false; 66 else 67 return false; 68 69 return l_dbus_message_builder_append_basic(builder, 'b', &value); 70 }