-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathups.c
78 lines (68 loc) · 4.8 KB
/
ups.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/******************************************************************************************************************************/
/* ups.c Gestion des ups dans l'API HTTP WebService */
/* Projet Abls-Habitat version 4.3 Gestion d'habitat 19.06.2022 09:24:49 */
/* Auteur: LEFEVRE Sebastien */
/******************************************************************************************************************************/
/*
* ups.c
* This file is part of Abls-Habitat
*
* Copyright (C) 1988-2024 - Sebastien LEFEVRE
*
* Watchdog is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Watchdog is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Watchdog; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/************************************************** Prototypes de fonctions ***************************************************/
#include "Http.h"
extern struct GLOBAL Global; /* Configuration de l'API */
/******************************************************************************************************************************/
/* UPS_SET_request_post: Appelé depuis libsoup pour éditer ou creer un ups */
/* Entrée: Les paramètres libsoup */
/* Sortie: néant */
/******************************************************************************************************************************/
void UPS_SET_request_post ( struct DOMAIN *domain, JsonNode *token, const char *path, SoupServerMessage *msg, JsonNode *request )
{ gboolean retour;
if (!Http_is_authorized ( domain, token, path, msg, 6 )) return;
Http_print_request ( domain, token, path );
if (Http_fail_if_has_not ( domain, path, msg, request, "agent_uuid" )) return;
if (Http_fail_if_has_not ( domain, path, msg, request, "thread_tech_id" )) return;
if (Http_fail_if_has_not ( domain, path, msg, request, "host" )) return;
if (Http_fail_if_has_not ( domain, path, msg, request, "name" )) return;
if (Http_fail_if_has_not ( domain, path, msg, request, "admin_username" )) return;
if (Http_fail_if_has_not ( domain, path, msg, request, "admin_password" )) return;
gchar *agent_uuid = Normaliser_chaine ( Json_get_string( request, "agent_uuid" ) );
gchar *thread_tech_id = Normaliser_chaine ( Json_get_string( request, "thread_tech_id" ) );
gchar *host = Normaliser_chaine ( Json_get_string( request, "host" ) );
gchar *name = Normaliser_chaine ( Json_get_string( request, "name" ) );
gchar *admin_username = Normaliser_chaine ( Json_get_string( request, "admin_username" ) );
gchar *admin_password = Normaliser_chaine ( Json_get_string( request, "admin_password" ) );
retour = DB_Write ( domain,
"INSERT INTO ups SET agent_uuid='%s', thread_tech_id=UPPER('%s'), "
"host='%s', name='%s', admin_username='%s', admin_password='%s' "
"ON DUPLICATE KEY UPDATE agent_uuid=VALUES(agent_uuid), "
"host=VALUES(host), name=VALUES(name), admin_username=VALUES(admin_username), admin_password=VALUES(admin_password) ",
agent_uuid, thread_tech_id, host, name, admin_username, admin_password );
g_free(agent_uuid);
g_free(thread_tech_id);
g_free(host);
g_free(name);
g_free(admin_username);
g_free(admin_password);
if (!retour) { Http_Send_json_response ( msg, retour, domain->mysql_last_error, NULL ); return; }
Json_node_add_string ( request, "thread_classe", "ups" );
MQTT_Send_to_domain ( domain, "agents", "THREAD_RESTART", request ); /* Stop sent to all agents */
Http_Send_json_response ( msg, SOUP_STATUS_OK, "Thread changed", NULL );
}
/*----------------------------------------------------------------------------------------------------------------------------*/