コード例 #1
0
ファイル: imagelibrary.c プロジェクト: nupfel/friendup
Http*  WebRequest( struct ImageLibrary *l, User *usr, char **urlpath, Http* request, Socket* sock )
{
	Http* response = NULL;
	
	DEBUG("IMAGE WEBREQUEST %s\n", urlpath[ 0 ] );
	SystemBase *sb = (SystemBase *)l->sb;
	
	if( strcmp( urlpath[ 0 ], "help" ) == 0 )
	{
		struct TagItem tags[] = {
			{ HTTP_HEADER_CONTENT_TYPE, (ULONG)  StringDuplicate( "text/html" ) },
			{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
			{TAG_DONE, TAG_DONE}
		};
		
		response = HttpNewSimple( HTTP_200_OK,  tags );
		
		HttpAddTextContent( response, \
			"resize - resize image on filesystem\n \
			" );			// out of memory/user not found
		
		//HttpWriteAndFree( response );
	
		//
		// resize image on filesystem
		//
		
	}
	else if( strcmp( urlpath[ 0 ], "resize" ) == 0 )
コード例 #2
0
ファイル: key_value_list.c プロジェクト: eloekset/friendup
KeyValueList *KeyValueListNewWithEntry( char *key, char *value )
{
	KeyValueList *ne = FCalloc( 1, sizeof( KeyValueList ) );
	if( ne != NULL )
	{
		ne->key = StringDuplicate( key );
		ne->value = StringDuplicate( value );
	}
	return ne;
}
コード例 #3
0
ファイル: file_system.c プロジェクト: AntoineD/spaf
//=============================================================================
char*
ListFilesInDirectory(
const char* DirName ) ///< name of a directory
{
  if ( DirName == NULL ) return NULL;
    
  DIR *directory = opendir(DirName);
  
  if ( directory == NULL ) return NULL;
  
  // entry in the directory
  struct dirent *entry;
  
  // initialize file list to empty
  char* FileList = StringDuplicate("");

  // loop over entries
  while( (entry = readdir(directory)) != NULL )
  {
    // filter . and .. entries
    if ( StringCompare(entry->d_name,".") || 
         StringCompare(entry->d_name,"..") ) continue;
    
    // append file name and separator to list
    StringAppend(&FileList,entry->d_name);
    StringAppend(&FileList," ");
  }
  
  // close directory
  assert_error( closedir(directory) == 0, "Failed to close directory");
  
  return FileList;
}
コード例 #4
0
ファイル: key_value_list.c プロジェクト: eloekset/friendup
int KeyValueListSetValues( KeyValueList *list, char *key, char *value )
{
	if( list != NULL )
	{
		if( list->key != NULL )
		{
			FFree( list->key );
		}
		
		if( list->value != NULL )
		{
			FFree( list->value );
		}
		
		list->key = StringDuplicate( key );
		list->value = StringDuplicate( value );
	}
	return 0;
}
コード例 #5
0
ファイル: build.c プロジェクト: LoyolaChicagoCode/apt
void BuildTypeTable()
{
  TypeNode *t;
  int count;

  TypeTable = (char **)Allocate(TypeCount * sizeof(char *));
  for (count=0, t=TypeList; t != NULL; t=t->next, count++)
    TypeTable[count] = StringDuplicate(t->text);

}
コード例 #6
0
ファイル: strings.c プロジェクト: AntoineD/spaf
//==============================================================================
char*
StringConcat(
const char* string1,  ///< string
const char* string2 ) ///< string
{
  char *string = StringDuplicate(string1);
  StringAppend(&string, string2);
  
  return string;
}
コード例 #7
0
ファイル: build.c プロジェクト: LoyolaChicagoCode/apt
void BuildSymbolTable()
{
  SymbolNode *s;
  int i;

  SymbolCount += 2;
  SymTab = (SymTabElem *)
      Allocate(SymbolCount*sizeof(SymTabElem));
  SymTab[0].symbol = StringDuplicate(StartSymbol);
  SymTab[0].type = NonTerminal;
  SymTab[0].derives_lambda = FALSE;
  SymTab[0].reachable = FALSE;
  for (i=1, s=SymbolList; s != NULL; s=s->next)
    if (s->type == NonTerminal) {
      SymTab[i].symbol = StringDuplicate(s->text);
      SymTab[i].type = s->type;
      SymTab[i].derives_lambda = FALSE;
      SymTab[i].reachable = FALSE;
      i++;
    }
  SymTab[i].symbol = StringDuplicate(EOFSymbol);
  SymTab[i].type = Terminal;
  SymTab[i].derives_lambda = FALSE;
  SymTab[i].reachable = FALSE;
  for (i++, s=SymbolList; s != NULL; s=s->next)
    if (s->type == Terminal) {
      SymTab[i].symbol = StringDuplicate(s->text);
      SymTab[i].type = s->type;
      SymTab[i].derives_lambda = FALSE;
      SymTab[i].reachable = FALSE;
      i++;
    }
  for (s=SymbolList; s != NULL; s=s->next)
    if (s->type == Action) {
      SymTab[i].symbol = StringDuplicate(s->text);
      SymTab[i].type = s->type;
      SymTab[i].derives_lambda = FALSE;
      SymTab[i].reachable = FALSE;
      i++;
    }
}
コード例 #8
0
void Burger::LinkedListObjects::PrependObject(const char *pString)
{
	char *pStringCopy = StringDuplicate(pString);
	if (pStringCopy) {
		// Create the new object
		Object *pObject = Object::New(pStringCopy);
		// If successful, append it
		if (pObject) {
			PrependObject(pObject);
		}
	}
}
コード例 #9
0
ファイル: file_system.c プロジェクト: AntoineD/spaf
//==============================================================================
char*
GetAbsolutePath(
char* path )  ///< a path
{
  // check we have a relative path, i.e. that starts with '/'
  // otherwise return the path itself
  if ( path[0] == '/' )
  {
    path = StringDuplicate(path);
    return path;
  }
        
  // get working directory
  char *AbsolutePath = GetWorkingDirectory();

  // append relative path to it
  StringAppend(&AbsolutePath, "/");
  StringAppend(&AbsolutePath, path);

  return AbsolutePath;
}
コード例 #10
0
ファイル: jc_scanner.c プロジェクト: nightstyles/focp
static jc_int Read(CJcBuffer* pBuffer)
{
	jc_char c;
	if(!pBuffer->pCurLine)
	{
		const jc_char* sLine;
		pBuffer->pCurLine = (CJcSourceLineList*)g_oInterface.Malloc(sizeof(CJcSourceLineList));
		pBuffer->pCurLine->pLine = (CJcSourceLine*)g_oInterface.Malloc(sizeof(CJcSourceLine));
		pBuffer->pCurLine->pNext = NULL;
		sLine = pBuffer->GetLine(pBuffer->pSource, &pBuffer->pCurLine->pLine->nLine, &pBuffer->pCurLine->pLine->sFileName);
		if(!sLine)
			sLine = "";
		pBuffer->pCurLine->pLine->nPos = pBuffer->nPos;
		pBuffer->pCurLine->pLine->nSize = StringLength(sLine);
		pBuffer->pCurLine->pLine->sLine = StringDuplicate(sLine);
		pBuffer->pCurLine->pPrev = pBuffer->pTail;
		if(pBuffer->pTail)
			pBuffer->pTail->pNext = pBuffer->pCurLine;
		else
			pBuffer->pHead = pBuffer->pCurLine;
		pBuffer->pTail = pBuffer->pCurLine;
		pBuffer->nOff = 0;
	}
	c = pBuffer->pCurLine->pLine->sLine[pBuffer->nOff];
	++pBuffer->nOff;
	if(pBuffer->nOff >= pBuffer->pCurLine->pLine->nSize)
	{
		if(!c || c == -1)
		{
			--pBuffer->nOff;
			return EoF;
		}
		pBuffer->pCurLine = pBuffer->pCurLine->pNext;
		pBuffer->nOff = 0;
	}
	++pBuffer->nPos;
	return (jc_int)(jc_uchar)c;
}
コード例 #11
0
ファイル: String.cpp プロジェクト: pxf/pxf-tech2
char *Pxf::DuplicateReplaceChar(const char *str, const char find, const char replace)
{
	char *p = StringDuplicate(str);
	ReplaceChar(p, find, replace);
	return p;
}
コード例 #12
0
ファイル: protocol_http.c プロジェクト: seem8/friendup
extern inline Http *ProtocolHttp( Socket* sock, char* data, unsigned int length )
{
	Http *response = NULL;
	DEBUG("HTTP Callback called\n");
	
	if( length <= 0 )
	{
		DEBUG("RESULT<0 http400\n");
		
		struct TagItem tags[] = {
			{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicateN( "close", 5 ) },
			{TAG_DONE, TAG_DONE}
		};
		
		response = HttpNewSimple( HTTP_400_BAD_REQUEST,  tags );
	
		//HttpWriteAndFree( response );
	}
	
	// Get the current request we're working on, or start a new one
	Http* request = (Http*)sock->data;
	if( !request )
	{
		request = HttpNew( sock );
		request->timestamp = time( NULL );
		sock->data = (void*)request;
	}
	
	//DEBUG("Checking timeout, data %s\n", data );

	//DEBUG("time %ld\nreqtimestamp %ld\nreqtimestamp %ld\n",
	//	  time( NULL ), request->timestamp, HTTP_REQUEST_TIMEOUT );
	// Timeout
	if( time( NULL ) > request->timestamp + HTTP_REQUEST_TIMEOUT )
	{
		struct TagItem tags[] = {
			{ HTTP_HEADER_CONTENT_TYPE, (ULONG)  StringDuplicate( "text/plain" ) },
			{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
			{TAG_DONE, TAG_DONE}
		};
		
		response = HttpNewSimple( HTTP_408_REQUEST_TIME_OUT,  tags );
		
		HttpAddTextContent( response, "408 Request Timeout\n" );
		//HttpWriteAndFree( response );
		HttpFreeRequest( request );
		sock->data = NULL;
		DEBUG("HTTP TIMER\n");
		return response;
	}
	

	// Continue parsing the request
	int result = HttpParsePartialRequest( request, data, length );
	
	// Protocol error
	if( result < 0 )
	{
		DEBUG("RESULT<0 http400\n");
		struct TagItem tags[] = {
			{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
			{TAG_DONE, TAG_DONE}
		};
		
		response = HttpNewSimple( HTTP_400_BAD_REQUEST,  tags );
	
		//HttpWriteAndFree( response );
	}
	// Request not fully parsed yet. Return and wait for more data
	else if( result == -1 )
	{
		DEBUG( " <- (%d): Waiting for more data\n", sock->fd );
		HttpFreeRequest( request );
		return response;
	}
	// Request parsed without errors!
	else if( result == 1 )
	{
		Uri* uri = request->uri;
		
		// Disallow proxy requests
		if( uri && ( uri->scheme || uri->authority ) )
		{
			struct TagItem tags[] = {
				{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
				{TAG_DONE, TAG_DONE}
			};
		
			response = HttpNewSimple( HTTP_403_FORBIDDEN,  tags );
	
			result = 403;
		}

		// Cross-domain requests uses a pre-flight OPTIONS call
		if( !request->errorCode && request->method && strcmp( request->method, "OPTIONS" ) == 0 )
		{
			struct TagItem tags[] = {
				{ HTTP_HEADER_CONTROL_ALLOW_ORIGIN, (ULONG)StringDuplicateN( "*", 1 ) },
				{ HTTP_HEADER_CONTROL_ALLOW_HEADERS, (ULONG)StringDuplicateN( "Origin, X-Requested-With, Content-Type, Accept, Method", 54 ) },
				{ HTTP_HEADER_CONTROL_ALLOW_METHODS,  (ULONG)StringDuplicateN( "GET, POST, OPTIONS", 18 ) },
				{ HTTP_HEADER_CONNECTION, (ULONG)StringDuplicateN( "close", 5 ) },
				{TAG_DONE, TAG_DONE}
			};
		
			if( response != NULL ) ERROR("Response != NULL\n");
			response = HttpNewSimple( HTTP_200_OK,  tags );

			result = 200;
		}		
		// Check for connection upgrade
		else if( !request->errorCode && HttpHeaderContains( request, "connection", "Upgrade", false ) )
		{
			struct TagItem tags[] = {
				{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
				{TAG_DONE, TAG_DONE}
			};
		
			response = HttpNewSimple(  HTTP_400_BAD_REQUEST, tags );
	
		}
		else
		{
			Path* path = NULL;
			if( uri->path->raw )
			{
				int nlen = 0;
				for( ; ; nlen++ )
				{
					if( !uri->path->raw[nlen] )
						break;
				}
				DEBUG("Want to parse path: %s (%d)\n", uri->path->raw, nlen );
				path = PathNew( uri->path->raw );
				if( path ) PathResolve( path );  // Resolve checks for "../"'s, and removes as many as it can.
			}
			if( !path || !path->resolved ) // If it cannot remove all, path->resolved == false.
			{
				DEBUG( "We have no path..\n" );
				struct TagItem tags[] = {
					{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
					{TAG_DONE, TAG_DONE}
				};
		
				response = HttpNewSimple( HTTP_403_FORBIDDEN,  tags );
	
				result = 403;
			}
			else
			{
				DEBUG( "We got through. %s\n", path->parts[ 0 ] );
				
				if( path->size >= 2 && StringCheckExtension( path->parts[0], "library" ) == 0 )
				{
					// system.library is main library and should be use for most things
					// we open it and close in main
					//DEBUG("systemlib found\n");
					DEBUG("Calling systemlib\n");
					
					if( strcmp( path->parts[ 0 ], "system.library" ) == 0 )
					{
						DEBUG( "%s\n", path->parts[1] );
						response = SLIB->SysWebRequest( SLIB, &(path->parts[1]), request );
						
						if( response == NULL )
						{
							struct TagItem tags[] = {
								{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
								{TAG_DONE, TAG_DONE}
							};	
		
							response = HttpNewSimple(  HTTP_500_INTERNAL_SERVER_ERROR,  tags );
	
							result = 500;
						}
					}
					else
					{
						FriendCoreInstance_t *fci = (FriendCoreInstance_t *) sock->s_Data;
						Library* lib = FriendCoreGetLibrary( fci, path->parts[0], 1 );
						if( lib && lib->WebRequest )
						{
							response =(Http *) lib->WebRequest( lib, path->parts[1], request );
							if( response == NULL )
							{
								struct TagItem tags[] = {
									{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
									{TAG_DONE, TAG_DONE}
								};	
		
								response = HttpNewSimple( HTTP_500_INTERNAL_SERVER_ERROR,  tags );
	
								result = 500;
							}
						}
						else
						{
							struct TagItem tags[] = {
								{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
								{TAG_DONE, TAG_DONE}
							};	
		
							response = HttpNewSimple( HTTP_404_NOT_FOUND,  tags );
	
							result = 404;
						}
					}
				}
				// We're calling on a static file.
				else
				{
					//DEBUG("Getting resources\n");
					// Read the file
					Path *base = PathNew( "resources" );
					Path* complete = PathJoin( base, path );
					BOOL freeFile = FALSE;
					
					LocFile* file = CacheManagerFileGet( SLIB->cm, complete->raw );
					if( file == NULL )
					{
						file = LocFileNew( complete->raw, FILE_READ_NOW | FILE_CACHEABLE );
						if( file != NULL )
						{
							if( CacheManagerFilePut( SLIB->cm, file ) != 0 )
							{
								freeFile = TRUE;
							}
						}
					}

					// Send reply
					if( file != NULL )
					{
						char* mime = NULL;
						
						if(  file->buffer == NULL )
						{
							ERROR("File is empty %s\n", complete->raw );
						}

						if( complete->extension )
						{
							mime = StringDuplicate( MimeFromExtension( complete->extension ) );
						}
						else
						{
							mime = StringDuplicate( "text/plain" );
						}
						
						struct TagItem tags[] = {
							{ HTTP_HEADER_CONTENT_TYPE, (ULONG)  mime },
							{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
							{TAG_DONE, TAG_DONE}
						};
		
						response = HttpNewSimple( HTTP_200_OK, tags );

						
						//DEBUG("Before returning data\n");
						
						HttpSetContent( response, file->buffer, file->bufferSize );
						
						// write here and set data to NULL!!!!!
						// retusn response
						HttpWrite( response, sock );
						result = 200;
						
						INFO("--------------------------------------------------------------%d\n", freeFile );
						if( freeFile == TRUE )
						{
							//ERROR("\n\n\n\nFREEEEEEFILE\n");
							LocFileFree( file );
						}
						response->content = NULL;
						response->sizeOfContent = 0;
						
						response->h_WriteType = FREE_ONLY;
					}
					else
					{
						DEBUG( "[ProtocolHttp] Going ahead with %s.\n", path->parts ? path->parts[0] : "No path part.." );
						
						// Try to fall back on module
						// TODO: Make this behaviour configurable
						char command[255];
						sprintf( command, "php \"php/catch_all.php\" \"%s\";", uri->path->raw ); 
						DEBUG( "[ProtocolHttp] Executing %s\n", command );
						ListString *bs = RunPHPScript( command );
						int phpRun = FALSE;
						if( bs )
						{
							if( bs->ls_Size > 0 )
							{
								struct TagItem tags[] = {
									{ HTTP_HEADER_CONTENT_TYPE, (ULONG)  StringDuplicate( "text/html" ) },
									{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
									{TAG_DONE, TAG_DONE}
								};
		
								response = HttpNewSimple(  HTTP_200_OK,  tags );
						
								HttpSetContent( response, bs->ls_Data, bs->ls_Size );
								
								result = 200;
								phpRun = TRUE;
								bs->ls_Data = NULL;
							}
							ListStringDelete( bs );
						}
						
						if( !phpRun )
						{
							DEBUG("File do not exist\n");
							
							struct TagItem tags[] = {
								{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
								{TAG_DONE, TAG_DONE}
							};	
		
							response = HttpNewSimple( HTTP_404_NOT_FOUND,  tags );
	
							result = 404;
						}
					}
					
					PathFree( base );
					PathFree( complete );
				}
			}
			PathFree( path );
		}

		// SPRING CLEANING!!! TIME TO CLEAN THE CASTLE!!! :) :) :)
		HttpFreeRequest( request );
		
		if( result != 101 )
		{
			sock->data = NULL;
		}
		return response;
	}
	// Winter cleaning
	HttpFreeRequest( request );
	return response;
}
コード例 #13
0
ファイル: fsysphp.c プロジェクト: FriendSoftwareLabs/friendup
int MakeDir( struct File *f, const char *path )
{
	DEBUG("[fsysphp] makedir filesystem\n");
	if( f != NULL && f->f_SpecialData != NULL )
	{
		char *comm = NULL;
	
		// If we don't have a path or we have a path without colon, allocate
		// for a base path 
		if( strstr( path, ":" ) == NULL || !path )
		{
			comm = calloc( ( path ? strlen( path ) : 0 ) + 512, sizeof(char) );
			if( comm == NULL ) return -1;
		}
		// If we have comm or a path
		if( comm || path )
		{
			// If we have a comm
			if( comm )
			{
				strcpy( comm, f->f_Name );
				strcat( comm, ":" );
			}
			// A path and a comm, concat
			if( path != NULL && comm )
				strcat( comm, path ); 
				
			// No comm, just use path!
			if( !comm ) comm = StringDuplicate( path );
		
			SpecialData *sd = (SpecialData *)f->f_SpecialData;
	
			char command[ 2048 ];	// maybe we should count that...
		
			sprintf( command, "php \"modules/system/module.php\" \"module=files&command=dosaction&action=makedir&sessionid=%s&path=%s\";",
				f->f_SessionID, comm
			);
		
			DEBUG("[fsysphp] MAKEDIR %s\n", command );
	
			int answerLength = 0;
		
			ListString *result = PHPCall( command, &answerLength );
		
			if( result && result->ls_Size >= 0 )
			{
				if( strncmp( result->ls_Data, "fail", 4 ) == 0 )
				{
					ERROR( "[fsysphp] phpfs: Failed to execute makedir on device %s..\n", f->f_Name );
				}
			}
			else
			{
				ERROR( "[fsysphp] Unknown error unmounting device %s..\n", f->f_Name );
			}
	
			// TODO: we should parse result to get information about success
			if( result ) ListStringDelete( result );
		}
	}
	else
	{
		return -1;
	}
	return 1;
}
コード例 #14
0
ファイル: jc_scanner.c プロジェクト: nightstyles/focp
static void InitializeKeywordElem(CJcKeywordElem* elem, jc_char* sKey, jc_int nVal)
{
	elem->sKey = StringDuplicate(sKey);
	elem->nVal = nVal;
	elem->pNext = NULL;
}
コード例 #15
0
ファイル: locfile.c プロジェクト: eloekset/friendup
/**
 * Create new LocFile structure and read file from provided path
 *
 * @param path pointer to char table with path
 * @param flags additional flags used to open file
 * @return pointer to new LocFile when success, otherwise NULL
 */
LocFile* LocFileNew( char* path, unsigned int flags )
{
	if( path == NULL )
	{
		FERROR("File path is null\n");
		return NULL;
	}
	FILE* fp = fopen( path, "rb" );
	if( fp == NULL )
	{
		FERROR("Cannot open file %s (file does not exist?)..\n", path );
		return NULL;
	}
	
	struct stat st;
	if( stat( path, &st ) < 0 )
	{
		FERROR( "Cannot stat file: '%s'.\n", path );
		fclose( fp );
		return NULL;
	}
	
	if( S_ISDIR( st.st_mode ) )
	{
		FERROR( "'%s' is a directory. Can not open.\n", path );
		fclose( fp );
		return NULL;
	}
	DEBUG("Read local file %s\n", path );
	
	LocFile* fo = (LocFile*) FCalloc( 1, sizeof(LocFile) );
	if( fo != NULL )
	{
		fo->lf_PathLength = strlen( path );
		fo->lf_Path = StringDuplicateN( path, fo->lf_PathLength );
		fo->lf_Filename = StringDuplicate( GetFileNamePtr( path, fo->lf_PathLength ) );
		
		MURMURHASH3( fo->lf_Path, fo->lf_PathLength, fo->hash );
		
		DEBUG("PATH: %s\n", fo->lf_Path );
		
		memcpy(  &(fo->lf_Info),  &st, sizeof( struct stat) );

		fseek( fp, 0, SEEK_END );
		long fsize = ftell( fp );
		fseek( fp, 0, SEEK_SET );  //same as rewind(f);
		fo->lf_FileSize = fsize;// st.st_size; //ftell( fp );

		if( flags & FILE_READ_NOW )
		{
#if LOCFILE_USE_MMAP == 0
			LocFileRead( fo, fp, 0, fo->lf_FileSize );
#else

			fo->lf_Buffer = mmap(NULL/*address can be anywhere*/,
					fo->lf_FileSize/*map whole file*/,
					PROT_READ,
					MAP_SHARED | MAP_POPULATE,
					fileno(fp),
					0/*beginning of file*/);
			//DEBUG("***************** Mapping length: %d at %p\n", fo->lf_FileSize, fo->lf_Buffer);

#endif
		}
	}
	else
	{
		FERROR("Cannot allocate memory for LocFile\n");
	}
	
#if LOCFILE_USE_MMAP == 0
	fclose( fp );
#endif
	
	return fo;
}
コード例 #16
0
void *GetStructureFromJSON( ULONG *descr, const char *jsondata )
{
	char tmpQuery[ 1024 ];
	void *firstObject = NULL;
	void *lastObject = NULL;
	
	DEBUG("[GetStructureFromJSON] Load\n");
	
	if( jsondata == NULL  )
	{
		ERROR("Cannot parse NULL!\n");
		return NULL;
	}
	
	if( descr == NULL  )
	{
		ERROR("Data description was not provided!\n");
		return NULL;
	}
	
	if( descr[ 0 ] != SQLT_TABNAME )
	{
		ERROR("SQLT_TABNAME was not provided!\n");
		return NULL;
	}
	
	INFO("Start\n");
	
	int j = 0;
	json_char* json;
	json_value* value;
	MinNode *node = NULL;
	
		//[{'ID'= '1' , 'Name'= 'testowa' , 'API'= '11' , 'Version'= '1' , 'Author'= 'stefanek' , 'Email'= '1' , 'Description'= '*****@*****.**' , 'PEGI'= '0' , 'DateCreated'= '18' , 'DateInstalled'= '2015' }]
	//json = (json_char*)"{ \"applications\" :  [  {\"ID\": \"1\" , \"Name\": \"testowa\" , \"API\": \"11\" , \"Version\": \"1\" , \"Author\": \"stefanek\" , \"Email\": \"1\" , \"Description\": \"[email protected]\" , \"PEGI\": \"0\" , \"DateCreated\": \"18\" , \"DateInstalled\": \"2015\" }] }";

	json = (json_char*)jsondata;
	
	//DEBUG("[GetStructureFromJSON] Before parse  -> '%s' \n", json );

	value = json_parse( json, strlen( json ) );

	if (value == NULL) 
	{
		ERROR("Cannot parse string to object\n");
		return NULL;
	}
	
	if( value->type == json_object || value->type == json_array )			// ''main object"
	{
		//DEBUG("OBJECT NAME = %s value array length %d\n", value->u.object.values[0].name, value->array.length );
		
		json_value* arrval;
		
		
		DEBUG("Parse arrval type %d value type %d \n", value->type, value->type );
		
		if( value->type == json_object )
		{
			void *data = calloc( 1, descr[ SQL_DATA_STRUCTURE_SIZE ] );
		
			UBYTE *strptr = (UBYTE *)data;	// pointer to structure to which will will insert data
			ULONG *dptr = &descr[ SQL_DATA_STRUCT_START ];		// first 2 entries inform about table and size, rest information provided is about columns
				
			unsigned int i;
			
			lastObject = data;
			
			for( i=0 ; i < value->u.object.length ; i++ )
			{
				//printf("------%d ---- %s\n", i, value->u.object.values[ i ].name );
			}
			
			//DEBUG("Found obejct\n");
			
			while( dptr[0] != SQLT_END )
			{
				switch( dptr[ 0 ] )
				{
					case SQLT_NODE:
					{
					}
					break;
					
					case SQLT_IDINT:	// primary key
					case SQLT_INT:
					{
						int retPos = -1;
						//DEBUG("FIND INT!\n");
						
						for( i = 0; i <  value->u.object.length; i++) 
						{
							//DEBUG("aaaaaaaaaaobject[%d].name = %s\n", i, locaval->u.object.values[i].name);
							if( strcmp( value->u.object.values[i].name, (char *) dptr[1] ) == 0 )
							{
								retPos = i;
							}
						}
						
						json_value*mval = NULL;
						if( retPos >= 0 )
						{
							mval = value->u.object.values[retPos].value;
						}
						
						if( retPos >= 0 && mval->type == json_integer )
						{
							//DEBUG("ENTRY FOUND %s  int val %d\n",(char *) dptr[ 1 ], mval->u.integer );
							memcpy( strptr + dptr[ 2 ], &(mval->u.integer), sizeof( int ) );
						}
					}
					break;
						
					case SQLT_STR:
					case SQLT_TIMESTAMP:
					{
						int retPos = -1;
						for( i = 0; i <  value->u.object.length; i++) 
						{
							//DEBUG("aaaaaaaaaaobject[%d].name = %s\n", i, value->u.object.values[i].name);
							if( strcmp( value->u.object.values[i].name, (char *)dptr[1] ) == 0 )
							{
								retPos = i;
							}
						}
						
						json_value*mval = NULL;
						
						if( retPos >= 0 )
						{
							mval = value->u.object.values[retPos].value;
						}
						
						if( retPos >= 0  && mval->type == json_string && mval->u.string.ptr != NULL )
						{
							//DEBUG("STRENTRY FOUND %s data %s\n", (char *)dptr[ 1 ], mval->u.string.ptr );
							
							// this is date
							if( strlen( mval->u.string.ptr ) == 19 && mval->u.string.ptr[ 5 ] == '-' && mval->u.string.ptr[ 8 ] == '-' )
							{
								char *ptr = NULL;
								struct tm ltm;
							
								//DEBUG("TIMESTAMP load\n");
							
								//ptr = strptime( row[ i ], "%C%y-%m-%d %H:%M:%S", &ltm );
								if( ptr != NULL )
								{
									// REMEMBER, data fix
								
									ltm.tm_year += 1900;
									ltm.tm_mon ++;
								
									memcpy( strptr+ dptr[ 2 ], &ltm, sizeof( struct tm) );
								
									//DEBUG("Year %d  month %d  day %d\n", ltm.tm_year, ltm.tm_mon, ltm.tm_mday );
								}
							}
							else		// this is string
							{
								char *tmpval = StringDuplicate( mval->u.string.ptr );
								memcpy( strptr+ dptr[ 2 ], &tmpval, sizeof( char *) );
							}
						}
					}
					break;
				}
				i++;
				dptr += 3;
			}
		}
		else if( value->type == json_array )		// object contain our objects
		{
			arrval = value;
			
			int length = value->u.array.length;
			int x;
			for (x = 0; x < length; x++) // get object from array
			{
				json_value*locaval = value->u.array.values[x]; 
				
				void *data = calloc( 1, descr[ SQL_DATA_STRUCTURE_SIZE ] );
				if( firstObject == NULL )
				{
					firstObject = data;
				}
		
				UBYTE *strptr = (UBYTE *)data;	// pointer to structure to which will will insert data
				ULONG *dptr = &descr[ SQL_DATA_STRUCT_START ];		// first 2 entries inform about table and size, rest information provided is about columns
				
				int intlength = locaval->u.object.length;
				int i;
				
				while( dptr[0] != SQLT_END )
				{
					switch( dptr[ 0 ] )
					{
						case SQLT_NODE:
						{
							//DEBUG("Node found\n");
							MinNode *locnode = (MinNode *)(data + dptr[ 2 ]);
							locnode->mln_Succ = (MinNode *)lastObject;
							
							//DEBUG("\n\nlastObject %x currobject %x\n\n", lastObject, data );
						}
						break;
					
						case SQLT_IDINT:	// primary key
						case SQLT_INT:
						{
							int retPos = -1;
							for( i = 0; i < intlength; i++) 
							{
								//DEBUG("aaaaaaaaaaobject[%d].name = %s\n", i, locaval->u.object.values[i].name);
								if( strcmp( locaval->u.object.values[i].name, (char *) dptr[1] ) == 0 )
								{
									retPos = i;
								}
							}
							json_value*mval = locaval->u.object.values[retPos].value;
							
							if( retPos >= 0 && mval->type == json_integer )
							{
								//DEBUG("ENTRY FOUND %s  int val %d\n",(char *) dptr[ 1 ], mval->u.integer );
								memcpy( strptr + dptr[ 2 ], &(mval->u.integer), sizeof( int ) );
							}
						}
						break;
						
						case SQLT_STR:
						case SQLT_TIMESTAMP:
						{
							int retPos = -1;
							for( i = 0; i < intlength; i++) 
							{
								//DEBUG("aaaaaaaaaaobject[%d].name = %s\n", i, locaval->u.object.values[i].name);
								if( strcmp( locaval->u.object.values[i].name, (char *)dptr[1] ) == 0 )
								{
									retPos = i;
								}
							}
							
							json_value*mval = locaval->u.object.values[retPos].value;
							
							if( retPos >= 0  && mval->type == json_string && mval->u.string.ptr != NULL )
							{
								//DEBUG("STRENTRY FOUND %s data %s\n", (char *)dptr[ 1 ], mval->u.string.ptr );
								
								// this is date
								if( strlen( mval->u.string.ptr ) == 19 && mval->u.string.ptr[ 5 ] == '-' && mval->u.string.ptr[ 8 ] == '-' )
								{
									char *ptr = NULL;
									struct tm ltm;
							
									//DEBUG("TIMESTAMP load\n");
							
									//ptr = strptime( row[ i ], "%C%y-%m-%d %H:%M:%S", &ltm );
									if( ptr != NULL )
									{
										// REMEMBER, data fix
								
										ltm.tm_year += 1900;
										ltm.tm_mon ++;
								
										memcpy( strptr+ dptr[ 2 ], &ltm, sizeof( struct tm) );
								
										//DEBUG("Year %d  month %d  day %d\n", ltm.tm_year, ltm.tm_mon, ltm.tm_mday );
									}
								}
								else		// this is string
								{
									char *tmpval = StringDuplicate( mval->u.string.ptr );
									memcpy( strptr+ dptr[ 2 ], &tmpval, sizeof( char *) );
								}
							}
						}
						break;
					}
					i++;
					dptr += 3;
				}
				
				lastObject = data;
			}
		}
	}
	firstObject = lastObject;

	json_value_free( value );
	
	return firstObject;
}
コード例 #17
0
ファイル: imagelibrary.c プロジェクト: nupfel/friendup
		
		HttpAddTextContent( response, \
			"resize - resize image on filesystem\n \
			" );			// out of memory/user not found
		
		//HttpWriteAndFree( response );
	
		//
		// resize image on filesystem
		//
		
	}
	else if( strcmp( urlpath[ 0 ], "resize" ) == 0 )
	{
		struct TagItem tags[] = {
			{ HTTP_HEADER_CONTENT_TYPE, (ULONG)  StringDuplicate( "text/html" ) },
			{	HTTP_HEADER_CONNECTION, (ULONG)StringDuplicate( "close" ) },
			{TAG_DONE, TAG_DONE}
		};
		
			response = HttpNewSimple( HTTP_200_OK,  tags );
		
		char *path = NULL, *oPath = NULL;
		File *pathRoot = NULL;
		char toPath = NULL, *otoPath = NULL;
		File *toRoot = NULL;
		int width = 0, height = 0;
		char *error = NULL;
		
		HashmapElement *tst = HashmapGet( request->parsedPostContent, "path" );
		if( tst == NULL ) tst = HashmapGet( request->query, "path" );