Skip to content

Commit

Permalink
Merge pull request titi38#33 from geraldolsribeiro/master
Browse files Browse the repository at this point in the history
Mimetype for svg extension + GetTextTypeContent fix
  • Loading branch information
titi38 authored Dec 21, 2018
2 parents f9dacf8 + 7ce49e0 commit 1180842
Show file tree
Hide file tree
Showing 17 changed files with 1,131 additions and 461 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.o
*.swp
build
examples/1_basic/PrecompiledRepository.cc
examples/3_websocket/PrecompiledRepository.cc
examples/3_websocket/example
test/example

32 changes: 15 additions & 17 deletions include/MPFDParser/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@


#ifndef _EXCEPTION_H
#define _EXCEPTION_H
#define _EXCEPTION_H

#include <string>
#include <iostream>
#include <errno.h>
#include <iostream>
#include <string>


namespace MPFD {

class Exception {
public:
Exception(std::string error);
Exception(const Exception& orig);
virtual ~Exception();

std::string GetError();

private:
std::string Error;

};
}
class Exception {
public:
Exception( std::string error );
Exception( const Exception &orig );
virtual ~Exception();

std::string GetError();

#endif /* _EXCEPTION_H */
private:
std::string Error;
};
}

#endif /* _EXCEPTION_H */
70 changes: 33 additions & 37 deletions include/MPFDParser/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,60 @@


#ifndef _FIELD_H
#define _FIELD_H
#define _FIELD_H

#include "Exception.h"
#include <iostream>
#include <fstream>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <vector>

namespace MPFD {

class Field {
public:
static const int TextType = 1, FileType = 2;
class Field {
public:
static const int TextType = 1, FileType = 2;

Field();
virtual ~Field();
Field();
virtual ~Field();

void SetType(int type);
int GetType();
void SetType( int type );
int GetType();

void AcceptSomeData(char *data, long length);
void AcceptSomeData( char *data, long length );


// File functions
void SetUploadedFilesStorage(int where);
void SetTempDir(std::string dir);
// File functions
void SetUploadedFilesStorage( int where );
void SetTempDir( std::string dir );

void SetFileName(std::string name);
std::string GetFileName();
void SetFileName( std::string name );
std::string GetFileName();

void SetFileContentType(std::string type);
std::string GetFileMimeType();
void SetFileContentType( std::string type );
std::string GetFileMimeType();

char * GetFileContent();
unsigned long GetFileContentSize();
char * GetFileContent();
unsigned long GetFileContentSize();

std::string GetTempFileName();
std::string GetTempFileName();

// Text field operations
std::string GetTextTypeContent();
// Text field operations
std::string GetTextTypeContent();


private:
unsigned long FieldContentLength;

int WhereToStoreUploadedFiles;

private:
std::string TempDir, TempFile;
std::string FileContentType, FileName;

int WhereToStoreUploadedFiles;

std::string TempDir, TempFile;
std::string FileContentType, FileName;

int type;
std::vector<char> FieldContent;
std::ofstream file;

};
int type;
char * FieldContent;
std::ofstream file;
};
}
#endif /* _FIELD_H */

#endif /* _FIELD_H */
86 changes: 41 additions & 45 deletions include/MPFDParser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,66 @@
// Contacts and other info are on the WEB page: grigory.info/MPFDParser



#ifndef _PARSER_H
#define _PARSER_H
#define _PARSER_H

#include <iostream>
#include <string>
#include <map>
#include <vector>
#include "Exception.h"
#include "Field.h"
#include <string.h>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string.h>
#include <string>

namespace MPFD {

class Parser {
public:
static const int StoreUploadedFilesInFilesystem = 1, StoreUploadedFilesInMemory = 2;
class Parser {
public:
static const int StoreUploadedFilesInFilesystem = 1, StoreUploadedFilesInMemory = 2;


Parser();
~Parser();
Parser();
~Parser();

void SetContentType(const std::string type);
void SetContentType( const std::string type );

void AcceptSomeData(const char *data, const long length);
void AcceptSomeData( const char *data, const long length );


void SetMaxCollectedDataLength( long max );
void SetTempDirForFileUpload( std::string dir );
void SetUploadedFilesStorage( int where );

void SetMaxCollectedDataLength(long max);
void SetTempDirForFileUpload(std::string dir);
inline std::string GetTempDirForFileUpload() { return TempDirForFileUpload; };
void SetUploadedFilesStorage(int where);
std::map<std::string, Field *> GetFieldsMap();
Field *GetField( std::string Name );

std::map<std::string, Field *> GetFieldsMap();
Field * GetField(std::string Name);
private:
int WhereToStoreUploadedFiles;

private:
int WhereToStoreUploadedFiles;
std::map<std::string, Field *> Fields;

std::map<std::string, Field *> Fields;
std::string TempDirForFileUpload;
int CurrentStatus;

std::string TempDirForFileUpload;
int CurrentStatus;
// Work statuses
static int const Status_LookingForStartingBoundary = 1;
static int const Status_ProcessingHeaders = 2;
static int const Status_ProcessingContentOfTheField = 3;

// Work statuses
static int const Status_LookingForStartingBoundary = 1;
static int const Status_ProcessingHeaders = 2;
static int const Status_ProcessingContentOfTheField = 3;

std::string Boundary;
std::string ProcessingFieldName;
bool _HeadersOfTheFieldAreProcessed;
std::vector<char> DataCollector;
long MaxDataCollectorLength;
bool FindStartingBoundaryAndTruncData();
void _ProcessData();
void _ParseHeaders(std::string headers);
bool WaitForHeadersEndAndParseThem();
void TruncateDataCollectorFromTheBeginning(long n);
long BoundaryPositionInDataCollector();
bool ProcessContentOfTheField();
};
std::string Boundary;
std::string ProcessingFieldName;
bool _HeadersOfTheFieldAreProcessed;
long ContentLength;
char * DataCollector;
long DataCollectorLength, MaxDataCollectorLength;
bool FindStartingBoundaryAndTruncData();
void _ProcessData();
void _ParseHeaders( std::string headers );
bool WaitForHeadersEndAndParseThem();
void TruncateDataCollectorFromTheBeginning( long n );
long BoundaryPositionInDataCollector();
bool ProcessContentOfTheField();
};
}

#endif /* _PARSER_H */

#endif /* _PARSER_H */
27 changes: 23 additions & 4 deletions include/libnavajo/HttpRequest.hh
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,21 @@ class HttpRequest
size_t posEq=0;
if ((posEq = theParam.find('=')) == std::string::npos)
parameters[theParam]="";
else
parameters[theParam.substr(0,posEq)]=theParam.substr(posEq+1);
else {
auto key = theParam.substr(0,posEq);
auto value = theParam.substr(posEq+1);
if( parameters.count( key ) == 0 ) {
parameters[key] = value;
} else {
auto arrayKey = key + "[]";
if( parameters.count( arrayKey ) == 1 ) {
parameters[arrayKey] += "|" + value;
} else {
parameters[arrayKey] = parameters[key] + "|" + value;
}
parameters[key] = value;
}
}

start = end + 1;
}
Expand Down Expand Up @@ -392,8 +405,7 @@ class HttpRequest
this->payload=payload ;
this->mutipartContentParser=parser;

if (params != NULL && strlen(params))
decodParams(params);
setParams( params );

if (cookies != NULL && strlen(cookies))
decodCookies(cookies);
Expand Down Expand Up @@ -442,6 +454,13 @@ class HttpRequest
* */
inline void setUrl(const char *newUrl) { url=newUrl; };

// GLSR: torna pública a configuração de parâmetros permitindo realizar forwardTo com novos parâmetros
inline void setParams( const char*params ) {
if (params != NULL && strlen(params)) {
decodParams(params);
}
}

/**********************************************************************/
/**
* get request type
Expand Down
19 changes: 11 additions & 8 deletions src/MPFDParser/Exception.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@

#include "MPFDParser/Exception.h"

MPFD::Exception::Exception(std::string error) {
Error = error;
MPFD::Exception::Exception( std::string error )
{
Error = error;
}

MPFD::Exception::Exception(const MPFD::Exception& orig) {
Error = orig.Error;
MPFD::Exception::Exception( const MPFD::Exception &orig )
{
Error = orig.Error;
}

MPFD::Exception::~Exception() {

MPFD::Exception::~Exception()
{
}

std::string MPFD::Exception::GetError() {
return Error;
std::string MPFD::Exception::GetError()
{
return Error;
}
Loading

0 comments on commit 1180842

Please sign in to comment.