From 54ae1a1be32607b20e4994dd123fe016f7636232 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?=
Date: Mon, 24 Feb 2020 19:31:55 +0100
Subject: [PATCH] Version19.131
---
Makefile | 2 +-
swad_API.c | 1004 ++++++++++++++++++++++++++++++----------------
swad_API.h | 1 +
swad_changelog.h | 3 +-
swad_database.c | 11 +-
swad_global.h | 2 -
swad_info.c | 172 +-------
swad_info.h | 7 +-
swad_syllabus.c | 274 +++++--------
swad_syllabus.h | 11 +-
10 files changed, 793 insertions(+), 694 deletions(-)
diff --git a/Makefile b/Makefile
index 74fb67da..e1a130d1 100644
--- a/Makefile
+++ b/Makefile
@@ -72,7 +72,7 @@ CC = gcc
# LIBS when using MariaDB (also valid with MySQL):
LIBS = -lssl -lcrypto -lpthread -lrt -lmysqlclient -lz -L/usr/lib64/mysql -lm -lgsoap
-CFLAGS = -Wall -Wextra -mtune=native -O2 -s
+CFLAGS = -Wall -Wextra -mtune=native -O2
all: swad_ca swad_de swad_en swad_es swad_fr swad_gn swad_it swad_pl swad_pt
diff --git a/swad_API.c b/swad_API.c
index e20ff30d..3a4f3639 100644
--- a/swad_API.c
+++ b/swad_API.c
@@ -201,22 +201,24 @@ static const API_Role_t API_RolRole_to_SvcRole[Rol_NUM_ROLES] =
#define API_BYTES_WS_KEY Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64
-/*****************************************************************************/
-/********************************* Data types ********************************/
-/*****************************************************************************/
-
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
-static int API_GetPlgCodFromAppKey (const char *appKey);
-static int API_CheckIdSession (const char *IdSession);
+static void API_Set_gSOAP_RuntimeEnv (struct soap *soap);
+
+static int API_GetPlgCodFromAppKey (struct soap *soap,
+ const char *appKey);
+static int API_CheckIdSession (struct soap *soap,
+ const char *IdSession);
static int API_CheckWSKey (char WSKey[API_BYTES_WS_KEY + 1]);
-static int API_CheckCourseAndGroupCodes (long CrsCod,long GrpCod);
-static int API_GenerateNewWSKey (long UsrCod,
+static int API_CheckCourseAndGroupCodes (struct soap *soap,
+ long CrsCod,long GrpCod);
+static int API_GenerateNewWSKey (struct soap *soap,
+ long UsrCod,
char WSKey[API_BYTES_WS_KEY + 1]);
-static int API_RemoveOldWSKeys (void);
+static int API_RemoveOldWSKeys (struct soap *soap);
static int API_GetCurrentDegCodFromCurrentCrsCod (void);
static bool API_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod);
@@ -226,24 +228,44 @@ static int API_CheckParamsNewAccount (char *NewNicknameWithArroba, // Input
char *NewPlainPassword, // Input
char *NewEncryptedPassword); // Output
-static void API_CopyListUsers (Rol_Role_t Role,struct swad__getUsersOutput *getUsersOut);
-static void API_CopyUsrData (struct swad__user *Usr,struct UsrData *UsrDat,bool UsrIDIsVisible);
+static int API_WriteSyllabusIntoHTMLBuffer (struct soap *soap,
+ char **HTMLBuffer);
+static int API_WritePlainTextIntoHTMLBuffer (struct soap *soap,
+ char **HTMLBuffer);
+static int API_WritePageIntoHTMLBuffer (struct soap *soap,
+ char **HTMLBuffer);
-static void API_GetListGrpsInAttendanceEventFromDB (long AttCod,char **ListGroups);
+static void API_CopyListUsers (struct soap *soap,
+ Rol_Role_t Role,
+ struct swad__getUsersOutput *getUsersOut);
+static void API_CopyUsrData (struct soap *soap,
+ struct swad__user *Usr,struct UsrData *UsrDat,
+ bool UsrIDIsVisible);
+
+static void API_GetListGrpsInAttendanceEventFromDB (struct soap *soap,
+ long AttCod,char **ListGroups);
static void API_GetLstGrpsSel (const char *Groups);
-static int API_GetMyLanguage (void);
+static int API_GetMyLanguage (struct soap *soap);
static int API_SendMessageToUsr (long OriginalMsgCod,long SenderUsrCod,long ReplyUsrCod,long RecipientUsrCod,bool NotifyByEmail,const char *Subject,const char *Content);
static int API_GetTstConfig (long CrsCod);
static int API_GetNumTestQuestionsInCrs (long CrsCod);
-static int API_GetTstTags (long CrsCod,struct swad__getTestsOutput *getTestsOut);
-static int API_GetTstQuestions (long CrsCod,long BeginTime,struct swad__getTestsOutput *getTestsOut);
-static int API_GetTstAnswers (long CrsCod,long BeginTime,struct swad__getTestsOutput *getTestsOut);
-static int API_GetTstQuestionTags (long CrsCod,long BeginTime,struct swad__getTestsOutput *getTestsOut);
+static int API_GetTstTags (struct soap *soap,
+ long CrsCod,struct swad__getTestsOutput *getTestsOut);
+static int API_GetTstQuestions (struct soap *soap,
+ long CrsCod,long BeginTime,
+ struct swad__getTestsOutput *getTestsOut);
+static int API_GetTstAnswers (struct soap *soap,
+ long CrsCod,long BeginTime,
+ struct swad__getTestsOutput *getTestsOut);
+static int API_GetTstQuestionTags (struct soap *soap,
+ long CrsCod,long BeginTime,
+ struct swad__getTestsOutput *getTestsOut);
-static void API_GetListGrpsInGameFromDB (long MchCod,char **ListGroups);
+static void API_GetListGrpsInGameFromDB (struct soap *soap,
+ long MchCod,char **ListGroups);
static void API_ListDir (unsigned Level,const char *Path,const char *PathInTree);
static bool API_WriteRowFileBrowser (unsigned Level,Brw_FileType_t FileType,const char *FileName);
@@ -253,6 +275,22 @@ static void API_IndentXMLLine (unsigned Level);
/******* Function called when a web service if required by a plugin **********/
/*****************************************************************************/
+static struct soap *API_soap = NULL; // gSOAP runtime environment
+
+static void API_Set_gSOAP_RuntimeEnv (struct soap *soap)
+ {
+ API_soap = soap;
+ }
+
+struct soap *API_Get_gSOAP_RuntimeEnv (void)
+ {
+ return API_soap;
+ }
+
+/*****************************************************************************/
+/******* Function called when a web service if required by a plugin **********/
+/*****************************************************************************/
+
void API_WebService (void)
{
struct soap *soap;
@@ -272,13 +310,19 @@ void API_WebService (void)
void API_Exit (const char *DetailErrorMessage)
{
- int ReturnCode = (DetailErrorMessage ? soap_receiver_fault (Gbl.soap,
- "Error in swad web service",
- DetailErrorMessage) :
- 0);
+ struct soap *soap = API_Get_gSOAP_RuntimeEnv ();
+ int ReturnCode = 0;
- soap_end (Gbl.soap); // Clean up and remove deserialized data
- soap_free (Gbl.soap); // Detach and free runtime context
+ if (soap)
+ {
+ ReturnCode = (DetailErrorMessage ? soap_receiver_fault (soap,
+ "Error in swad web service",
+ DetailErrorMessage) :
+ 0);
+
+ soap_end (soap); // Clean up and remove deserialized data
+ soap_free (soap); // Detach and free runtime context
+ }
exit (ReturnCode);
}
@@ -288,7 +332,8 @@ void API_Exit (const char *DetailErrorMessage)
/****** is one of the application keys allowed in the plugins *******/
/*****************************************************************************/
-static int API_GetPlgCodFromAppKey (const char *appKey)
+static int API_GetPlgCodFromAppKey (struct soap *soap,
+ const char *appKey)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
@@ -309,7 +354,7 @@ static int API_GetPlgCodFromAppKey (const char *appKey)
DB_FreeMySQLResult (&mysql_res);
if (Gbl.WebService.PlgCod < 0)
- return soap_sender_fault (Gbl.soap,
+ return soap_sender_fault (soap,
"Unknown application key",
"Unknown application");
@@ -331,20 +376,21 @@ const char *API_GetFunctionNameFromFunCod (long FunCod)
/****** Check if a session identifier is valid and exists in database ********/
/*****************************************************************************/
-static int API_CheckIdSession (const char *IdSession)
+static int API_CheckIdSession (struct soap *soap,
+ const char *IdSession)
{
const char *Ptr;
unsigned i;
/***** Check if pointer is NULL *****/
if (IdSession == NULL)
- return soap_sender_fault (Gbl.soap,
+ return soap_sender_fault (soap,
"Bad session identifier",
"Session identifier is a null pointer");
/***** Check length of session identifier *****/
if (strlen (IdSession) != Cns_BYTES_SESSION_ID)
- return soap_sender_fault (Gbl.soap,
+ return soap_sender_fault (soap,
"Bad session identifier",
"The length of the session identifier is wrong");
@@ -359,7 +405,7 @@ static int API_CheckIdSession (const char *IdSession)
if (*Ptr == Str_BIN_TO_BASE64URL[i])
break;
if (i == 64) // Character not found
- return soap_sender_fault (Gbl.soap,
+ return soap_sender_fault (soap,
"Bad session identifier",
"The session identifier must contain only base64url characters");
}
@@ -369,7 +415,7 @@ static int API_CheckIdSession (const char *IdSession)
"SELECT COUNT(*) FROM sessions"
" WHERE SessionId='%s'",
IdSession) != 1)
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Bad session identifier",
"Session identifier does not exist in database");
@@ -412,11 +458,12 @@ static int API_CheckWSKey (char WSKey[API_BYTES_WS_KEY + 1])
/** Check if a course code and a group code are valid and exist in database **/
/*****************************************************************************/
-static int API_CheckCourseAndGroupCodes (long CrsCod,long GrpCod)
+static int API_CheckCourseAndGroupCodes (struct soap *soap,
+ long CrsCod,long GrpCod)
{
/***** Check if course code is correct *****/
if (CrsCod <= 0)
- return soap_sender_fault (Gbl.soap,
+ return soap_sender_fault (soap,
"Bad course code",
"Course code must be a integer greater than 0");
@@ -425,7 +472,7 @@ static int API_CheckCourseAndGroupCodes (long CrsCod,long GrpCod)
"SELECT COUNT(*) FROM courses"
" WHERE CrsCod=%ld",
CrsCod) != 1)
- return soap_sender_fault (Gbl.soap,
+ return soap_sender_fault (soap,
"Bad course code",
"Course code does not exist in database");
@@ -439,7 +486,7 @@ static int API_CheckCourseAndGroupCodes (long CrsCod,long GrpCod)
" AND crs_grp_types.GrpTypCod=crs_grp.GrpTypCod"
" AND crs_grp.GrpCod=%ld",
CrsCod,GrpCod) != 1)
- return soap_sender_fault (Gbl.soap,
+ return soap_sender_fault (soap,
"Bad group code",
"Group code does not exist in database or it's not a group of the specified course");
}
@@ -451,13 +498,14 @@ static int API_CheckCourseAndGroupCodes (long CrsCod,long GrpCod)
/***** Generate a key used in subsequents calls to other web services ********/
/*****************************************************************************/
-static int API_GenerateNewWSKey (long UsrCod,
+static int API_GenerateNewWSKey (struct soap *soap,
+ long UsrCod,
char WSKey[API_BYTES_WS_KEY + 1])
{
int ReturnCode;
/***** Remove expired web service keys *****/
- if ((ReturnCode = API_RemoveOldWSKeys ()) != SOAP_OK)
+ if ((ReturnCode = API_RemoveOldWSKeys (soap)) != SOAP_OK)
return ReturnCode;
/***** Create a unique name for the key *****/
@@ -469,7 +517,7 @@ static int API_GenerateNewWSKey (long UsrCod,
"SELECT COUNT(*) FROM ws_keys"
" WHERE WSKey='%s'",
WSKey))
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Error when generating key",
"Generated key already existed in database");
@@ -488,7 +536,7 @@ static int API_GenerateNewWSKey (long UsrCod,
/************************ Remove old web service keys ************************/
/*****************************************************************************/
-static int API_RemoveOldWSKeys (void)
+static int API_RemoveOldWSKeys (struct soap *soap)
{
char Query[512];
@@ -499,7 +547,7 @@ static int API_RemoveOldWSKeys (void)
" WHERE LastTimewsKey = (char *) soap_malloc (Gbl.soap,API_BYTES_WS_KEY + 1);
+ createAccountOut->wsKey = (char *) soap_malloc (soap,API_BYTES_WS_KEY + 1);
/***** Default values returned on error *****/
createAccountOut->userCode = 0; // Undefined error
createAccountOut->wsKey[0] = '\0';
/***** Get plugin code *****/
- if ((ReturnCode = API_GetPlgCodFromAppKey ((const char *) appKey)) != SOAP_OK)
+ if ((ReturnCode = API_GetPlgCodFromAppKey (soap,(const char *) appKey)) != SOAP_OK)
return ReturnCode;
/***** Check parameters used to create the new account *****/
@@ -731,7 +779,8 @@ int swad__createAccount (struct soap *soap,
createAccountOut->userCode = Gbl.Usrs.Me.UsrDat.UsrCod;
/***** Generate a key used in subsequents calls to other web services *****/
- return API_GenerateNewWSKey ((long) createAccountOut->userCode,
+ return API_GenerateNewWSKey (soap,
+ (long) createAccountOut->userCode,
createAccountOut->wsKey);
}
@@ -803,18 +852,18 @@ int swad__loginByUserPasswordKey (struct soap *soap,
bool UsrFound;
/***** Initializations *****/
- Gbl.soap = soap;
+ API_Set_gSOAP_RuntimeEnv (soap);
Gbl.WebService.Function = API_loginByUserPasswordKey;
/***** Allocate space for strings *****/
- loginByUserPasswordKeyOut->wsKey = (char *) soap_malloc (Gbl.soap,API_BYTES_WS_KEY + 1);
- loginByUserPasswordKeyOut->userNickname = (char *) soap_malloc (Gbl.soap,Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1);
- loginByUserPasswordKeyOut->userID = (char *) soap_malloc (Gbl.soap,ID_MAX_BYTES_USR_ID + 1);
- loginByUserPasswordKeyOut->userFirstname = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
- loginByUserPasswordKeyOut->userSurname1 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
- loginByUserPasswordKeyOut->userSurname2 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
- loginByUserPasswordKeyOut->userPhoto = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_WWW + 1);
- loginByUserPasswordKeyOut->userBirthday = (char *) soap_malloc (Gbl.soap,Dat_LENGTH_YYYYMMDD + 1);
+ loginByUserPasswordKeyOut->wsKey = (char *) soap_malloc (soap,API_BYTES_WS_KEY + 1);
+ loginByUserPasswordKeyOut->userNickname = (char *) soap_malloc (soap,Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1);
+ loginByUserPasswordKeyOut->userID = (char *) soap_malloc (soap,ID_MAX_BYTES_USR_ID + 1);
+ loginByUserPasswordKeyOut->userFirstname = (char *) soap_malloc (soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
+ loginByUserPasswordKeyOut->userSurname1 = (char *) soap_malloc (soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
+ loginByUserPasswordKeyOut->userSurname2 = (char *) soap_malloc (soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
+ loginByUserPasswordKeyOut->userPhoto = (char *) soap_malloc (soap,Cns_MAX_BYTES_WWW + 1);
+ loginByUserPasswordKeyOut->userBirthday = (char *) soap_malloc (soap,Dat_LENGTH_YYYYMMDD + 1);
/***** Default values returned on error *****/
loginByUserPasswordKeyOut->userCode = -1;
@@ -829,7 +878,8 @@ int swad__loginByUserPasswordKey (struct soap *soap,
loginByUserPasswordKeyOut->userRole = 0; // unknown
/***** Get plugin code *****/
- if ((ReturnCode = API_GetPlgCodFromAppKey ((const char *) appKey)) != SOAP_OK)
+ if ((ReturnCode = API_GetPlgCodFromAppKey (soap,
+ (const char *) appKey)) != SOAP_OK)
return ReturnCode;
/***** Check if user's email, @nickname or ID are valid *****/
@@ -881,7 +931,7 @@ int swad__loginByUserPasswordKey (struct soap *soap,
UsrIDNickOrEmail,userPassword);
}
else // String is not a valid user's nickname, email or ID
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Bad log in",
"User's ID or nickname don't exist or password is wrong");
}
@@ -940,7 +990,8 @@ int swad__loginByUserPasswordKey (struct soap *soap,
loginByUserPasswordKeyOut->userRole = API_RolRole_to_SvcRole[Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role];
/***** Generate a key used in subsequents calls to other web services *****/
- return API_GenerateNewWSKey ((long) loginByUserPasswordKeyOut->userCode,
+ return API_GenerateNewWSKey (soap,
+ (long) loginByUserPasswordKeyOut->userCode,
loginByUserPasswordKeyOut->wsKey);
}
else
@@ -953,7 +1004,7 @@ int swad__loginByUserPasswordKey (struct soap *soap,
loginByUserPasswordKeyOut->userPhoto = NULL;
loginByUserPasswordKeyOut->userRole = 0;
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Bad log in",
"User's ID or nickname don't exist or password is wrong");
}
@@ -975,20 +1026,20 @@ int swad__loginBySessionKey (struct soap *soap,
bool UsrFound;
/***** Initializations *****/
- Gbl.soap = soap;
+ API_Set_gSOAP_RuntimeEnv (soap);
Gbl.WebService.Function = API_loginBySessionKey;
/***** Allocate space for strings *****/
- loginBySessionKeyOut->wsKey = (char *) soap_malloc (Gbl.soap,API_BYTES_WS_KEY + 1);
- loginBySessionKeyOut->userNickname = (char *) soap_malloc (Gbl.soap,Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1);
- loginBySessionKeyOut->userID = (char *) soap_malloc (Gbl.soap,ID_MAX_BYTES_USR_ID + 1);
- loginBySessionKeyOut->userFirstname = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
- loginBySessionKeyOut->userSurname1 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
- loginBySessionKeyOut->userSurname2 = (char *) soap_malloc (Gbl.soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
- loginBySessionKeyOut->userPhoto = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_WWW + 1);
- loginBySessionKeyOut->userBirthday = (char *) soap_malloc (Gbl.soap,Dat_LENGTH_YYYYMMDD + 1);
- loginBySessionKeyOut->degreeName = (char *) soap_malloc (Gbl.soap,Hie_MAX_BYTES_FULL_NAME + 1);
- loginBySessionKeyOut->courseName = (char *) soap_malloc (Gbl.soap,Hie_MAX_BYTES_FULL_NAME + 1);
+ loginBySessionKeyOut->wsKey = (char *) soap_malloc (soap,API_BYTES_WS_KEY + 1);
+ loginBySessionKeyOut->userNickname = (char *) soap_malloc (soap,Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1);
+ loginBySessionKeyOut->userID = (char *) soap_malloc (soap,ID_MAX_BYTES_USR_ID + 1);
+ loginBySessionKeyOut->userFirstname = (char *) soap_malloc (soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
+ loginBySessionKeyOut->userSurname1 = (char *) soap_malloc (soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
+ loginBySessionKeyOut->userSurname2 = (char *) soap_malloc (soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
+ loginBySessionKeyOut->userPhoto = (char *) soap_malloc (soap,Cns_MAX_BYTES_WWW + 1);
+ loginBySessionKeyOut->userBirthday = (char *) soap_malloc (soap,Dat_LENGTH_YYYYMMDD + 1);
+ loginBySessionKeyOut->degreeName = (char *) soap_malloc (soap,Hie_MAX_BYTES_FULL_NAME + 1);
+ loginBySessionKeyOut->courseName = (char *) soap_malloc (soap,Hie_MAX_BYTES_FULL_NAME + 1);
/***** Default values returned on error *****/
loginBySessionKeyOut->userCode = -1;
@@ -1007,17 +1058,18 @@ int swad__loginBySessionKey (struct soap *soap,
loginBySessionKeyOut->courseName[0] = '\0';
/***** Get plugin code *****/
- if ((ReturnCode = API_GetPlgCodFromAppKey ((const char *) appKey)) != SOAP_OK)
+ if ((ReturnCode = API_GetPlgCodFromAppKey (soap,
+ (const char *) appKey)) != SOAP_OK)
return ReturnCode;
/***** Check length of session identifier *****/
if (sessionID == NULL)
- return soap_sender_fault (Gbl.soap,
+ return soap_sender_fault (soap,
"SessionID is null",
"Login by session");
/***** Check session identifier coming from an external plugin *****/
- if ((ReturnCode = API_CheckIdSession (sessionID)) != SOAP_OK)
+ if ((ReturnCode = API_CheckIdSession (soap,sessionID)) != SOAP_OK)
return ReturnCode;
// Now, we know that sessionID is a valid session identifier
@@ -1095,11 +1147,12 @@ int swad__loginBySessionKey (struct soap *soap,
loginBySessionKeyOut->userRole = API_RolRole_to_SvcRole[Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role];
/***** Generate a key used in subsequents calls to other web services *****/
- return API_GenerateNewWSKey ((long) loginBySessionKeyOut->userCode,
+ return API_GenerateNewWSKey (soap,
+ (long) loginBySessionKeyOut->userCode,
loginBySessionKeyOut->wsKey);
}
else
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Bad session identifier",
"Session identifier does not exist in database");
}
@@ -1120,14 +1173,15 @@ int swad__getNewPassword (struct soap *soap,
char NewRandomPlainPassword[Pwd_MAX_BYTES_PLAIN_PASSWORD + 1];
/***** Initializations *****/
- Gbl.soap = soap;
+ API_Set_gSOAP_RuntimeEnv (soap);
Gbl.WebService.Function = API_getNewPassword;
/***** Default values returned on error *****/
getNewPasswordOut->success = 0; // error
/***** Get plugin code *****/
- if ((ReturnCode = API_GetPlgCodFromAppKey ((const char *) appKey)) != SOAP_OK)
+ if ((ReturnCode = API_GetPlgCodFromAppKey (soap,
+ (const char *) appKey)) != SOAP_OK)
return ReturnCode;
/***** Check if user's email, @nickname or ID are valid *****/
@@ -1170,7 +1224,7 @@ int swad__getNewPassword (struct soap *soap,
UsrIDNickOrEmail);
}
else // String is not a valid user's nickname, email or ID
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Bad log in",
"User's email, nickname or ID don't exist");
}
@@ -1215,20 +1269,20 @@ int swad__getCourses (struct soap *soap,
Rol_Role_t Role;
/***** Initializations *****/
- Gbl.soap = soap;
+ API_Set_gSOAP_RuntimeEnv (soap);
Gbl.WebService.Function = API_getCourses;
/***** Check web service key *****/
if ((ReturnCode = API_CheckWSKey (wsKey)) != SOAP_OK)
return ReturnCode;
if (Gbl.Usrs.Me.UsrDat.UsrCod < 0) // Web service key does not exist in database
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Bad web service key",
"Web service key does not exist in database");
/***** Get some of my data *****/
if (!API_GetSomeUsrDataFromUsrCod (&Gbl.Usrs.Me.UsrDat,-1L))
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Can not get user's data from database",
"User does not exist in database");
Gbl.Usrs.Me.Logged = true;
@@ -1254,7 +1308,7 @@ int swad__getCourses (struct soap *soap,
getCoursesOut->coursesArray.__ptr = NULL;
else // Courses found
{
- getCoursesOut->coursesArray.__ptr = soap_malloc (Gbl.soap,
+ getCoursesOut->coursesArray.__ptr = soap_malloc (soap,
(getCoursesOut->coursesArray.__size) *
sizeof (*(getCoursesOut->coursesArray.__ptr)));
@@ -1270,13 +1324,13 @@ int swad__getCourses (struct soap *soap,
/* Get course short name (row[1]) */
getCoursesOut->coursesArray.__ptr[NumRow].courseShortName =
- (char *) soap_malloc (Gbl.soap,Hie_MAX_BYTES_SHRT_NAME + 1);
+ (char *) soap_malloc (soap,Hie_MAX_BYTES_SHRT_NAME + 1);
Str_Copy (getCoursesOut->coursesArray.__ptr[NumRow].courseShortName,row[1],
Hie_MAX_BYTES_SHRT_NAME);
/* Get course full name (row[2]) */
getCoursesOut->coursesArray.__ptr[NumRow].courseFullName =
- (char *) soap_malloc (Gbl.soap,Hie_MAX_BYTES_FULL_NAME + 1);
+ (char *) soap_malloc (soap,Hie_MAX_BYTES_FULL_NAME + 1);
Str_Copy (getCoursesOut->coursesArray.__ptr[NumRow].courseFullName,row[2],
Hie_MAX_BYTES_FULL_NAME);
@@ -1330,7 +1384,7 @@ int swad__getCourseInfo (struct soap *soap,
};
/***** Initializations *****/
- Gbl.soap = soap;
+ API_Set_gSOAP_RuntimeEnv (soap);
Gbl.WebService.Function = API_getCourseInfo;
Gbl.Hierarchy.Crs.CrsCod = (long) courseCode;
@@ -1338,17 +1392,19 @@ int swad__getCourseInfo (struct soap *soap,
if ((ReturnCode = API_CheckWSKey (wsKey)) != SOAP_OK)
return ReturnCode;
if (Gbl.Usrs.Me.UsrDat.UsrCod < 0) // Web service key does not exist in database
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Bad web service key",
"Web service key does not exist in database");
/***** Check course and group codes *****/
- if ((ReturnCode = API_CheckCourseAndGroupCodes (Gbl.Hierarchy.Crs.CrsCod,-1L)) != SOAP_OK)
+ if ((ReturnCode = API_CheckCourseAndGroupCodes (soap,
+ Gbl.Hierarchy.Crs.CrsCod,
+ -1L)) != SOAP_OK)
return ReturnCode;
/***** Get some of my data *****/
if (!API_GetSomeUsrDataFromUsrCod (&Gbl.Usrs.Me.UsrDat,Gbl.Hierarchy.Crs.CrsCod))
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Can not get user's data from database",
"User does not exist in database");
Gbl.Usrs.Me.Logged = true;
@@ -1358,7 +1414,7 @@ int swad__getCourseInfo (struct soap *soap,
if (Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role != Rol_STD &&
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role != Rol_NET &&
Gbl.Usrs.Me.UsrDat.Roles.InCurrentCrs.Role != Rol_TCH)
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Request forbidden",
"Requester must belong to course");
@@ -1369,13 +1425,13 @@ int swad__getCourseInfo (struct soap *soap,
if (!strcmp (infoType,NamesInWSForInfoType[InfoType]))
break;
if (InfoType == Inf_NUM_INFO_TYPES) // Not found!
- return soap_receiver_fault (Gbl.soap,
+ return soap_receiver_fault (soap,
"Bad info type",
"Unknown requested info type");
Gbl.Crs.Info.Type = InfoType;
Inf_GetAndCheckInfoSrcFromDB (Gbl.Hierarchy.Crs.CrsCod,Gbl.Crs.Info.Type,&InfoSrc,&MustBeRead);
Length = strlen (NamesInWSForInfoSrc[InfoSrc]);
- getCourseInfo->infoSrc = (char *) soap_malloc (Gbl.soap,Length + 1);
+ getCourseInfo->infoSrc = (char *) soap_malloc (soap,Length + 1);
Str_Copy (getCourseInfo->infoSrc,NamesInWSForInfoSrc[InfoSrc],
Length);
@@ -1393,7 +1449,7 @@ int swad__getCourseInfo (struct soap *soap,
{
case Inf_LECTURES: // Syllabus (lectures)
case Inf_PRACTICALS: // Syllabys (practicals)
- Result = Syl_WriteSyllabusIntoHTMLBuffer (&(getCourseInfo->infoTxt));
+ Result = API_WriteSyllabusIntoHTMLBuffer (soap,&(getCourseInfo->infoTxt));
break;
default:
break;
@@ -1401,13 +1457,13 @@ int swad__getCourseInfo (struct soap *soap,
break;
case Inf_INFO_SRC_PLAIN_TEXT: // Plain text
case Inf_INFO_SRC_RICH_TEXT: // Rich text (not yet available)
- Result = Inf_WritePlainTextIntoHTMLBuffer (&(getCourseInfo->infoTxt));
+ Result = API_WritePlainTextIntoHTMLBuffer (soap,&(getCourseInfo->infoTxt));
break;
case Inf_INFO_SRC_PAGE: // Web page hosted in SWAD server
- Result = Inf_WritePageIntoHTMLBuffer (&(getCourseInfo->infoTxt));
+ Result = API_WritePageIntoHTMLBuffer (soap,&(getCourseInfo->infoTxt));
break;
case Inf_INFO_SRC_URL: // Link to a web page
- getCourseInfo->infoTxt = (char *) soap_malloc (Gbl.soap,Cns_MAX_BYTES_WWW + 1);
+ getCourseInfo->infoTxt = (char *) soap_malloc (soap,Cns_MAX_BYTES_WWW + 1);
Inf_WriteURLIntoTxtBuffer (getCourseInfo->infoTxt);
break;
}
@@ -1415,13 +1471,249 @@ int swad__getCourseInfo (struct soap *soap,
/***** Return empty text if pointer is null *****/
if (getCourseInfo->infoTxt == NULL)
{
- getCourseInfo->infoTxt = (char *) soap_malloc (Gbl.soap,1);
+ getCourseInfo->infoTxt = (char *) soap_malloc (soap,1);
getCourseInfo->infoTxt[0] = '\0';
}
return Result;
}
+/*****************************************************************************/
+/************** Write the syllabus into a temporary HTML file ****************/
+/*****************************************************************************/
+
+static int API_WriteSyllabusIntoHTMLBuffer (struct soap *soap,
+ char **HTMLBuffer)
+ {
+ extern struct LstItemsSyllabus Syl_LstItemsSyllabus;
+ char FileNameHTMLTmp[PATH_MAX + 1];
+ FILE *FileHTMLTmp;
+ size_t Length;
+
+ /***** Initialize buffer *****/
+ *HTMLBuffer = NULL;
+
+ /***** Load syllabus from XML file to list of items in memory *****/
+ Syl_LoadListItemsSyllabusIntoMemory (Gbl.Hierarchy.Crs.CrsCod);
+
+ if (Syl_LstItemsSyllabus.NumItems)
+ {
+ /***** Create a unique name for the file *****/
+ snprintf (FileNameHTMLTmp,sizeof (FileNameHTMLTmp),
+ "%s/%s_syllabus.html",
+ Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
+
+ /***** Create a new temporary file for writing and reading *****/
+ if ((FileHTMLTmp = fopen (FileNameHTMLTmp,"w+b")) == NULL)
+ {
+ Syl_FreeListItemsSyllabus ();
+ return soap_receiver_fault (soap,
+ "Syllabus can not be copied into buffer",
+ "Can not create temporary file");
+ }
+
+ /***** Write syllabus in HTML into a temporary file *****/
+ Syl_WriteSyllabusIntoHTMLTmpFile (FileHTMLTmp);
+
+ /***** Write syllabus from list of items in memory to text buffer *****/
+ /* Compute length of file */
+ Length = (size_t) ftell (FileHTMLTmp);
+
+ /* Allocate memory for buffer */
+ if ((*HTMLBuffer = (char *) malloc (Length + 1)) == NULL)
+ {
+ fclose (FileHTMLTmp);
+ unlink (FileNameHTMLTmp);
+ Syl_FreeListItemsSyllabus ();
+ return soap_receiver_fault (soap,
+ "Syllabus can not be copied into buffer",
+ "Not enough memory for buffer");
+ }
+
+ /* Copy file content into buffer */
+ fseek (FileHTMLTmp,0L,SEEK_SET);
+ if (fread (*HTMLBuffer,sizeof (char),Length,FileHTMLTmp) != Length)
+ {
+ fclose (FileHTMLTmp);
+ unlink (FileNameHTMLTmp);
+ Syl_FreeListItemsSyllabus ();
+ return soap_receiver_fault (soap,
+ "Syllabus can not be copied into buffer",
+ "Error reading file into buffer");
+ }
+ (*HTMLBuffer)[Length] = '\0';
+
+ /***** Close and remove temporary file *****/
+ fclose (FileHTMLTmp);
+ unlink (FileNameHTMLTmp);
+ }
+
+ /***** Free list of items *****/
+ Syl_FreeListItemsSyllabus ();
+
+ return SOAP_OK;
+ }
+
+/*****************************************************************************/
+/************* Check if exists and write page into HTML buffer ***************/
+/*****************************************************************************/
+
+static int API_WritePlainTextIntoHTMLBuffer (struct soap *soap,
+ char **HTMLBuffer)
+ {
+ extern const char *Txt_INFO_TITLE[Inf_NUM_INFO_TYPES];
+ char TxtHTML[Cns_MAX_BYTES_LONG_TEXT + 1];
+ char FileNameHTMLTmp[PATH_MAX + 1];
+ FILE *FileHTMLTmp;
+ size_t Length;
+
+ /***** Initialize buffer *****/
+ *HTMLBuffer = NULL;
+
+ /***** Get info text from database *****/
+ Inf_GetInfoTxtFromDB (Gbl.Hierarchy.Crs.CrsCod,Gbl.Crs.Info.Type,
+ TxtHTML,NULL);
+
+ if (TxtHTML[0])
+ {
+ /***** Create a unique name for the file *****/
+ snprintf (FileNameHTMLTmp,sizeof (FileNameHTMLTmp),
+ "%s/%s_info.html",
+ Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
+
+ /***** Create a new temporary file for writing and reading *****/
+ if ((FileHTMLTmp = fopen (FileNameHTMLTmp,"w+b")) == NULL)
+ return soap_receiver_fault (soap,
+ "Plain text can not be copied into buffer",
+ "Can not create temporary file");
+
+ /***** Write start of HTML code *****/
+ Lay_StartHTMLFile (FileHTMLTmp,Txt_INFO_TITLE[Gbl.Crs.Info.Type]);
+ fprintf (FileHTMLTmp,"\n"
+ "\n");
+
+ /***** Write plain text into text buffer *****/
+ /* Convert to respectful HTML and insert links */
+ Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
+ TxtHTML,Cns_MAX_BYTES_LONG_TEXT,false); // Convert from HTML to recpectful HTML
+ Str_InsertLinks (TxtHTML,Cns_MAX_BYTES_LONG_TEXT,60); // Insert links
+
+ /* Write text */
+ fprintf (FileHTMLTmp,"%s",TxtHTML);
+
+ /***** Write end of page into file *****/
+ fprintf (FileHTMLTmp,"
\n"
+ "\n"
+ "
\n"
- "\n");
-
- /***** Write plain text into text buffer *****/
- /* Convert to respectful HTML and insert links */
- Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
- TxtHTML,Cns_MAX_BYTES_LONG_TEXT,false); // Convert from HTML to recpectful HTML
- Str_InsertLinks (TxtHTML,Cns_MAX_BYTES_LONG_TEXT,60); // Insert links
-
- /* Write text */
- fprintf (FileHTMLTmp,"%s",TxtHTML);
-
- /***** Write end of page into file *****/
- fprintf (FileHTMLTmp,"
\n"
- "