comparison src/xs_config.c @ 939:49b689449a37

Change xs_read_configuration() to return a boolean value, TRUE if configuration was successfully read for all items, FALSE if not. Failure might be non-existent or partial configuration (old/incompatible version.)
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 19 Nov 2012 17:57:05 +0200
parents 3fdb0af448c7
children d624258d7800
comparison
equal deleted inserted replaced
938:7a3aefb4844c 939:49b689449a37
805 } 805 }
806 806
807 807
808 /* Get the configuration (from file or default) 808 /* Get the configuration (from file or default)
809 */ 809 */
810 void xs_read_configuration(void) 810 gboolean xs_read_configuration(void)
811 { 811 {
812 XS_CONFIG_FILE *cfg; 812 XS_CONFIG_FILE *cfg;
813 gint i; 813 gint i;
814 gchar *tmpStr; 814 gboolean configOK = TRUE;
815 815
816 /* Try to open the XMMS configuration file */ 816 /* Try to open the XMMS configuration file */
817 XS_MUTEX_LOCK(xs_cfg); 817 XS_MUTEX_LOCK(xs_cfg);
818 XSDEBUG("loading from config-file ...\n"); 818 XSDEBUG("loading from config-file ...\n");
819 819
820 cfg = XS_CONFIG_OPEN(); 820 cfg = XS_CONFIG_OPEN();
821
822 if (cfg == NULL) 821 if (cfg == NULL)
823 { 822 {
824 XSDEBUG("Could not open configuration, trying to write defaults...\n"); 823 configOK = FALSE;
825 xs_write_configuration(); 824 goto error;
826 return;
827 } 825 }
828 826
829 /* Read the new settings from XMMS configuration file */ 827 /* Read the new settings from XMMS configuration file */
830 for (i = 0; i < xs_ncfgtable; i++) 828 for (i = 0; i < xs_ncfgtable; i++)
831 switch (xs_cfgtable[i].itemType) 829 switch (xs_cfgtable[i].itemType)
832 { 830 {
833 case CTYPE_INT: 831 case CTYPE_INT:
834 XS_CFG_GET_INT(xs_cfgtable[i].itemName, 832 if (!XS_CFG_GET_INT(xs_cfgtable[i].itemName,
835 (gint *) xs_cfgtable[i].itemData); 833 (gint *) xs_cfgtable[i].itemData))
834 configOK = FALSE;
836 break; 835 break;
837 836
838 case CTYPE_BOOL: 837 case CTYPE_BOOL:
839 XS_CFG_GET_BOOL(xs_cfgtable[i].itemName, 838 if (!XS_CFG_GET_BOOL(xs_cfgtable[i].itemName,
840 (gboolean *) xs_cfgtable[i].itemData); 839 (gboolean *) xs_cfgtable[i].itemData))
840 configOK = FALSE;
841 break; 841 break;
842 842
843 case CTYPE_FLOAT: 843 case CTYPE_FLOAT:
844 XS_CFG_GET_FLOAT(xs_cfgtable[i].itemName, 844 if (!XS_CFG_GET_FLOAT(xs_cfgtable[i].itemName,
845 (gfloat *) xs_cfgtable[i].itemData); 845 (gfloat *) xs_cfgtable[i].itemData))
846 configOK = FALSE;
846 break; 847 break;
847 848
848 case CTYPE_STR: 849 case CTYPE_STR:
849 if (XS_CFG_GET_STRING(xs_cfgtable[i].itemName,
850 (gchar **) &tmpStr))
851 { 850 {
852 xs_pstrcpy((gchar **) xs_cfgtable[i].itemData, tmpStr); 851 gchar *tmpStr;
853 g_free(tmpStr); 852 if (XS_CFG_GET_STRING(xs_cfgtable[i].itemName,
853 (gchar **) &tmpStr))
854 {
855 xs_pstrcpy((gchar **) xs_cfgtable[i].itemData, tmpStr);
856 g_free(tmpStr);
857 }
858 else
859 configOK = FALSE;
854 } 860 }
855 break; 861 break;
856 } 862 }
857 863
858 /* Filters and presets are a special case */ 864 /* Filters and presets are a special case */
862 { 868 {
863 xs_cfg.sid2FilterPresets = g_malloc0(xs_cfg.sid2NFilterPresets * sizeof(xs_sid_filter_t *)); 869 xs_cfg.sid2FilterPresets = g_malloc0(xs_cfg.sid2NFilterPresets * sizeof(xs_sid_filter_t *));
864 if (!xs_cfg.sid2FilterPresets) 870 if (!xs_cfg.sid2FilterPresets)
865 { 871 {
866 xs_error("Allocation of sid2FilterPresets structure failed!\n"); 872 xs_error("Allocation of sid2FilterPresets structure failed!\n");
873 configOK = FALSE;
867 } 874 }
868 else 875 else
869 { 876 {
870 for (i = 0; i < xs_cfg.sid2NFilterPresets; i++) 877 for (i = 0; i < xs_cfg.sid2NFilterPresets; i++)
871 xs_cfg.sid2FilterPresets[i] = xs_filter_load(cfg, i); 878 xs_cfg.sid2FilterPresets[i] = xs_filter_load(cfg, i);
872 } 879 }
873 } 880 }
874 881
875 XS_CONFIG_FREE(cfg); 882 error:
876 883 if (cfg != NULL)
884 {
885 XS_CONFIG_FREE(cfg);
886 }
877 XS_MUTEX_UNLOCK(xs_cfg); 887 XS_MUTEX_UNLOCK(xs_cfg);
878 XSDEBUG("OK\n"); 888 XSDEBUG("%s\n", configOK ? "OK" : "ERRORS!");
889 return configOK;
879 } 890 }
880 891
881 892
882 /* Write the current configuration 893 /* Write the current configuration
883 */ 894 */