swad-core/swad_image.h

145 lines
6.4 KiB
C
Raw Normal View History

2016-04-03 01:24:57 +02:00
// swad_image.h: processing of image 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.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 Antonio Ca<EFBFBD>as Vargas
2016-04-03 01:24:57 +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 ***********************************/
/*****************************************************************************/
/*****************************************************************************/
/***************************** Public constants ******************************/
/*****************************************************************************/
2017-03-13 14:22:36 +01:00
#define Img_BYTES_NAME Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64
2017-03-08 14:12:33 +01:00
#define Img_MAX_CHARS_TITLE (128 - 1) // 127
#define Img_MAX_BYTES_TITLE ((Img_MAX_CHARS_TITLE + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 2047
#define Img_MAX_CHARS_ATTRIBUTION (256 - 1) // 255
#define Img_MAX_BYTES_ATTRIBUTION ((Img_MAX_CHARS_ATTRIBUTION + 1) * Str_MAX_BYTES_PER_CHAR - 1) // 4095
2016-04-06 14:41:47 +02:00
2016-04-03 01:24:57 +02:00
/*****************************************************************************/
/******************************* Public types ********************************/
/*****************************************************************************/
2016-04-04 14:48:12 +02:00
/***** Action to perform when editing a form with an image *****/
#define Img_NUM_ACTIONS 4
typedef enum
{
Img_ACTION_NEW_IMAGE, // Upload new image
2016-04-11 15:32:59 +02:00
Img_ACTION_KEEP_IMAGE, // Keep current image unchanged
2016-04-04 14:48:12 +02:00
Img_ACTION_CHANGE_IMAGE, // Change existing image by a new image
2016-04-11 15:32:59 +02:00
Img_ACTION_NO_IMAGE, // Do not use image (remove current image if exists)
2016-04-04 14:48:12 +02:00
} Img_Action_t;
2017-01-29 21:41:08 +01:00
#define Img_ACTION_DEFAULT Img_ACTION_NO_IMAGE
2016-04-04 14:48:12 +02:00
/***** Status of an image file *****/
2016-04-03 01:24:57 +02:00
/*
No image Original file Temporary Definitive Name of the image
uploaded uploaded by user processed image processed image stored in database
--------- --------------------------- ------------------ ------------------ ---------------------
2016-04-04 14:48:12 +02:00
Img_NONE Img_FILE_RECEIVED Img_FILE_PROCESSED Img_FILE_MOVED Img_NAME_STORED_IN_DB
2016-04-03 01:24:57 +02:00
--------- --------------------------- ------------------ ------------------ ---------------------
-> upload-file -> -> process-file -> b -> move-file -> -> insert-name ->
--------- --------------------------- ------------------ ------------------ ---------------------
file.ext / / / xx-unique-name
| | |
var var var
| | |
www www www
| | |
swad swad swad
| | |
img img img
| | |
tmp tmp xx (2 first chars)
| | |
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
{
2016-04-04 03:00:12 +02:00
Img_FILE_NONE,
Img_FILE_RECEIVED,
2016-04-03 01:24:57 +02:00
Img_FILE_PROCESSED,
Img_FILE_MOVED,
Img_NAME_STORED_IN_DB,
2016-04-04 03:00:12 +02:00
} Img_FileStatus_t;
2016-04-03 01:24:57 +02:00
2016-04-04 14:48:12 +02:00
/***** Struct used to get images from forms *****/
struct Image
2016-04-03 15:53:27 +02:00
{
2016-04-04 14:48:12 +02:00
Img_Action_t Action;
Img_FileStatus_t Status;
2017-03-13 14:22:36 +01:00
char Name[Img_BYTES_NAME + 1];
2016-04-08 16:37:59 +02:00
char *Title; // Title/attribution (it must be initialized to NULL
// in order to not trying to free it when no memory allocated)
2016-04-15 02:33:16 +02: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)
2016-04-14 19:19:55 +02:00
unsigned Width;
unsigned Height;
unsigned Quality;
2016-04-04 14:48:12 +02:00
};
2016-04-03 15:53:27 +02:00
2016-04-14 21:33:24 +02:00
/***** Parameters used in a form to upload an image *****/
2017-03-07 19:55:29 +01:00
#define Img_MAX_BYTES_PARAM_UPLOAD_IMG (16 - 1)
2016-04-14 18:59:18 +02:00
struct ParamUploadImg
{
2017-03-07 19:55:29 +01:00
char Action[Img_MAX_BYTES_PARAM_UPLOAD_IMG + 1];
char File [Img_MAX_BYTES_PARAM_UPLOAD_IMG + 1];
char Title [Img_MAX_BYTES_PARAM_UPLOAD_IMG + 1];
char URL [Img_MAX_BYTES_PARAM_UPLOAD_IMG + 1];
2016-04-14 18:59:18 +02:00
};
2016-04-03 01:24:57 +02:00
/*****************************************************************************/
/***************************** Public prototypes *****************************/
/*****************************************************************************/
2016-04-08 23:30:43 +02:00
void Img_ImageConstructor (struct Image *Image);
2016-04-15 02:33:16 +02:00
void Img_ResetImageExceptTitleAndURL (struct Image *Image);
2016-04-08 23:30:43 +02:00
void Img_ImageDestructor (struct Image *Image);
2016-04-15 10:58:35 +02:00
void Img_FreeImageTitle (struct Image *Image);
void Img_FreeImageURL (struct Image *Image);
2016-04-08 23:30:43 +02:00
2016-04-15 02:33:16 +02:00
void Img_GetImageNameTitleAndURLFromRow (const char *Name,
const char *Title,
const char *URL,
struct Image *Image);
2016-04-06 01:10:04 +02:00
2016-04-15 10:58:35 +02:00
void Img_PutImageUploader (int NumImgInForm,const char *ClassImgTitURL);
2016-04-14 21:33:24 +02:00
void Img_GetImageFromForm (int NumImgInForm,struct Image *Image,
void (*GetImageFromDB) (int NumImgInForm,struct Image *Image));
void Img_SetParamNames (struct ParamUploadImg *ParamUploadImg,int NumImgInForm);
2016-04-04 14:48:12 +02:00
Img_Action_t Img_GetImageActionFromForm (const char *ParamAction);
2016-04-14 19:19:55 +02:00
void Img_GetAndProcessImageFileFromForm (struct Image *Image,const char *ParamFile);
2016-04-03 17:49:09 +02:00
2016-04-04 14:48:12 +02:00
void Img_MoveImageToDefinitiveDirectory (struct Image *Image);
2016-04-15 14:30:28 +02:00
void Img_ShowImage (struct Image *Image,
const char *ClassContainer,const char *ClassImg);
2016-04-03 14:18:43 +02:00
void Img_RemoveImageFile (const char *ImageName);
2016-04-03 01:24:57 +02:00
#endif