swad-core/swad_media.h

160 lines
6.6 KiB
C
Raw Normal View History

2019-03-02 21:49:28 +01:00
// swad_media.h: processing of image/video uploaded in a form
#ifndef _SWAD_IMG
#define _SWAD_IMG
/*
SWAD (Shared Workspace At a Distance in Spanish),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
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 ***********************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Public constants ******************************/
/*****************************************************************************/
#define Med_BYTES_NAME Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64
#define Med_MAX_CHARS_TITLE (128 - 1) // 127
#define Med_MAX_BYTES_TITLE ((Med_MAX_CHARS_TITLE + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047
#define Med_MAX_CHARS_ATTRIBUTION (256 - 1) // 255
#define Med_MAX_BYTES_ATTRIBUTION ((Med_MAX_CHARS_ATTRIBUTION + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 4095
/*****************************************************************************/
/******************************* Public types ********************************/
/*****************************************************************************/
/***** Action to perform when editing a form with an image/video *****/
2019-03-17 14:47:58 +01:00
#define Med_NUM_ACTIONS 3
2019-03-02 21:49:28 +01:00
typedef enum
{
2019-03-15 15:25:31 +01:00
Med_ACTION_NO_MEDIA, // Do not use media (remove current media if exists)
2019-03-17 14:47:58 +01:00
Med_ACTION_KEEP_MEDIA, // Keep current media unchanged
Med_ACTION_NEW_MEDIA, // Upload new media (if current media exists, remove and change by the new one)
2019-03-02 21:49:28 +01:00
} Med_Action_t;
#define Med_ACTION_DEFAULT Med_ACTION_NO_MEDIA
/***** Status of an image/video file *****/
/*
No file Original file Temporary Definitive Name of the image/video
uploaded uploaded by user processed file processed file stored in database
--------- --------------------------- ------------------ ------------------ ---------------------
2019-03-18 15:42:22 +01:00
Med_STATUS_NONE Med_PROCESSED Med_MOVED Med_NAME_STORED_IN_DB
2019-03-02 21:49:28 +01:00
--------- --------------------------- ------------------ ------------------ ---------------------
2019-03-17 14:47:58 +01:00
upload-file process file move file insert in database
2019-03-02 21:49:28 +01:00
--------- --------------------------- ------------------ ------------------ ---------------------
2019-03-17 14:47:58 +01:00
file.ext / / / xx-unique-name
| | |
var var var
| | |
www www www
| | |
swad swad swad
| | |
med med med
| | |
tmp tmp xx (2 first chars)
| | |
2019-03-02 21:49:28 +01:00
xx-unique-name_original.ext xx-unique-name.jpg xx-unique-name.jpg
xx-unique-name: a unique name encrypted starting by two random chars xx
*/
typedef enum
{
2019-03-15 15:25:31 +01:00
Med_STATUS_NONE,
Med_PROCESSED,
2019-03-18 15:42:22 +01:00
Med_MOVED,
2019-03-15 15:25:31 +01:00
Med_STORED_IN_DB,
} Med_Status_t;
2019-03-02 21:49:28 +01:00
2019-03-21 20:04:01 +01:00
#define Med_NUM_TYPES 8
2019-03-02 21:49:28 +01:00
typedef enum
{
2019-03-15 15:25:31 +01:00
Med_TYPE_NONE,
2019-03-02 21:49:28 +01:00
Med_JPG,
Med_GIF,
2019-03-13 23:04:00 +01:00
Med_MP4,
Med_WEBM,
Med_OGG,
2019-03-15 15:25:31 +01:00
Med_YOUTUBE,
2019-03-21 20:04:01 +01:00
Med_EMBED,
2019-03-02 21:49:28 +01:00
} Med_Type_t;
/***** Struct used to get images/videos from forms *****/
struct Media
{
2019-03-18 15:42:22 +01:00
long MedCod;
2019-03-02 21:49:28 +01:00
Med_Action_t Action;
2019-03-15 15:25:31 +01:00
Med_Status_t Status;
2019-03-02 21:49:28 +01:00
char Name[Med_BYTES_NAME + 1];
Med_Type_t Type;
2019-03-17 14:47:58 +01:00
bool URLIsAllocated;
bool TitleIsAllocated;
2019-03-02 21:49:28 +01:00
char *URL; // URL, i.e. link to original big photo or video
// (it must be initialized to NULL
// in order to not trying to free it when no memory allocated)
2019-03-17 14:47:58 +01:00
char *Title; // Title/attribution (it must be initialized to NULL
// in order to not trying to free it when no memory allocated)
2019-03-02 21:49:28 +01:00
unsigned Width;
unsigned Height;
unsigned Quality;
};
/***** Parameters used in a form to upload an image/video *****/
#define Med_MAX_BYTES_PARAM_UPLOAD_MEDIA (16 - 1)
struct ParamUploadMedia
{
2019-03-15 15:25:31 +01:00
char Action [Med_MAX_BYTES_PARAM_UPLOAD_MEDIA + 1];
2019-03-17 01:38:10 +01:00
char FormType[Med_MAX_BYTES_PARAM_UPLOAD_MEDIA + 1];
2019-03-15 15:25:31 +01:00
char File [Med_MAX_BYTES_PARAM_UPLOAD_MEDIA + 1];
char Title [Med_MAX_BYTES_PARAM_UPLOAD_MEDIA + 1];
char URL [Med_MAX_BYTES_PARAM_UPLOAD_MEDIA + 1];
2019-03-02 21:49:28 +01:00
};
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
void Med_MediaConstructor (struct Media *Media);
void Med_MediaDestructor (struct Media *Media);
2019-03-17 14:47:58 +01:00
void Med_ResetMedia (struct Media *Media);
2019-03-02 21:49:28 +01:00
2019-03-18 15:42:22 +01:00
void Med_GetMediaDataByCod (struct Media *Media);
2019-03-02 21:49:28 +01:00
2019-03-16 16:15:15 +01:00
void Med_PutMediaUploader (int NumMediaInForm,const char *ClassInput);
2019-03-02 21:49:28 +01:00
void Med_GetMediaFromForm (int NumMediaInForm,struct Media *Media,
2019-03-17 14:47:58 +01:00
void (*GetMediaFromDB) (int NumMediaInForm,struct Media *Media),
const char *SectionForAlerts);
2019-03-02 21:49:28 +01:00
void Med_SetParamNames (struct ParamUploadMedia *ParamUploadMedia,int NumMediaInForm);
2019-03-19 11:20:29 +01:00
void Med_RemoveKeepOrStoreMedia (long CurrentMedCodInDB,struct Media *Media);
2019-03-04 10:10:46 +01:00
void Med_MoveMediaToDefinitiveDir (struct Media *Media);
2019-03-18 15:42:22 +01:00
void Med_StoreMediaInDB (struct Media *Media);
2019-03-02 21:49:28 +01:00
void Med_ShowMedia (struct Media *Media,
const char *ClassContainer,const char *ClassMedia);
2019-03-18 15:42:22 +01:00
void Med_RemoveMediaFromAllRows (unsigned NumMedia,MYSQL_RES *mysql_res);
void Med_RemoveMedia (long MedCod);
2019-03-02 21:49:28 +01:00
#endif