diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-23 15:58:23 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-23 15:58:23 +0000 |
commit | 3ecbb9b47c2f8c1ed5e9dbed4803999420dbd6ac (patch) | |
tree | f6266a7b908593cb99992fb6da539f7f6e6c8220 /src/namestore | |
parent | 1358762d69a894017d1be7d3d55367e492deb111 (diff) | |
download | gnunet-3ecbb9b47c2f8c1ed5e9dbed4803999420dbd6ac.tar.gz gnunet-3ecbb9b47c2f8c1ed5e9dbed4803999420dbd6ac.zip |
simplify gnunet-namestore / namestore_rest_plugin to avoid deprecated CLIENT_service_test
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-namestore.c | 117 | ||||
-rw-r--r-- | src/namestore/plugin_rest_namestore.c | 151 |
2 files changed, 89 insertions, 179 deletions
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 8f0c14fa0..457e77022 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -753,27 +753,37 @@ del_monitor (void *cls, | |||
753 | 753 | ||
754 | 754 | ||
755 | /** | 755 | /** |
756 | * Function called with the result from the check if the namestore | 756 | * Callback invoked from identity service with ego information. |
757 | * service is actually running. If it is, we start the actual | 757 | * An @a ego of NULL means the ego was not found. |
758 | * operation. | ||
759 | * | 758 | * |
760 | * @param cls closure with our configuration | 759 | * @param cls closure with the configuration |
761 | * @param result #GNUNET_YES if the namestore service is running | 760 | * @param ego an ego known to identity service, or NULL |
762 | */ | 761 | */ |
763 | static void | 762 | static void |
764 | testservice_task (void *cls, | 763 | identity_cb (void *cls, |
765 | int result) | 764 | const struct GNUNET_IDENTITY_Ego *ego) |
766 | { | 765 | { |
767 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 766 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
768 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 767 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
769 | struct GNUNET_GNSRECORD_Data rd; | 768 | struct GNUNET_GNSRECORD_Data rd; |
770 | 769 | ||
771 | if (GNUNET_YES != result) | 770 | el = NULL; |
771 | if (NULL == ego) | ||
772 | { | 772 | { |
773 | FPRINTF (stderr, _("Service `%s' is not running\n"), | 773 | if (NULL != ego_name) |
774 | "namestore"); | 774 | { |
775 | fprintf (stderr, | ||
776 | _("Ego `%s' not known to identity service\n"), | ||
777 | ego_name); | ||
778 | } | ||
779 | GNUNET_SCHEDULER_shutdown (); | ||
780 | ret = -1; | ||
775 | return; | 781 | return; |
776 | } | 782 | } |
783 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
784 | GNUNET_free_non_null (ego_name); | ||
785 | ego_name = NULL; | ||
786 | |||
777 | if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey)) ) | 787 | if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey)) ) |
778 | { | 788 | { |
779 | /* nothing more to be done */ | 789 | /* nothing more to be done */ |
@@ -1028,42 +1038,6 @@ testservice_task (void *cls, | |||
1028 | } | 1038 | } |
1029 | 1039 | ||
1030 | 1040 | ||
1031 | /** | ||
1032 | * Callback invoked from identity service with ego information. | ||
1033 | * An @a ego of NULL means the ego was not found. | ||
1034 | * | ||
1035 | * @param cls closure with the configuration | ||
1036 | * @param ego an ego known to identity service, or NULL | ||
1037 | */ | ||
1038 | static void | ||
1039 | identity_cb (void *cls, | ||
1040 | const struct GNUNET_IDENTITY_Ego *ego) | ||
1041 | { | ||
1042 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
1043 | |||
1044 | el = NULL; | ||
1045 | if (NULL == ego) | ||
1046 | { | ||
1047 | if (NULL != ego_name) | ||
1048 | { | ||
1049 | fprintf (stderr, | ||
1050 | _("Ego `%s' not known to identity service\n"), | ||
1051 | ego_name); | ||
1052 | } | ||
1053 | GNUNET_SCHEDULER_shutdown (); | ||
1054 | ret = -1; | ||
1055 | return; | ||
1056 | } | ||
1057 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
1058 | GNUNET_free_non_null (ego_name); | ||
1059 | ego_name = NULL; | ||
1060 | GNUNET_CLIENT_service_test ("namestore", cfg, | ||
1061 | GNUNET_TIME_UNIT_SECONDS, | ||
1062 | &testservice_task, | ||
1063 | (void *) cfg); | ||
1064 | } | ||
1065 | |||
1066 | |||
1067 | static void | 1041 | static void |
1068 | default_ego_cb (void *cls, | 1042 | default_ego_cb (void *cls, |
1069 | struct GNUNET_IDENTITY_Ego *ego, | 1043 | struct GNUNET_IDENTITY_Ego *ego, |
@@ -1104,19 +1078,23 @@ id_connect_cb (void *cls, | |||
1104 | } | 1078 | } |
1105 | 1079 | ||
1106 | 1080 | ||
1081 | /** | ||
1082 | * Main function that will be run. | ||
1083 | * | ||
1084 | * @param cls closure | ||
1085 | * @param args remaining command-line arguments | ||
1086 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
1087 | * @param cfg configuration | ||
1088 | */ | ||
1107 | static void | 1089 | static void |
1108 | testservice_id_task (void *cls, int result) | 1090 | run (void *cls, |
1091 | char *const *args, | ||
1092 | const char *cfgfile, | ||
1093 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
1109 | { | 1094 | { |
1110 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 1095 | if ( (NULL != args[0]) && (NULL == uri) ) |
1096 | uri = GNUNET_strdup (args[0]); | ||
1111 | 1097 | ||
1112 | if (result != GNUNET_YES) | ||
1113 | { | ||
1114 | fprintf (stderr, | ||
1115 | _("Identity service is not running\n")); | ||
1116 | GNUNET_SCHEDULER_shutdown (); | ||
1117 | ret = -1; | ||
1118 | return; | ||
1119 | } | ||
1120 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 1098 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
1121 | (void *) cfg); | 1099 | (void *) cfg); |
1122 | 1100 | ||
@@ -1126,7 +1104,8 @@ testservice_id_task (void *cls, int result) | |||
1126 | &id_connect_cb, | 1104 | &id_connect_cb, |
1127 | (void *) cfg); | 1105 | (void *) cfg); |
1128 | if (NULL == idh) | 1106 | if (NULL == idh) |
1129 | fprintf (stderr, _("Cannot connect to identity service\n")); | 1107 | fprintf (stderr, |
1108 | _("Cannot connect to identity service\n")); | ||
1130 | ret = -1; | 1109 | ret = -1; |
1131 | return; | 1110 | return; |
1132 | } | 1111 | } |
@@ -1138,30 +1117,6 @@ testservice_id_task (void *cls, int result) | |||
1138 | 1117 | ||
1139 | 1118 | ||
1140 | /** | 1119 | /** |
1141 | * Main function that will be run. | ||
1142 | * | ||
1143 | * @param cls closure | ||
1144 | * @param args remaining command-line arguments | ||
1145 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
1146 | * @param cfg configuration | ||
1147 | */ | ||
1148 | static void | ||
1149 | run (void *cls, | ||
1150 | char *const *args, | ||
1151 | const char *cfgfile, | ||
1152 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
1153 | { | ||
1154 | if ( (NULL != args[0]) && (NULL == uri) ) | ||
1155 | uri = GNUNET_strdup (args[0]); | ||
1156 | |||
1157 | GNUNET_CLIENT_service_test ("identity", cfg, | ||
1158 | GNUNET_TIME_UNIT_SECONDS, | ||
1159 | &testservice_id_task, | ||
1160 | (void *) cfg); | ||
1161 | } | ||
1162 | |||
1163 | |||
1164 | /** | ||
1165 | * The main function for gnunet-namestore. | 1120 | * The main function for gnunet-namestore. |
1166 | * | 1121 | * |
1167 | * @param argc number of arguments from the command line | 1122 | * @param argc number of arguments from the command line |
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index 58ab46ca9..0d36cf445 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -967,22 +967,22 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
967 | allow_methods); | 967 | allow_methods); |
968 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 968 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
969 | cleanup_handle (handle); | 969 | cleanup_handle (handle); |
970 | return; | ||
971 | } | 970 | } |
972 | 971 | ||
972 | |||
973 | /** | 973 | /** |
974 | * Function called with the result from the check if the namestore | 974 | * Callback invoked from identity service with ego information. |
975 | * service is actually running. If it is, we start the actual | 975 | * An @a ego of NULL means the ego was not found. |
976 | * operation. | ||
977 | * | 976 | * |
978 | * @param cls closure with our configuration | 977 | * @param cls closure with the configuration |
979 | * @param result #GNUNET_YES if the namestore service is running | 978 | * @param ego an ego known to identity service, or NULL |
980 | */ | 979 | */ |
981 | static void | 980 | static void |
982 | testservice_task (void *cls, | 981 | identity_cb (void *cls, |
983 | int result) | 982 | const struct GNUNET_IDENTITY_Ego *ego) |
984 | { | 983 | { |
985 | struct RequestHandle *handle = cls; | 984 | struct RequestHandle *handle = cls; |
985 | struct MHD_Response *resp; | ||
986 | struct GNUNET_REST_RequestHandlerError err; | 986 | struct GNUNET_REST_RequestHandlerError err; |
987 | static const struct GNUNET_REST_RequestHandler handlers[] = { | 987 | static const struct GNUNET_REST_RequestHandler handlers[] = { |
988 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse | 988 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse |
@@ -994,13 +994,21 @@ testservice_task (void *cls, | |||
994 | GNUNET_REST_HANDLER_END | 994 | GNUNET_REST_HANDLER_END |
995 | }; | 995 | }; |
996 | 996 | ||
997 | if (GNUNET_YES != result) | 997 | handle->ego_lookup = NULL; |
998 | if (NULL == ego) | ||
998 | { | 999 | { |
999 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Service `%s' is not running\n"), | 1000 | if (NULL != handle->ego_name) |
1000 | "namestore"); | 1001 | { |
1001 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1002 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1003 | _("Ego `%s' not known to identity service\n"), | ||
1004 | handle->ego_name); | ||
1005 | } | ||
1006 | resp = GNUNET_REST_create_response (NULL); | ||
1007 | handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); | ||
1008 | cleanup_handle (handle); | ||
1002 | return; | 1009 | return; |
1003 | } | 1010 | } |
1011 | handle->zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
1004 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); | 1012 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); |
1005 | if (NULL == handle->ns_handle) | 1013 | if (NULL == handle->ns_handle) |
1006 | { | 1014 | { |
@@ -1010,51 +1018,18 @@ testservice_task (void *cls, | |||
1010 | return; | 1018 | return; |
1011 | } | 1019 | } |
1012 | 1020 | ||
1013 | if (GNUNET_OK != GNUNET_JSONAPI_handle_request (handle->rest_handle, | 1021 | if (GNUNET_OK != |
1014 | handlers, | 1022 | GNUNET_JSONAPI_handle_request (handle->rest_handle, |
1015 | &err, | 1023 | handlers, |
1016 | handle)) | 1024 | &err, |
1025 | handle)) | ||
1017 | { | 1026 | { |
1018 | handle->response_code = err.error_code; | 1027 | handle->response_code = err.error_code; |
1019 | GNUNET_SCHEDULER_add_now (&do_error, (void*) handle); | 1028 | GNUNET_SCHEDULER_add_now (&do_error, |
1029 | (void *) handle); | ||
1020 | } | 1030 | } |
1021 | |||
1022 | } | 1031 | } |
1023 | 1032 | ||
1024 | /** | ||
1025 | * Callback invoked from identity service with ego information. | ||
1026 | * An @a ego of NULL means the ego was not found. | ||
1027 | * | ||
1028 | * @param cls closure with the configuration | ||
1029 | * @param ego an ego known to identity service, or NULL | ||
1030 | */ | ||
1031 | static void | ||
1032 | identity_cb (void *cls, | ||
1033 | const struct GNUNET_IDENTITY_Ego *ego) | ||
1034 | { | ||
1035 | struct RequestHandle *handle = cls; | ||
1036 | struct MHD_Response *resp; | ||
1037 | |||
1038 | handle->ego_lookup = NULL; | ||
1039 | if (NULL == ego) | ||
1040 | { | ||
1041 | if (NULL != handle->ego_name) | ||
1042 | { | ||
1043 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1044 | _("Ego `%s' not known to identity service\n"), | ||
1045 | handle->ego_name); | ||
1046 | } | ||
1047 | resp = GNUNET_REST_create_response (NULL); | ||
1048 | handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); | ||
1049 | cleanup_handle (handle); | ||
1050 | return; | ||
1051 | } | ||
1052 | handle->zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
1053 | GNUNET_CLIENT_service_test ("namestore", handle->cfg, | ||
1054 | GNUNET_TIME_UNIT_SECONDS, | ||
1055 | &testservice_task, | ||
1056 | (void *) handle); | ||
1057 | } | ||
1058 | 1033 | ||
1059 | static void | 1034 | static void |
1060 | default_ego_cb (void *cls, | 1035 | default_ego_cb (void *cls, |
@@ -1095,25 +1070,40 @@ id_connect_cb (void *cls, | |||
1095 | } | 1070 | } |
1096 | } | 1071 | } |
1097 | 1072 | ||
1073 | |||
1074 | /** | ||
1075 | * Function processing the REST call | ||
1076 | * | ||
1077 | * @param method HTTP method | ||
1078 | * @param url URL of the HTTP request | ||
1079 | * @param data body of the HTTP request (optional) | ||
1080 | * @param data_size length of the body | ||
1081 | * @param proc callback function for the result | ||
1082 | * @param proc_cls closure for callback function | ||
1083 | * @return #GNUNET_OK if request accepted | ||
1084 | */ | ||
1098 | static void | 1085 | static void |
1099 | testservice_id_task (void *cls, int result) | 1086 | rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, |
1087 | GNUNET_REST_ResultProcessor proc, | ||
1088 | void *proc_cls) | ||
1100 | { | 1089 | { |
1101 | struct RequestHandle *handle = cls; | 1090 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
1102 | struct MHD_Response *resp; | 1091 | struct MHD_Response *resp; |
1103 | struct GNUNET_HashCode key; | 1092 | struct GNUNET_HashCode key; |
1104 | char *ego; | 1093 | char *ego; |
1105 | char *name; | 1094 | char *name; |
1106 | char *type; | 1095 | char *type; |
1107 | 1096 | ||
1108 | if (result != GNUNET_YES) | 1097 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
1109 | { | 1098 | handle->proc_cls = proc_cls; |
1110 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1099 | handle->proc = proc; |
1111 | _("Identity service is not running\n")); | 1100 | handle->rest_handle = rest_handle; |
1112 | resp = GNUNET_REST_create_response (NULL); | 1101 | handle->url = GNUNET_strdup (rest_handle->url); |
1113 | handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); | 1102 | if (handle->url[strlen (handle->url)-1] == '/') |
1114 | cleanup_handle (handle); | 1103 | handle->url[strlen (handle->url)-1] = '\0'; |
1115 | return; | 1104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1116 | } | 1105 | "Connecting...\n"); |
1106 | handle->cfg = cfg; | ||
1117 | ego = NULL; | 1107 | ego = NULL; |
1118 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_EGO, | 1108 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_EGO, |
1119 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO), | 1109 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO), |
@@ -1160,41 +1150,6 @@ testservice_id_task (void *cls, int result) | |||
1160 | handle->ego_name, | 1150 | handle->ego_name, |
1161 | &identity_cb, | 1151 | &identity_cb, |
1162 | handle); | 1152 | handle); |
1163 | } | ||
1164 | |||
1165 | /** | ||
1166 | * Function processing the REST call | ||
1167 | * | ||
1168 | * @param method HTTP method | ||
1169 | * @param url URL of the HTTP request | ||
1170 | * @param data body of the HTTP request (optional) | ||
1171 | * @param data_size length of the body | ||
1172 | * @param proc callback function for the result | ||
1173 | * @param proc_cls closure for callback function | ||
1174 | * @return GNUNET_OK if request accepted | ||
1175 | */ | ||
1176 | static void | ||
1177 | rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | ||
1178 | GNUNET_REST_ResultProcessor proc, | ||
1179 | void *proc_cls) | ||
1180 | { | ||
1181 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | ||
1182 | |||
1183 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | ||
1184 | handle->proc_cls = proc_cls; | ||
1185 | handle->proc = proc; | ||
1186 | handle->rest_handle = rest_handle; | ||
1187 | handle->url = GNUNET_strdup (rest_handle->url); | ||
1188 | if (handle->url[strlen (handle->url)-1] == '/') | ||
1189 | handle->url[strlen (handle->url)-1] = '\0'; | ||
1190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1191 | "Connecting...\n"); | ||
1192 | handle->cfg = cfg; | ||
1193 | GNUNET_CLIENT_service_test ("identity", | ||
1194 | cfg, | ||
1195 | GNUNET_TIME_UNIT_SECONDS, | ||
1196 | &testservice_id_task, | ||
1197 | handle); | ||
1198 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, | 1153 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, |
1199 | &do_timeout, | 1154 | &do_timeout, |
1200 | handle); | 1155 | handle); |