BufString *Info( File *s, const char *path ) { DEBUG("Info!\n"); BufString *bs = BufStringNew(); int spath = strlen( path ); int rspath = strlen( s->f_Path ); DEBUG("Info!\n"); // user is trying to get access to not his directory DEBUG("Check access for path '%s' in root path '%s' name '%s'\n", path, s->f_Path, s->f_Name ); if( strncmp( path, s->f_Path, rspath ) != 0 ) { BufStringAdd( bs, "{ \"ErrorMessage\": \"No access to file\"}" ); } else { struct stat ls; if( stat( path, &ls ) == 0 ) { FillStat( bs, &ls, s, path ); } else { BufStringAdd( bs, "{ \"ErrorMessage\": \"File or directory do not exist\"}" ); } } DEBUG("Info END\n"); return bs; }
BufString *Info( File *s, const char *path ) { DEBUG("Info!\n"); BufString *bs = BufStringNew(); int spath = strlen( path ); int rspath = strlen( s->f_Path ); BufStringAdd( bs, "ok<!--separate-->"); DEBUG("Info!\n"); // user is trying to get access to not his directory DEBUG("Check access for path '%s' in root path '%s' name '%s'\n", path, s->f_Path, s->f_Name ); int doub = strlen( s->f_Name ); char *comm = NULL; if( ( comm = calloc( rspath + spath + 512, sizeof(char) ) ) != NULL ) { strcpy( comm, s->f_Path ); if( comm[ strlen( comm ) -1 ] != '/' ) { strcat( comm, "/" ); } strcat( comm, &(path[ doub+2 ]) ); DEBUG("PATH created %s\n", comm ); struct stat ls; if( stat( comm, &ls ) == 0 ) { FillStat( bs, &ls, s, comm ); } else { BufStringAdd( bs, "{ \"ErrorMessage\": \"File or directory do not exist\"}" ); } free( comm ); } DEBUG("Info END\n"); return bs; }
BufString *Info( File *s, const char *path ) { DEBUG("[INRAM] Info!\n"); BufString *bs = BufStringNew(); BufStringAdd( bs, "ok<!--separate-->"); DEBUG("Info!\n"); // user is trying to get access to not his directory DEBUG("Check access for path '%s' in root path '%s' name '%s'\n", path, s->f_Path, s->f_Name ); int error = 0; SpecialData *srd = (SpecialData *) s->f_SpecialData; INRAMFile *dir =INRAMFileGetLastPath( srd->root, path, &error ); if( dir != NULL ) { FillStat( bs, dir, s, path ); } else { DEBUG("[INRAM] file stat FAIL %s\n", path ); SpecialData *locsd = (SpecialData *)s->f_SpecialData; SystemBase *l = (SystemBase *)locsd->sb; char buffer[ 256 ]; int size = snprintf( buffer, sizeof(buffer), "{ \"response\": \"%s\", \"code\":\"%d\" }", l->sl_Dictionary->d_Msg[DICT_FILE_OR_DIRECTORY_DO_NOT_EXIST] , DICT_FILE_OR_DIRECTORY_DO_NOT_EXIST ); BufStringAddSize( bs, buffer, size ); //BufStringAdd( bs, "{ \"response\": \"File or directory do not exist\"}" ); } DEBUG("[INRAM] Info END\n"); return bs; }
BufString *Dir( File *s, const char *path ) { BufString *bs = BufStringNew(); DEBUG("\n\n\n\n\n\n"); DEBUG("Dir!\n"); int error = 0; // user is trying to get access to not his directory SpecialData *srd = (SpecialData *) s->f_SpecialData; INRAMFile *dir =INRAMFileGetLastPath( srd->root, path, &error ); DEBUG("Path received, pointer to: %p path %s!\n", dir, path ); if( dir != NULL ) { int pos = 0; BufStringAdd( bs, "ok<!--separate-->"); BufStringAdd( bs, "[" ); INRAMFile *f = dir->nf_Children; // temporary solution, must be fixed char tempString[ 4096 ]; int plen = strlen( path ) - 1; DEBUG("going through children\n"); while ( f != NULL ) { if( plen > 0 && path[ plen ] == '/' ) { sprintf( tempString, "%s:%s%s",s->f_Name, path, f->nf_Name ); } else { sprintf( tempString, "%s:%s/%s",s->f_Name, path, f->nf_Name ); } if( pos != 0 ) { BufStringAdd( bs, "," ); } FillStat( bs, f, s, tempString ); pos++; DEBUG("Dir/PAth added %s\n", tempString ); f = (INRAMFile *) f->node.mln_Succ; } BufStringAdd( bs, "]" ); } else { //BufStringAdd( bs, "fail<!--separate-->Could not open directory."); int pos = 0; BufStringAdd( bs, "ok<!--separate-->"); BufStringAdd( bs, "[]" ); } DEBUG("Dir END %s\n", bs->bs_Buffer); return bs; }
BufString *Dir( File *s, const char *path ) { BufString *bs = BufStringNew(); int rspath = strlen( s->f_Path ); DEBUG("Dir!\n"); // user is trying to get access to not his directory int doub = strlen( s->f_Name ); char *comm = NULL; if( ( comm = calloc( rspath +512, sizeof(char) ) ) != NULL ) { strcpy( comm, s->f_Path ); if( comm[ strlen( comm ) -1 ] != '/' && s->f_Path[ strlen(s->f_Path)-1 ] != '/' ) { DEBUG("Added '/\n"); strcat( comm, "/" ); } strcat( comm, path ); //&(path[ doub+1 ]) ); if( comm[ strlen( comm ) -1 ] != '/' ) { DEBUG("end was not endeed /\n"); strcat( comm, "/" ); } char tempString[ 1024 ]; DIR *d; struct dirent *dir; DEBUG("DIR -> directory '%s' for path '%s' devname '%s' double %d devpath '%s'\n", comm, path, s->f_Name, doub, s->f_Path ); d = opendir( comm ); if( d ) { int pos = 0; BufStringAdd( bs, "ok<!--separate-->"); //BufStringAdd( bs, "ok<!--separate-->[" ); BufStringAdd( bs, "[" ); while ((dir = readdir(d)) != NULL) { if( dir->d_name[ 0 ] == '/' ) { sprintf( tempString, "%s%s", comm, &(dir->d_name[1]) ); } else { sprintf( tempString, "%s%s", comm, dir->d_name ); } struct stat ls; //DEBUG("---------------> %s\n", dir->d_name ); if( stat( tempString, &ls ) == 0 ) { if( !(strcmp( dir->d_name, "." ) == 0 || strcmp( dir->d_name, ".." ) == 0 ) ) { if( pos != 0 ) { BufStringAdd( bs, "," ); } FillStat( bs, &ls, s, tempString ); pos++; } } } BufStringAdd( bs, "]" ); closedir( d ); } else { BufStringAdd( bs, "fail<!--separate-->Could not open directory."); } free( comm ); } DEBUG("Dir END\n"); return bs; }
virtual void Next() { dir_ent = readdir(dir); FillStat(); }