Beispiel #1
0
  // File consumption
  bool fileConsume( istream & argstream )
  {
    char c = '\0';
    size_t pos = 0;
    ofstream ofile;
    bool haveFile = filename.length() > 0;
    writelog2( "Consuming and saving file: ", filename );
    if( haveFile )
    {
      ofile.open( filename.c_str(), ios::out | ios::trunc | ios::binary );
    }
    writelog2( "fileBoundaryLen: " , fileBoundaryLen );
    // fill the buffer
    while( argstream.rdstate() == ios::goodbit &&
           pos < fileBoundaryLen &&
           argstream.get(c) )
    {
      testdata[pos++] = c;
    }
    writelog2( "final file testdata pos: ", pos-1 )

    // scan the buffer
    while( argstream.rdstate() == ios::goodbit &&
           fileBoundary != testdata &&
           argstream.get(c) )
    {
      if( haveFile )  ofile.put(testdata[0]);
      memmove( testdata, testdata + 1, fileBoundaryLen );
      testdata[fileBoundaryLen-1]=c;
    }
    writelog2( "Closing file: ", boundary );
    if( haveFile ) ofile.close();
    
    return true;
  }
Beispiel #2
0
 multipart( string inBoundary, queryStringMap & inVars, ocFiles  & fileMap, string iPath )
 :testdata(NULL),boundaryLen(0),state(init),rMap(inVars),rFileMap(fileMap),path(iPath)
 {
   clrf = "\r\n";
   fileBoundary = clrf;
   boundary = inBoundary;
   writelog2( "boundary: ", boundary );
   fileBoundary += inBoundary;
   endboundary = boundary;
   endboundary += "--";
   writelog2( "endboundary: ", endboundary );
   boundaryLen = boundary.length();
   fileBoundaryLen = fileBoundary.length();
   testdata = new char[fileBoundaryLen+1]; // for terminating null
   memset(testdata, 0, fileBoundaryLen+1); // initially zero length string
 }
Beispiel #3
0
 void fixupFilename( string temp )
 {
   value = "";
   filename = "";
   writelog2("fixupFilename: checking length of",temp);
   if(temp.length())
   {
     // now for stupid IE browsers that give us the WHOLE MSDOSLIKE FILE PATH!            
     string::size_type idx = temp.find_last_of("\\");
     if( idx != string::npos )
     {
       temp = temp.substr(idx+1);
     }       
     // finally set the filename
     writelog("fixupFilename adding path");
     filename = path;
     writelog("fixupFilename adding filename")
     filename += temp;
     value = temp;
   }    
   writelog2("fixupFilename  Done!", value);
 }
Beispiel #4
0
 // file dump of cgi input
 bool fileDump( istream & argstream )
 {
   char c = '\0';
   size_t pos = 0;
   ofstream ofile;
   filename = "cgiDump.log";    
   writelog2( "Dumping file: ", filename );
   ofile.open( filename.c_str(), ios::out | ios::trunc | ios::binary );    
   while( argstream.rdstate() == ios::goodbit &&
          argstream.get(c) )
   {
     ofile.put(c);
   }    
   ofile.close();
   
   return true;
 }
Beispiel #5
0
  void checkForfilesToDelete(cgiScript & script)
  {
    cgiInput & args = script.ClientArguments(); 
    if( args.count("delete") > 0 && args["delete"].length() > 0)
    {
      string delPath = m_fileDir;      
      delPath +="/";
      delPath += args["delete"].c_str();

      writelog2(  "Deleting ", delPath );
      // remove the file
      if( !fs.remove(delPath) )
      {
        script << "Error Deleting " << delPath << " - " << fs.check();
      }
    }
  }
Beispiel #6
0
 bool getline(  istream & argstream )
 {
   char term;
   if( argstream.rdstate() == ios::goodbit &&
       state != readFile ) // don't want to steal first line from inline file
   {
     // try this:      
     std::getline(argstream, testline);
     
     // remove the CR of the CRLF pair
     if( testline.length() ) testline.resize( testline.length() - 1 );
     // prepare testline for parsing
     testline.parseInit();
     // to the log if loggin enabled
     writelog2( "multipart::getline got: ", testline );
   }
   return true;
 }
Beispiel #7
0
extvec * J(matr * A, const extvec * b, int max_it, REAL tol, extvec *& X, size_t & iters, REAL undef_value) {

	int flag = 0;                                // initialization
	int iter = 0;
	iters = 0;
	
	REAL bnrm2 = norm2( b );
	if  ( bnrm2 == REAL(0) )
		bnrm2 = REAL(1); 

	extvec * x = NULL;
	if (!X) 
		x = create_extvec(*b);
	else 
	{
		x = X;
		X = NULL;
	}

	writelog2(LOG_MESSAGE,"jacobi: (%d) ",x->size());

	REAL error = FLT_MAX;
	REAL error_norm = bnrm2;	
	REAL sigma = 0;
	int i;

	int n = b->size();
	REAL a_ii;

	REAL MM = A->norm();
	REAL gamma = REAL(2)/(MM);
	REAL save_x;

	extvec * x_1 = create_extvec(*x);

	error_norm = norm2(x, undef_value);
		
	for (iter = 0; iter < max_it; iter++) {

		for (i = 0; i < n; i++) {
			
			a_ii = A->at(i,i);
			if (a_ii == REAL(0)) 
				continue;

			save_x = (*x)(i);
			(*x)(i) = 0;
			sigma = A->mult_line(i, x->const_begin(), x->const_end());
			(*x)(i) = save_x;

			(*x_1)(i) = ( ((*b)(i) - sigma )/a_ii -(*x)(i))*gamma + (*x)(i);
			
		}

		// compute residual
		error = 0;
		for (i = 0; i < n; i++) {
			error = MAX( error, fabs((*x_1)(i) - (*x)(i)) );
		}
		error /= error_norm;
		if ( (error < tol) || (stop_execution == 1))
			break;
		
		*x = *x_1;

	}

	if (x_1)
		x_1->release();
	
	log_printf("error : %12.6G iter : %d\n", error, iter);

	iters = (size_t)iter;

	return x;
	
};
Beispiel #8
0
bool f_lcm_simple::minimize() {

	writelog(LOG_MESSAGE,"lcm_simple : processing...");

	bool res = true;

	if (gfaults)
		gfaults->release();
	gfaults = NULL;
	size_t q, f_cnt = 0;
	bool have_faults = false;
	for (q = 0; q < functionals->size(); q++)
	{
		functional * f = (*functionals)[q];
		if (f->get_pos() >= get_pos())
			break;
		if (f->getType() != F_MODIFIER)
			continue;
		f_fault * flt = dynamic_cast<f_fault*>(f);
		if (flt == NULL)
			continue;

		const d_curv * fault_crv = flt->get_fault();
		if (fault_crv == NULL)
			continue;
		if (!have_faults) {
			writelog2(LOG_MESSAGE,"trend_faults: \"%s\"", fault_crv->getName());
			have_faults = true;
			f_cnt++;
		} else {
			if (f_cnt % 4 != 0) 
				log_printf(", \"%s\"", fault_crv->getName());
			else
				log_printf("\"%s\"", fault_crv->getName());
			f_cnt++;
			if (f_cnt % 4 == 0) {
				log_printf("\n");
				writelog2(LOG_MESSAGE,"              ");
			}
		}
		gfaults = curv_to_grid_line(gfaults, fault_crv, method_grid);
	}
	if (have_faults)
		log_printf("\n");

	if ( cond() ) {

		res = minimize_step() && res;

	} else { // use some optimizations

		if (reproject_faults && gfaults) {
			if (method_prev_grid != NULL) {
				writelog(LOG_MESSAGE,"reprojecting with faults...");
				
				bitvec * saved_mask_solved = create_bitvec(method_mask_solved);
				method_mask_solved->init_false();
				
				int size = method_mask_solved->size();
				int i;
				for (i = 0; i < size; i++) {
					
					if (!gfaults->check_for_node(i)) 
						method_mask_solved->set_true(i);
					
				};
				
				res = minimize_step() && res;

				method_mask_solved->copy(saved_mask_solved);
				if (saved_mask_solved)
					saved_mask_solved->release();
			}
		}

		if (reproject_undef_areas) {
			if (method_prev_grid != NULL) {
				writelog(LOG_MESSAGE,"reprojecting with undef areas...");
											
				grid_line * undef_grd_line = trace_undef_grd_line(method_mask_undefined, method_grid->getCountX());
				if (undef_grd_line) {
					
					bitvec * saved_mask_solved = create_bitvec(method_mask_solved);
					int size = method_mask_solved->size();
					int i;
					
					for (i = 0; i < size; i++) {
						if (!undef_grd_line->check_for_node(i)) 
							method_mask_solved->set_true(i);
					};
					
					res = minimize_step() && res;
					
					undef_grd_line->release();
					method_mask_solved->copy(saved_mask_solved);
					if (saved_mask_solved)
						saved_mask_solved->release();
					
				}

			}
		}

		size_t matrix_size = method_basis_cntX*method_basis_cntY;

		shortvec * flood_areas = create_shortvec(matrix_size);
		int flood_areas_cnt = 0;

		fill_all_areas(flood_areas, method_grid, gfaults, flood_areas_cnt, method_mask_undefined);

		if ((flood_areas_cnt > 1) && (process_isolated_areas)) {
			
			writelog(LOG_MESSAGE,"flood_areas_cnt = %d", flood_areas_cnt);
			writelog(LOG_MESSAGE,"processing each isolated area (%d)...", flood_areas_cnt);
			
			bitvec * saved_mask_solved = create_bitvec(method_mask_solved);
			bitvec * saved_mask_undefined = create_bitvec(method_mask_undefined);
			
			int color;
			size_t f_size = flood_areas->size();
			
			bool undef, solved;
			
			size_t pos = 0;
			int exists = 0;
			
			for (color = 1; color <= flood_areas_cnt; color++) {
				
				method_mask_undefined->copy(saved_mask_undefined);
				method_mask_solved->copy(saved_mask_solved);
				
				for (pos = 0; pos < f_size; pos++) {
					if ( (*flood_areas)(pos) != color ) {
						method_mask_undefined->set_true(pos);
						method_mask_solved->set_false(pos);
					}
				}
				
				res = minimize_step() && res;
				
				for (pos = 0; pos < f_size; pos++) {
					if ( (*flood_areas)(pos) == color ) {
						
						undef = method_mask_undefined->get(pos);
						if (undef)
							saved_mask_undefined->set_true(pos);
						else 
							saved_mask_undefined->set_false(pos);
						
						solved = method_mask_solved->get(pos);	
						if (solved)
							saved_mask_solved->set_true(pos);
						else
							saved_mask_solved->set_false(pos);
						
					}
				}
				
			};
						
			method_mask_solved->copy(saved_mask_solved);
			method_mask_undefined->copy(saved_mask_undefined);
			
			if (saved_mask_solved)
				saved_mask_solved->release();
			if (saved_mask_undefined)
				saved_mask_undefined->release();
			
		}

		if (flood_areas)
			flood_areas->release();
		
		writelog(LOG_MESSAGE,"processing whole grid...");
		res = minimize_step(); // && res;

	}

	return res;
};
Beispiel #9
0
 // data consumption is line oriented until we get to a file attachment
 bool consume( istream & argstream )
 {
   bool bret = true;
   ocString test;
   while(  argstream.rdstate() == ios::goodbit &&
           state != eof &&
           getline( argstream ) )
   {
     writelog2("Consumed",testline);
     switch( state )
     {
     case init:
       // check to see if we just consumed the boundary
       if( boundary != testline )
       {
         state = eof;
       }
       else
       {
         state = newData;
       }
       break;
     case newData:
       // should be reading the content disposition line
       test = testline.parse(": ");
       transform(test.begin(),test.end(),test.begin(),::tolower);
       writelog2("Testing",test);
       if( test == "content-disposition" )
       {
         // good - see what the data is
         test = testline.parse("; ");          
         // Added :: prefix to tolower so SGI recognizes global scope C function
         transform(test.begin(),test.end(),test.begin(),::tolower);          
         // expect it to be form-data
         writelog2("Content Testing",test);
         if( test == "form-data" )
         {
           // parse any remaining parameters
           while( testline.length() && !testline.endOfParse() )
           {
             ocString test = testline.parse("; ");
             writelog2("Param Testing",test);
             if( test.length() )
             {
               string paramname=test.parse("=\"");
               // Added :: prefix to tolower so SGI recognizes global scope C function
               transform(paramname.begin(),paramname.end(),paramname.begin(),::tolower);
               // could be name or filename
               if( paramname == "name" )
               {
                 // set the name
                 name = test.parse("\"");
                 state = dataSep;
               }
               else if( paramname == "filename" )
               {
                 writelog2("Fix Filename",test);
                 fixupFilename(test.parse("\""));
                 writelog("Filename Fixed");
                 state = fileType;
               }
             }
           }
         }
       }
       else
       {
         // unexpected place so abort method call
         state = eof;
       }
       break;
     case fileType:
       // expect Content-Type: image/jpeg
       test = testline.parse(": ");
       // Added :: prefix to tolower so SGI recognizes global scope C function
       transform(test.begin(),test.end(),test.begin(),::tolower);
       if( test == "content-type" )
       {
         type = testline.remainder();
         state = fileSep;
       }
       else
       {
         state = eof;
       }
       break;
     case fileSep:
       if(testline.length() == 0)
       {
         state = readFile;
       }
       else
       {
         state = eof;
       }
       break;
     case dataSep:
       // expect an empty line
       if(testline.length() == 0)
       {
         state = readData;
       }
       else
       {
         state = eof;
       }
       break;
     case readData:
       // expect the data
       dataConsume(argstream);
       break;
     case readFile:
       fileConsume(argstream);
       addFile();
       addDataItem();
       // fileConsume also consumes the boundary (up to the (potential) -- closing)
       state = fileRead;
       break;
     case fileRead:
       if( testline == "--" )
       {
         state = eof;
       }
       state = newData;
       break;
     case finished:
       // see if there is another boundary:
       if( boundary == testline )
       {
         state = newData; // note that the terminating boundary will have -- at the end
       }
       else
       {
         state = eof;
       }
       break;
     default:
       state = eof;
       break;
     } // end switch
   }  // end while
   return bret;
 }