summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2014-10-26 14:30:25 +0200
committerYakov Goldberg <yakov.g@samsung.com>2014-10-26 16:06:33 +0200
commit12954fbb64f7a0b4ed234d677fdbbfb44117d1cc (patch)
tree79a394ad35e709e1baff51fdf30452cd6deab0c8
parent356fc8d935b76aaad76b1bd23aca585d90096c15 (diff)
add null checks when parsing json
-rw-r--r--src/lib/gui_parser.c126
1 files changed, 66 insertions, 60 deletions
diff --git a/src/lib/gui_parser.c b/src/lib/gui_parser.c
index 8f40819..b88f99c 100644
--- a/src/lib/gui_parser.c
+++ b/src/lib/gui_parser.c
@@ -938,87 +938,93 @@ _gui_parser_parse(Gui_Context *gui_ctx, char *_data)
938 parse_ret = _settings_parse(gui_ctx, _tmp); 938 parse_ret = _settings_parse(gui_ctx, _tmp);
939 _tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Widgets"); 939 _tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Widgets");
940 940
941 Eina_Iterator *it = eina_json_object_iterator_new(_tmp); 941 if (_tmp)
942 /* Iterate over widgets, to register names. */
943 EINA_ITERATOR_FOREACH(it, c)
944 { 942 {
945 name = eina_json_pair_name_get(c); 943 Eina_Iterator *it = eina_json_object_iterator_new(_tmp);
946 c = eina_json_pair_value_get(c); 944 /* Iterate over widgets, to register names. */
947 Eina_Json_Value *j = EINA_JSON_OBJECT_VALUE_GET(c, "Desc", "class"); 945 EINA_ITERATOR_FOREACH(it, c)
948 if (!j) goto end;
949
950 if (gui_context_dep_id_by_name_get(gui_ctx, name))
951 { 946 {
952 ERR("Name: %s already used", name); 947 name = eina_json_pair_name_get(c);
953 parse_ret = EINA_FALSE; 948 c = eina_json_pair_value_get(c);
954 break; 949 Eina_Json_Value *j = EINA_JSON_OBJECT_VALUE_GET(c, "Desc", "class");
955 } 950 if (!j) goto end;
956 951
957 Dep_Id *dep_id = gui_context_dep_data_set(gui_ctx, name, DEP_TYPE_WIDGET); 952 if (gui_context_dep_id_by_name_get(gui_ctx, name))
958 const char *class_name = eina_json_string_get(j); 953 {
959 wdg_new(gui_ctx, class_name, dep_id); 954 ERR("Name: %s already used", name);
960 } 955 parse_ret = EINA_FALSE;
961 eina_iterator_free(it); 956 break;
962 if (!parse_ret) 957 }
963 {
964 goto end;
965 }
966 958
967 /* Iterate over widgets again, in order to create widgets. */ 959 Dep_Id *dep_id = gui_context_dep_data_set(gui_ctx, name, DEP_TYPE_WIDGET);
968 _tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Widgets"); 960 const char *class_name = eina_json_string_get(j);
969 it = eina_json_object_iterator_new(_tmp); 961 wdg_new(gui_ctx, class_name, dep_id);
970 EINA_ITERATOR_FOREACH(it, c) 962 }
971 { 963 eina_iterator_free(it);
972 name = eina_json_pair_name_get(c); 964 if (!parse_ret)
973 c = eina_json_pair_value_get(c); 965 {
966 goto end;
967 }
974 968
975 Dep_Id *name_id = gui_context_dep_id_by_name_get(gui_ctx, name); 969 /* Iterate over widgets again, in order to create widgets. */
976 if (!name_id) 970 _tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Widgets");
971 it = eina_json_object_iterator_new(_tmp);
972 EINA_ITERATOR_FOREACH(it, c)
977 { 973 {
978 ERR("Name: %s doesnt exist", name); 974 name = eina_json_pair_name_get(c);
979 parse_ret = EINA_FALSE; 975 c = eina_json_pair_value_get(c);
980 break; 976
977 Dep_Id *name_id = gui_context_dep_id_by_name_get(gui_ctx, name);
978 if (!name_id)
979 {
980 ERR("Name: %s doesnt exist", name);
981 parse_ret = EINA_FALSE;
982 break;
983 }
984 parse_ret = _widget_parse(gui_ctx, name_id, c);
985 if (!parse_ret)
986 {
987 ERR("Can not parse widget: \"%s\"", name);
988 break;
989 }
981 } 990 }
982 parse_ret = _widget_parse(gui_ctx, name_id, c); 991 eina_iterator_free(it);
983 if (!parse_ret) 992 if (!parse_ret)
984 { 993 {
985 ERR("Can not parse widget: \"%s\"", name); 994 goto end;
986 break;
987 } 995 }
988 } 996 }
989 eina_iterator_free(it);
990 if (!parse_ret)
991 {
992 goto end;
993 }
994 997
995 /* Iterate over sequences again, in order to create them. */ 998 /* Iterate over sequences again, in order to create them. */
996 _tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Sequences"); 999 _tmp = EINA_JSON_OBJECT_VALUE_GET(jv, "Sequences");
997 it = eina_json_object_iterator_new(_tmp); 1000 if (_tmp)
998 EINA_ITERATOR_FOREACH(it, c)
999 { 1001 {
1000 name = eina_json_pair_name_get(c); 1002 Eina_Iterator *it = eina_json_object_iterator_new(_tmp);
1001 c = eina_json_pair_value_get(c); 1003 EINA_ITERATOR_FOREACH(it, c)
1002
1003 Dep_Id *name_id = gui_context_dep_id_by_name_get(gui_ctx, name);
1004 if (!name_id)
1005 { 1004 {
1006 ERR("Looks like sequence: \"%s\" was not registered in resources.", name); 1005 name = eina_json_pair_name_get(c);
1007 parse_ret = EINA_FALSE; 1006 c = eina_json_pair_value_get(c);
1008 break; 1007
1008 Dep_Id *name_id = gui_context_dep_id_by_name_get(gui_ctx, name);
1009 if (!name_id)
1010 {
1011 ERR("Looks like sequence: \"%s\" was not registered in resources.", name);
1012 parse_ret = EINA_FALSE;
1013 break;
1014 }
1015 parse_ret = _sequence_parse(gui_ctx, name_id, c);
1016 if (!parse_ret)
1017 {
1018 ERR("Can not parse sequence: \"%s\"", name);
1019 break;
1020 }
1009 } 1021 }
1010 parse_ret = _sequence_parse(gui_ctx, name_id, c); 1022 eina_iterator_free(it);
1011 if (!parse_ret) 1023 if (!parse_ret)
1012 { 1024 {
1013 ERR("Can not parse sequence: \"%s\"", name); 1025 goto end;
1014 break;
1015 } 1026 }
1016 } 1027 }
1017 eina_iterator_free(it);
1018 if (!parse_ret)
1019 {
1020 goto end;
1021 }
1022 1028
1023end: 1029end:
1024 eina_json_value_free(jv); 1030 eina_json_value_free(jv);