2021-10-06 21:38:15 +02:00
|
|
|
|
// swad_plugin_database.c: plugins called from SWAD using web services, operations with database
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
SWAD (Shared Workspace At a Distance),
|
|
|
|
|
is a web platform developed at the University of Granada (Spain),
|
|
|
|
|
and used to support university teaching.
|
|
|
|
|
|
|
|
|
|
This file is part of SWAD core.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2021-10-06 21:38:15 +02:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program 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 Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************************* Headers ***********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "swad_database.h"
|
|
|
|
|
#include "swad_plugin_database.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Create a new plugin ***************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2022-10-19 18:07:49 +02:00
|
|
|
|
void Plg_DB_CreatePlugin (const struct Plg_Plugin *Plg)
|
2021-10-06 21:38:15 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryINSERT ("can not create plugin",
|
|
|
|
|
"INSERT INTO plg_plugins"
|
|
|
|
|
" (Name,Description,Logo,AppKey,URL,IP)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" ('%s','%s','%s','%s','%s','%s')",
|
|
|
|
|
Plg->Name,
|
|
|
|
|
Plg->Description,
|
|
|
|
|
Plg->Logo,
|
|
|
|
|
Plg->AppKey,
|
|
|
|
|
Plg->URL,
|
|
|
|
|
Plg->IP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Rename a plugin *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plg_DB_ChangeName (long PlgCod,
|
|
|
|
|
const char NewPlgName[Plg_MAX_BYTES_PLUGIN_NAME + 1])
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update the name of a plugin",
|
|
|
|
|
"UPDATE plg_plugins"
|
|
|
|
|
" SET Name='%s'"
|
|
|
|
|
" WHERE PlgCod=%ld",
|
|
|
|
|
NewPlgName,
|
|
|
|
|
PlgCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Change the description of a plugin **********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plg_DB_ChangeDescription (long PlgCod,
|
|
|
|
|
const char NewDescription[Plg_MAX_BYTES_PLUGIN_DESCRIPTION + 1])
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update the description of a plugin",
|
|
|
|
|
"UPDATE plg_plugins"
|
|
|
|
|
" SET Description='%s'"
|
|
|
|
|
" WHERE PlgCod=%ld",
|
|
|
|
|
NewDescription,
|
|
|
|
|
PlgCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*********************** Change the logo of a plugin *************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plg_DB_ChangeLogo (long PlgCod,
|
|
|
|
|
const char NewLogo[Plg_MAX_BYTES_PLUGIN_LOGO + 1])
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update the logo of a plugin",
|
|
|
|
|
"UPDATE plg_plugins"
|
|
|
|
|
" SET Logo='%s'"
|
|
|
|
|
" WHERE PlgCod=%ld",
|
|
|
|
|
NewLogo,
|
|
|
|
|
PlgCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************** Change the application key of a plugin ********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plg_DB_ChangeAppKey (long PlgCod,
|
|
|
|
|
const char NewAppKey[Plg_MAX_BYTES_PLUGIN_APP_KEY + 1])
|
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update the application key of a plugin",
|
|
|
|
|
"UPDATE plg_plugins"
|
|
|
|
|
" SET AppKey='%s'"
|
|
|
|
|
" WHERE PlgCod=%ld",
|
|
|
|
|
NewAppKey,
|
|
|
|
|
PlgCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Change the URL of a plugin ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plg_DB_ChangeURL (long PlgCod,
|
2024-04-23 23:54:23 +02:00
|
|
|
|
const char NewURL[WWW_MAX_BYTES_WWW + 1])
|
2021-10-06 21:38:15 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update the URL of a plugin",
|
|
|
|
|
"UPDATE plg_plugins"
|
|
|
|
|
" SET URL='%s'"
|
|
|
|
|
" WHERE PlgCod=%ld",
|
|
|
|
|
NewURL,
|
|
|
|
|
PlgCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Change the IP of a plugin ************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plg_DB_ChangeIP (long PlgCod,
|
2022-10-28 00:43:48 +02:00
|
|
|
|
const char NewIP[Cns_MAX_BYTES_IP + 1])
|
2021-10-06 21:38:15 +02:00
|
|
|
|
{
|
|
|
|
|
DB_QueryUPDATE ("can not update the IP address of a plugin",
|
|
|
|
|
"UPDATE plg_plugins"
|
|
|
|
|
" SET IP='%s'"
|
|
|
|
|
" WHERE PlgCod=%ld",
|
|
|
|
|
NewIP,
|
|
|
|
|
PlgCod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************* Get list of current plugins ***********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Plg_DB_GetListPlugins (MYSQL_RES **mysql_res)
|
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get plugins",
|
|
|
|
|
"SELECT PlgCod," // row[0]
|
|
|
|
|
"Name," // row[1]
|
|
|
|
|
"Description," // row[2]
|
|
|
|
|
"Logo," // row[3]
|
|
|
|
|
"AppKey," // row[4]
|
|
|
|
|
"URL," // row[5]
|
|
|
|
|
"IP" // row[6]
|
|
|
|
|
" FROM plg_plugins"
|
|
|
|
|
" ORDER BY Name");
|
|
|
|
|
}
|
2021-11-07 21:15:48 +01:00
|
|
|
|
|
2021-10-06 21:38:15 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/*************************** Get data of a plugin ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-03-23 09:35:20 +01:00
|
|
|
|
unsigned Plg_DB_GetPluginDataByCod (MYSQL_RES **mysql_res,long PlgCod)
|
2021-10-06 21:38:15 +02:00
|
|
|
|
{
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get data of a plugin",
|
2023-03-23 19:13:34 +01:00
|
|
|
|
"SELECT PlgCod," // row[0]
|
|
|
|
|
"Name," // row[1]
|
|
|
|
|
"Description," // row[2]
|
|
|
|
|
"Logo," // row[3]
|
|
|
|
|
"AppKey," // row[4]
|
|
|
|
|
"URL," // row[5]
|
|
|
|
|
"IP" // row[6]
|
2021-10-06 21:38:15 +02:00
|
|
|
|
" FROM plg_plugins"
|
|
|
|
|
" WHERE PlgCod=%ld",
|
|
|
|
|
PlgCod);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-07 21:15:48 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****** Check if the application key of the requester of a web service *******/
|
|
|
|
|
/****** is one of the application keys allowed in the plugins *******/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
long Plg_DB_GetPlgCodFromAppKey (const char *AppKey)
|
|
|
|
|
{
|
|
|
|
|
return DB_QuerySELECTCode ("can not check application key",
|
|
|
|
|
"SELECT PlgCod"
|
|
|
|
|
" FROM plg_plugins"
|
|
|
|
|
" WHERE AppKey='%s'",
|
|
|
|
|
AppKey);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 21:38:15 +02:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************** Check if the name of plugin exists *********************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
bool Plg_DB_CheckIfPluginNameExists (const char *Name,long PlgCod)
|
|
|
|
|
{
|
2021-11-05 23:41:26 +01:00
|
|
|
|
return
|
|
|
|
|
DB_QueryEXISTS ("can not check if the name of a plugin already existed",
|
|
|
|
|
"SELECT EXISTS"
|
|
|
|
|
"(SELECT *"
|
|
|
|
|
" FROM plg_plugins"
|
|
|
|
|
" WHERE Name='%s'"
|
|
|
|
|
" AND PlgCod<>%ld)",
|
|
|
|
|
Name,
|
|
|
|
|
PlgCod);
|
2021-10-06 21:38:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Remove a plugin *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Plg_DB_RemovePlugin (long PlgCod)
|
|
|
|
|
{
|
|
|
|
|
DB_QueryDELETE ("can not remove a plugin",
|
|
|
|
|
"DELETE FROM plg_plugins"
|
|
|
|
|
" WHERE PlgCod=%ld",
|
|
|
|
|
PlgCod);
|
|
|
|
|
}
|