Beispiel #1
0
char *loadPrefFile()
{
	if(!checkFileExist(SETTINGS_FILE) && checkFileExist(SETTINGS_FILE".tmp"))
		rename(SETTINGS_FILE".tmp", SETTINGS_FILE);

	size_t filesize = getFileSize(SETTINGS_FILE);

    if(filesize == 0)
		return NULL;
	
    char * output = calloc(filesize + 10, sizeof(char));
    if(output == NULL)
        return NULL;

	AESDecrypt(SETTINGS_PASSWORD, SETTINGS_FILE, output, OUTPUT_IN_MEMORY);

    if(output[0] != '<')
    {
#ifdef EXTENSIVE_LOGGING
		logR("Incorrect settings decryption: %s", output);
#else
		logR("Incorrect settings decryption");
#endif
		
        free(output);
		output = NULL;
    }

	return output;
}
Beispiel #2
0
void Cards_install::getLocalePackagesList()
{
	if (m_config.locale.empty())
		return;
	std::vector<std::string> tmpList;
	for ( auto i :  m_config.locale ) {
		for ( auto j :m_dependenciesList ) {
			std::string packageName  = j + "." + i;
#ifndef NDEBUG
			std::cerr << packageName << endl;
#endif
			if (checkBinaryExist(packageName)) {
				m_packageFileName = getPackageFileName(packageName);
				if ( ! checkFileExist(m_packageFileName) )
					downloadPackageFileName(packageName);
				tmpList.push_back(packageName);
			}
		}
		if (tmpList.size() > 0 )
			for (auto i : tmpList) m_dependenciesList.push_back(i);
	}
#ifndef NDEBUG
	for (auto i : m_dependenciesList ) std::cerr << i << endl;
#endif
}
Beispiel #3
0
bool C45Reader::setFile(const string& fileName) {

	renew();

	if (!checkFileExist(fileName)) {
		return false;
	}

	if (readAllDataFromNamesFile(fileName + ".names") != 0) {
		return false;
	}

	mNamesLoaded = true;

	string f = fileName + ".data";
	if (openDataFile(f) != 0) {
		return false;
	}

	// read first row
	if (readData() != 0) {
		return false;
	}

	return true;
}
Beispiel #4
0
void dumpTagCat(TAG_VERBOSE * tags, uint nbTags, CATEGORY_VERBOSE * category, uint nbCat)
{
	MUTEX_LOCK(concurentColdUpdate);
	
	//Delete a temporary file if Rak crashed while working on it
	if(checkFileExist(WIP_TAG_DB))
		remove(WIP_TAG_DB);
	
	//Open the database
	sqlite3 * newDB = NULL;
	if(sqlite3_open(WIP_TAG_DB, &newDB) != SQLITE_OK)
	{
		logR("Couldn't open the temporary database");
		return;
	}
	else
		createTagsTable(newDB);
	
	//Dump the content using our helpers
	tagUpdateCachedEntryWithRequest(tagUpdateQuery(newDB, false), tags, nbTags);
	catUpdateCachedEntryWithRequest(catUpdateQuery(newDB, false), category, nbCat);
	
	//Closing the DB, then swapping the files
	sqlite3_close(newDB);
	
	remove(OLD_TAG_DB);
	rename(TAG_DB, OLD_TAG_DB);
	rename(WIP_TAG_DB, TAG_DB);
	
	MUTEX_UNLOCK(concurentColdUpdate);
}
Beispiel #5
0
    bool Trie::loadDict(const char * const filePath)
    {
        if(!_getInitFlag())
        {
            LogError("not initted.");
            return false;
        }

        if(!checkFileExist(filePath))
        {
            LogError("cann't find fiel[%s].",filePath);
            return false;
        }
        bool res = false;
        res = _trieInsert(filePath);
        if(!res)
        {
            LogError("_trieInsert failed.");
            return false;
        }
        res = _countWeight();
        if(!res)
        {
            LogError("_countWeight failed.");
            return false;
        }
        return true;
    }
Beispiel #6
0
/**
*@description send requested file to sock
*@param sockFd int  socket Id
*@param request Request  http_request struct
*@return if failed, return negative number, otherwise, nonnegative
*/
int sendRequestedFile(int sockFd, Request * httpRequest) {
	char ok_line[]       = "HTTP/1.0 200 OK\r\n";
	char badReq_line[]   = "HTTP/1.0 400 Bad Request\r\n";  
	char badReq_content[] = "<html><head></head><body><h1>400 Bad Request</h1></body></html>";
	char notFound_line[] = "HTTP/1.0 404 Not Found\r\n";
	char notFound_content[] = "<html><head></head><body><h1>404 Not Found</h1></body></html>";
	char suffix_line[]   = "\r\n";
	char writeBuffer[MAX_WRITE_BUFFER];
	char * responseLine;
	char *filePath = (httpRequest->requestLine).path;
	int fileSize;
	if (!checkFileExist(filePath)) {
	  printf("file %s doesn't exist\n", filePath);
	}
	short isResolved = httpRequest->isResolved;
	if ( isResolved ) {
		fileSize = getFileSize(filePath);
		if (fileSize < 0) {
			printf("request file %s not found, so send 404 response\n", filePath);
			if (send(sockFd, notFound_line, strlen(notFound_line), 0) < 0) {
				return -1;
			}

			//send content length
			memset(writeBuffer, '\0', sizeof(writeBuffer));
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %lu\r\n","Content-Length",strlen(notFound_content));
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}

			//send persistent header
			memset(writeBuffer, '\0', sizeof(writeBuffer));
			if (httpRequest->isAlive == persistent) {
				snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Connection", "keep-alive");
			} else {
				snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Connection", "close");
			}
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}

			//send content-type header
			memset(writeBuffer, '\0', sizeof(writeBuffer));
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Content-Type", "text/html");
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}
			
			//send Date
			memset(writeBuffer, '\0', sizeof(writeBuffer));
			time_t current = time(0);
			time_t expire  = current + 60;
			struct tm currentTm = *gmtime(&current); 
			struct tm expireTm  = * gmtime(&expire);
			char timeStr[128];
			memset(timeStr, '\0', sizeof(timeStr));
			strftime(timeStr, sizeof(timeStr), "%a, %d %b %Y %H:%M:%S %Z", &currentTm);
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Date", timeStr);
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}

			memset(writeBuffer, '\0', sizeof(writeBuffer));
			memset(timeStr, '\0', sizeof(timeStr));
			strftime(timeStr, sizeof(timeStr), "%a, %d %b %Y %H:%M:%S %Z", &expireTm);
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Expires", timeStr);
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}
			//send suffix line
			if (send(sockFd, suffix_line, strlen(suffix_line), 0) < 0) {
				return -1;
			}
			//send content
			if (send(sockFd, notFound_content, strlen(notFound_content), 0) < 0) {
				return -1;
			}

			return 0;
		} else {

			printf("start to send request file of size %d bytes...\n", fileSize);
			//send 200 OK status line
			if (send(sockFd, ok_line, strlen(ok_line), 0) < 0) {
				return -1;
			}

			//send content-length header
			memset(writeBuffer, '\0', sizeof(writeBuffer));
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %d\r\n", "Content-Length", fileSize);
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}
			
			//send persistent header
			memset(writeBuffer, '\0', sizeof(writeBuffer));
			if (httpRequest->isAlive == persistent) {
				snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Connection", "keep-alive");
			} else {
				snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Connection", "close");
			}
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}

			//send content-type header
			memset(writeBuffer, '\0', sizeof(writeBuffer));
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Content-Type", "text/html");
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}
			
			//send Date
			memset(writeBuffer, '\0', sizeof(writeBuffer));
			time_t current = time(0);
			time_t expire  = current + 60;
			struct tm currentTm = *gmtime(&current); 
			struct tm expireTm  = * gmtime(&expire);
			char timeStr[128];
			memset(timeStr, '\0', sizeof(timeStr));
			strftime(timeStr, sizeof(timeStr), "%a, %d %b %Y %H:%M:%S %Z", &currentTm);
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Date", timeStr);
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}

			memset(writeBuffer, '\0', sizeof(writeBuffer));
			memset(timeStr, '\0', sizeof(timeStr));
			strftime(timeStr, sizeof(timeStr), "%a, %d %b %Y %H:%M:%S %Z", &expireTm);
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Expires", timeStr);
			if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
				return -1;
			}
			//send suffix line
			if (send(sockFd, suffix_line, strlen(suffix_line), 0) < 0) {
				return -1;
			}
			
			//send request body
			if (transferFile(filePath, sockFd) == 0) {
				printf("send  file %s of %d bytes successfully\n", filePath, fileSize);
			} else {
				return -1;
			}
		}
	} else {
		printf("start to send 400 bad request\n");
		if (send(sockFd, badReq_line, strlen(badReq_line), 0) < 0 ) {
			return -1;
		}
		//send content length
		memset(writeBuffer, '\0', sizeof(writeBuffer));
		snprintf(writeBuffer, sizeof(writeBuffer), "%s: %lu\r\n","Content-Length",strlen(badReq_content));
		if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
			return -1;
		}

		//send persistent header
		memset(writeBuffer, '\0', sizeof(writeBuffer));
		if (httpRequest->isAlive == persistent) {
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Connection", "keep-alive");
		} else {
			snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Connection", "close");
		}
		if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
			return -1;
		}

		//send content-type header
		memset(writeBuffer, '\0', sizeof(writeBuffer));
		snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Content-Type", "text/html");
		if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
			return -1;
		}
		
		//send Date
		memset(writeBuffer, '\0', sizeof(writeBuffer));
		time_t current = time(0);
		time_t expire  = current + 60;
		struct tm currentTm = *gmtime(&current); 
		struct tm expireTm  = * gmtime(&expire);
		char timeStr[128];
		memset(timeStr, '\0', sizeof(timeStr));
		strftime(timeStr, sizeof(timeStr), "%a, %d %b %Y %H:%M:%S %Z", &currentTm);
		snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Date", timeStr);
		if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
			return -1;
		}

		memset(writeBuffer, '\0', sizeof(writeBuffer));
		memset(timeStr, '\0', sizeof(timeStr));
		strftime(timeStr, sizeof(timeStr), "%a, %d %b %Y %H:%M:%S %Z", &expireTm);
		snprintf(writeBuffer, sizeof(writeBuffer), "%s: %s\r\n", "Expires", timeStr);
		if (send(sockFd, writeBuffer, strlen(writeBuffer), 0) < 0) {
			return -1;
		}
		//send suffix line
		if (send(sockFd, suffix_line, strlen(suffix_line), 0) < 0) {
			return -1;
		}
		//send content
		if (send(sockFd, notFound_content, strlen(notFound_content), 0) < 0) {
			return -1;
		}
		return 0;
	}

	return 1;
}
int extractWaveSpectra (struct Mviewer *param)
{
    FILE   *fp;

    struct FitsHdr  hdr;

    char   str[1024];

    char   colname[40];
    char   datatype[40];
    char   null[40];
    char   unit[40];

    char   rootname[1024];
    char   suffix[40];

    int    istatus;
    int    status;
    int    fileExist; 

    long    nelements;
  
    int    iscube;    

    int    ixpix;
    int    iypix;

    int    ixs;
    int    iys;
    int    ixe;
    int    iye;

    double xs;
    double ys;
    double xe;
    double ye;

    int    npixel;

    int    l;
    int    j;
    int    i;
    int    nullcnt;

    long   fpixel[4];
    
    double *data;
    double *xarr;
    double *yarr;
    
    fitsfile  *infptr;


/*
     Make a NaN value to use setting blank pixels 
*/

    union
    {
       double d;
       char   c[8];
    }
    value;

    double nan;

    for(i=0; i<8; ++i)
       value.c[i] = 255;

    nan = value.d;

    
    int    debugfile = 1;


    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
        fprintf (fp_debug, "\nEnter extractWaveSpectra: cubepath= [%s]\n", 
            param->imcubepath);
        
        fprintf (fp_debug, "\nEnter extractWaveSpectra: imageFile= [%s]\n", 
            param->imageFile);

        fprintf (fp_debug, "\nshrunkimfile= [%s]\n", param->shrunkimfile);
        fprintf (fp_debug, "\nwaveplottype= [%s]\n", param->waveplottype);

        if (strcasecmp (param->waveplottype, "pix") == 0) {
            fprintf (fp_debug, "xs= [%lf] ys= [%lf]\n", 
                param->xs, param->ys);
        }
        else {
            fprintf (fp_debug, "xs= [%lf] ys= [%lf] xe= [%lf] ye= [%lf]\n", 
                param->xs, param->ys, param->xe, param->ye);
        }
        
        fprintf (fp_debug, "zoomfactor= [%lf]\n", param->zoomfactor);
        fprintf (fp_debug, "ss= [%lf] sl= [%lf\n", param->ss, param->sl);
        fprintf (fp_debug, "xflip= [%d] yflip= [%d]\n", 
            param->xflip, param->yflip);
        fflush (fp_debug);
    }


    iscube = 1;
    istatus = getFitshdr (param->imcubepath, &hdr, iscube); 
    
    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
        fprintf (fp_debug, "returned getFitshdr: istatus= %d\n", istatus);
        fflush (fp_debug);
    }

    if (istatus == -1) {
        sprintf (param->errmsg, "Failed to getFitshdr: FITS file %s\n", 
            param->imcubepath);
        return (-1);
    }

    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
        fprintf (fp_debug, "ns= [%d] nl= [%d] nplane= [%d]\n", 
            hdr.ns, hdr.nl, hdr.nplane);
        fprintf (fp_debug, "crval3= [%lf] cdelt3= [%lf]\n", 
            hdr.crval[2], hdr.cdelt[2]);
        fflush (fp_debug);
    }


/*
    Adjust xpix, ypix based on xflip, yflip
*/
    if (strcasecmp (param->waveplottype, "pix") == 0) {
    
        param->xpix = param->xs/param->zoomfactor + param->ss;
        param->ypix = param->ys/param->zoomfactor + param->sl;
        
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "xpix= [%lf] ypix= [%lf]\n", 
                param->xpix, param->ypix);
            fflush (fp_debug);
        }
        
        ixpix = (int)(param->xpix+0.5);
        iypix = (int)(param->ypix+0.5);

        if (param->xflip)
            ixpix = hdr.ns - ixpix;
        else
            ixpix = ixpix + 1;
    
        if (param->yflip)
            iypix = hdr.nl - iypix;
        else
            iypix = iypix + 1;
    
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "ixpix= [%d] iypix= [%d]\n", ixpix, iypix);
            fflush (fp_debug);
        }
        
    }
    else if (strcasecmp (param->waveplottype, "ave") == 0) {

        xs = param->xs/param->zoomfactor + param->ss;
        ys = param->ys/param->zoomfactor + param->sl;
        xe = param->xe/param->zoomfactor + param->ss;
        ye = param->ye/param->zoomfactor + param->sl;
        
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "xs= [%lf] ys= [%lf]\n", xs, ys);
            fprintf (fp_debug, "xe= [%lf] ye= [%lf]\n", xe, ye);
            fflush (fp_debug);
        }
        
        ixs = (int)(xs+0.5);
        iys = (int)(ys+0.5);
        ixe = (int)(xe+0.5);
        iye = (int)(ye+0.5);

        
        if (param->xflip) {
            ixs = hdr.ns - ixs;
            ixe = hdr.ns - ixe;
        }
        else {
            ixs = ixs + 1;
            ixe = ixe + 1;
        }
    
        if (param->yflip) {
            iys = hdr.nl - iys;
            iye = hdr.nl - iye;
        }
        else {
            iys = iys + 1;
            iye = iye + 1;
        }

        if (iys > iye) {
            i = iys;
            iys = iye;
            iye = i;
        }
        if (ixs > ixe) {
            i = ixs;
            ixs = ixe;
            ixe = i;
        }
    
        npixel = (ixe-ixs+1) * (iye-iys+1);
    
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "ixs= [%d] iys= [%d] ixe= [%d] iye= [%d]\n", 
                ixs, iys, ixe, iye);
            fprintf (fp_debug, "npixel= [%d]\n", npixel);
            fflush (fp_debug);
        }
    
    }


/*
    malloc plot arrays: xarr and yarr
*/
    xarr = (double *)malloc (hdr.nplane*sizeof(double));
    yarr = (double *)malloc (hdr.nplane*sizeof(double));
    for (i=0; i<hdr.nplane; i++) {
        xarr[i] = 0.;
        yarr[i] = 0.;
    }


/*
    Create plot xarr based on wavelen axis (i.e. crval3 and cdelt3)
*/
    for (i=0; i<hdr.nplane; i++) {
        xarr[i] = hdr.crval[2] + i*hdr.cdelt[2];
    }

/*
    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
        for (i=0; i<hdr.nplane; i++) {
            fprintf (fp_debug, "i= [%d] xarr= [%lf]\n", i, xarr[i]);
        }
        fflush (fp_debug);
    }
*/


/*
    Open cubefile for read
*/
    istatus = 0;
    if (fits_open_file (&infptr, param->imcubepath, READONLY, &status)) {

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
            fprintf (fp_debug, "istatus= [%d] status= [%d]\n", istatus, status);
            fflush (fp_debug);
        }

        sprintf (param->errmsg, "Failed to open FITS cubefile %s\n", 
            param->imcubepath);
        
        sprintf (param->retstr, "[struct stat=error, msg=%s]\n", 
            param->errmsg); 
        return (-1);
    } 
   

/*
    Read data from nth plane and write to output fitsfile
*/
    nelements = 1;
    data  = (double *)malloc(nelements*sizeof(double));

    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        fprintf (fp_debug, "waveplottype= [%s]\n", param->waveplottype);
        fflush (fp_debug);
    }         
        
    
    for (l=0; l<hdr.nplane; l++) { 

        fpixel[2] = l;
        fpixel[3] = 1;
        
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "l= [%d] fpixel[2]= [%ld]\n", l, fpixel[2]);
            fflush (fp_debug);
        }         
        
        if (strcasecmp (param->waveplottype, "pix") == 0) {

            if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                fprintf (fp_debug, "here1\n");
                fflush (fp_debug);
            }             
            
            fpixel[0] = ixpix;
            fpixel[1] = iypix;

            if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                fprintf (fp_debug, "ixpix= [%d] iypix= [%d]\n", ixpix, iypix);
                fprintf (fp_debug, "fpixel[0]= [%ld] fpixel[1]= [%ld]\n", 
                    fpixel[0], fpixel[1]);
                fprintf (fp_debug, "call fits_read_pix\n");
                fflush (fp_debug);
            }             

            istatus = 0;
            istatus = fits_read_pix (infptr, TDOUBLE, fpixel, nelements, &nan,
                (void *)data, &nullcnt, &istatus);
           
            if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                fprintf (fp_debug, "returned fits_read_pix: istatus= [%d]\n",
                    istatus);
                fflush (fp_debug);
            }    

            
            if (istatus == -1) {
                sprintf (param->errmsg, "Failed to read FITS file %s\n",
                    param->imcubepath);
                sprintf (param->retstr, "[struct stat=error, msg=%s]\n", 
                    param->errmsg); 
                return (-1);
            }

            if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                fprintf (fp_debug, "l= [%d] data= [%lf]\n", l, data[0]);
                fflush (fp_debug);
            }         

            yarr[l] = (double)data[0];
        }
        else if (strcasecmp (param->waveplottype, "ave") == 0) {

            for (j=iys; j<=iye; j++) {
                
                fpixel[1] = j;

/*
                if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                    fprintf (fp_debug, "j= [%d] fpixel[1]= [%ld]\n", 
                        j, fpixel[1]);
                    fflush (fp_debug);
                }        
*/

                for (i=ixs; i<=ixe; i++) {

                    fpixel[0] = i;

/*
                    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                        fprintf (fp_debug, "i= [%d] fpixel[0]= [%ld]\n", 
                            i, fpixel[0]);
                        fflush (fp_debug);
                    }
*/

                    istatus = 0;
                    istatus = fits_read_pix (infptr, TDOUBLE, fpixel, nelements, &nan, 
                                        (void *)data, &nullcnt, &istatus);


/*
                    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                        fprintf (fp_debug, 
                            "returned fits_read_pix: istatus= [%d]\n", istatus);
                        fflush (fp_debug);
                    }    
 */

                    if (istatus == -1) {
                        sprintf (param->errmsg, "Failed to read FITS file %s\n",
                            param->imcubepath);
                        sprintf (param->retstr, "[struct stat=error, msg=%s]\n",
                            param->errmsg); 
                        return (-1);
                    }
/*
                    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                        fprintf (fp_debug, "l= [%d] data= [%lf]\n", l, data[0]);
                        fflush (fp_debug);
                    }         
 */           
                    yarr[l] += (double)data[0]/npixel;
  /*                  
                    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                        fprintf (fp_debug, "yarr= [%lf]\n", yarr[l]);
                        fflush (fp_debug);
                    }         
   */         
                }
            }
        }

    }

/*
    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        for (l=0; l<hdr.nplane; l++) {
            fprintf (fp_debug, "l= [%d] xarr= [%lf] yarr= [%lf]\n", 
                l, xarr[l], yarr[l]);
        }
        fflush (fp_debug);
    }         
*/

    istatus = 0;
    if (fits_close_file (infptr, &istatus)) {
        sprintf (param->errmsg, "Failed to close imcubepath %s\n", 
            param->imcubepath);
        
        sprintf (param->retstr, "[struct stat=error, msg=%s]\n", 
            param->errmsg); 
        return (-1); 
    }
    

/*
    Write tblarr to output IPAC table
*/
    sprintf (param->plotfile, "%s_plot.tbl", param->imageFile);
    sprintf (param->plotpath, "%s/%s", param->directory, param->plotfile);

    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        fprintf (fp_debug, "plotpath= [%s]\n", param->plotpath);
        fflush (fp_debug);
    }         

    fp = (FILE *)NULL;
    if ((fp = fopen (param->plotpath, "w+")) == (FILE *)NULL) {
   
        param->errmsg[0] = '\0';
        sprintf (param->errmsg, "Failed to open tblpath %s\n", 
            param->plotpath);
        
        sprintf (param->retstr, "[struct stat=error, msg=%s]\n", 
            param->errmsg); 
        return (-1);
    }
    
/*
    Write header
*/
    strcpy (colname, "planenum");
    fprintf (fp, "|%-16s|", colname); 

    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        fprintf (fp_debug, "plotxaxis= [%s] plotyaxis= [%s]\n", 
            param->plotxaxis, param->plotyaxis);
        fflush (fp_debug);
    }         


    if ((int)strlen(param->plotxaxis) > 0) {
        sprintf (colname, "%s", param->plotxaxis);
    }
    else {
        strcpy (colname, "wave");
    } 
    fprintf (fp, "%-16s|", colname);
    
    if ((int)strlen(param->plotyaxis) > 0) {
        sprintf (colname, "%s", param->plotyaxis);
    }
    else {
        strcpy (colname, "flux");
    } 
    fprintf (fp, "%-16s|", colname);
    fprintf (fp, "\n"); 
    fflush (fp);

    strcpy (datatype, "int");
    fprintf (fp, "|%-16s|", datatype); 
    strcpy (datatype, "double");
    fprintf (fp, "%-16s|", datatype);
    strcpy (datatype, "double");
    fprintf (fp, "%-16s|", datatype);
    fprintf (fp, "\n"); 
    fflush (fp);

    strcpy (unit, "");
    fprintf (fp, "|%-16s|", unit); 
    strcpy (unit, hdr.cunit[2]);
    fprintf (fp, "%-16s|", unit);
    strcpy (unit, "dn");
    fprintf (fp, "%-16s|", unit);
    fprintf (fp, "\n"); 
    fflush (fp);

    strcpy (null, "null");
    fprintf (fp, "|%-16s|", null); 
    fprintf (fp, "%-16s|", null);
    fprintf (fp, "%-16s|", null);
    fprintf (fp, "\n"); 
    fflush (fp);

/*
    Write data 
*/
    for (i=0; i<hdr.nplane; i++) {

        sprintf (str, "%d", i);
        fprintf (fp, " %-16s ", str); 
    
        sprintf (str, "%16.2f", xarr[i]);
        fprintf (fp, "%-16s ", str); 
    
        sprintf (str, "%16.4f", yarr[i]);
        fprintf (fp, "%-16s ", str); 
    
        fprintf (fp, "\n"); 
        fflush (fp);
    }
        
    fclose (fp);        


/*
    Plot jsonfile
*/
    sprintf (param->plotjsonfile, "%s_plot.json", param->imageFile);
        
    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
        fprintf (fp_debug, "call checkFileExist (plotjsonfile)\n");
        fflush (fp_debug);  
    }

    strcpy (param->plothistvalue, "uniform step"); 
    strcpy (param->plotcolor, "#008800"); 
    strcpy (param->plotlinecolor, "#008800"); 
    strcpy (param->plotbgcolor, "white"); 
    strcpy (param->plotsymbol, "ball"); 
    strcpy (param->plotlinestyle, "solid"); 
    strcpy (param->plotxaxis, "wave"); 
    strcpy (param->plotxlabel, "Wavelength (nm)"); 
    strcpy (param->plotyaxis, "flux"); 
    strcpy (param->plotylabel, "Flux (dn)"); 
    strcpy (param->plottitle, "");
    strcpy (param->plotxlabeloffset, "false");
    strcpy (param->plotylabeloffset, "false");
    
    param->plothiststyle = 1;


    fileExist = checkFileExist (param->plotjsonfile, rootname, suffix,
        param->directory, param->plotjsonpath);

    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
        fprintf (fp_debug, "returned checkFileExist: fileExist= [%d]\n", 
            fileExist);
        fprintf (fp_debug, "plotjsonfile= [%s]\n", param->plotjsonfile);
        fprintf (fp_debug, "plotjsonpath= [%s]\n", param->plotjsonpath);
        fflush (fp_debug);  
        
        fprintf (fp_debug, "plotwidth= [%d]\n", param->plotwidth);
        fprintf (fp_debug, "plotheight= [%d]\n", param->plotheight);
        fprintf (fp_debug, "plotbgcolor= [%s]\n", param->plotbgcolor);
        
        fprintf (fp_debug, "plothiststyle= [%d]\n", param->plothiststyle);
        fprintf (fp_debug, "plothistvalue= [%s]\n", param->plothistvalue);

        fprintf (fp_debug, "plotcolor= [%s]\n", param->plotcolor);
        fprintf (fp_debug, "plotlinecolor= [%s]\n", param->plotlinecolor);
        fprintf (fp_debug, "plotlinestyle= [%s]\n", param->plotlinestyle);
        

        fflush (fp_debug);  
    }
        

/*
    if (!fileExist) {
*/

/*
    Write plot jsonfile: re-write every time because the parameters 
    (width and height might have changed)
*/
        sprintf (param->plotjsonpath, "%s/%s", 
            param->directory, param->plotjsonfile);
    
    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
        fprintf (fp_debug, "plotjsonpaht= [%s]\n", param->plotjsonpath); 
        fflush (fp_debug);  
    }

        fp = (FILE *)NULL;
        if ((fp = fopen (param->plotjsonpath, "w+")) == (FILE *)NULL) {
   
            param->errmsg[0] = '\0';
            sprintf (param->errmsg, "Failed to open tblpath %s\n", 
                param->plotjsonpath);
        
            sprintf (param->retstr, "[struct stat=error, msg=%s]\n", 
                param->errmsg); 
            return (-1);
        }
    
    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
        fprintf (fp_debug, "start writint plotjsonfile: [%s]\n",
            param->plotjsonpath);
        fflush (fp_debug);  
    }

/* 
    Create a default jsonfile; in this case, the following input parameters
    have to exist.
*/

         fprintf(fp, "{\n");
         
         fprintf(fp, "   \"jpeg\" :\n");
         fprintf(fp, "   {\n");
/*
         fprintf(fp, "      \"width\"  : \"%dpx\",\n", param->plotwidth);
         fprintf(fp, "      \"height\" : \"%dpx\",\n", param->plotheight);
*/
         fprintf(fp, "      \"width\"  : %d,\n", param->plotwidth);
         fprintf(fp, "      \"height\" : %d,\n", param->plotheight);


         fprintf(fp, "      \"background\" : \"%s\"\n", 
             param->plotbgcolor);
         fprintf(fp, "   },\n");
         fprintf(fp, "\n");

         if (param->plothiststyle) {
             fprintf(fp, "   \"histogram\" : \"%s\",\n", param->plothistvalue);
             fprintf(fp, "\n");
         }

         fprintf(fp, "   \"axes\" :\n");
         fprintf(fp, "   {\n");
         fprintf(fp, "      \"colors\" :\n");
         fprintf(fp, "      {\n");
         fprintf(fp, "         \"axes\"   : \"black\",\n");
         fprintf(fp, "         \"labels\" : \"black\"\n");
         fprintf(fp, "      },\n");

         if(strlen(param->plottitle) > 0)
         {
            fprintf(fp, "\n");
            fprintf(fp, "      \"title\" : \"%s\",\n", param->plottitle);
         }

         fprintf(fp, "\n");
         fprintf(fp, "      \"xaxis\" :\n");
         fprintf(fp, "      {\n");
         
         if ((int)strlen(param->plotxlabel) > 0) {
             fprintf(fp, "         \"label\"       : \"%s\",\n", 
                 param->plotxlabel);
         }
         else {
             fprintf(fp, "         \"label\"       : \"%s\",\n", 
                 param->plotxaxis);
         }

         if ((int)strlen(param->plotxlabeloffset) > 0) {
             fprintf(fp, "         \"offsetlabel\"       : \"%s\",\n", 
                 param->plotxlabeloffset);
         }
         else {
             fprintf(fp, "         \"offsetlabel\" : \"false\",\n");
         } 
         
         fprintf(fp, "         \"autoscale\"   : true,\n");
         fprintf(fp, "         \"scaling\"     : \"linear\"\n");
         fprintf(fp, "      },\n");
         fprintf(fp, "\n");
         fprintf(fp, "      \"yaxis\" :\n");
         fprintf(fp, "      {\n");
         
         if ((int)strlen(param->plotylabel) > 0) {
             fprintf(fp, "         \"label\"       : \"%s\",\n", 
                 param->plotylabel);
         }
         else {
             fprintf(fp, "         \"label\"       : \"%s\",\n", 
                 param->plotyaxis);
         }
         
         if ((int)strlen(param->plotylabeloffset) > 0) {
             fprintf(fp, "         \"offsetlabel\"       : \"%s\",\n", 
                 param->plotxlabeloffset);
         }
         else {
             fprintf(fp, "         \"offsetlabel\" : \"false\",\n");
         } 
         
         fprintf(fp, "         \"autoscale\"   : true,\n");
         fprintf(fp, "         \"scaling\"     : \"linear\"\n");
         fprintf(fp, "      }\n");
         fprintf(fp, "   },\n");
         fprintf(fp, "\n");
         fprintf(fp, "   \"pointset\" : \n");
         fprintf(fp, "   [\n");
         fprintf(fp, "      {\n");
         fprintf(fp, "         \"source\" :\n");
         fprintf(fp, "         {\n");
         fprintf(fp, "            \"table\" : \"%s\",\n", param->plotpath);
         fprintf(fp, "\n");


         fprintf(fp, "            \"xcolumn\" : \"%s\",\n", param->plotxaxis);
         fprintf(fp, "            \"ycolumn\" : \"%s\"\n", param->plotyaxis);
         fprintf(fp, "         },\n");
         fprintf(fp, "\n");
         fprintf(fp, "         \"points\" :\n");
         fprintf(fp, "         {\n");
         fprintf(fp, "            \"symbol\" : \"%s\",\n", param->plotsymbol);
         fprintf(fp, "            \"size\"   : 0.5,\n");
         fprintf(fp, "            \"color\"  : \"%s\"\n", param->plotcolor);
         fprintf(fp, "         },\n");
         fprintf(fp, "\n");
         fprintf(fp, "         \"lines\" :\n");
         fprintf(fp, "         {\n");
         fprintf(fp, "            \"style\" : \"%s\",\n", param->plotlinestyle);
         fprintf(fp, "            \"width\"   : 1.0,\n");
         fprintf(fp, "            \"color\"  : \"%s\"\n", param->plotlinecolor);
         fprintf(fp, "         }\n");
         fprintf(fp, "      }\n");
         fprintf(fp, "   ]\n");
         fprintf(fp, "}\n");

         fflush(fp);
         fclose(fp);
    
    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
        
        fprintf (fp_debug, "done writing plotjsonpath= [%s]\n", 
            param->plotjsonpath); 
        fflush (fp_debug);  
    }

/*
    }
*/
    return (0);
}
Beispiel #8
0
void Pkginst::generateDependencies()
{
	vector< pair<string,time_t> > dependenciesWeMustAdd,depencenciestoSort;
	pair<string,time_t> PackageTime;
	PackageTime.first=m_packageName;
	PackageTime.second=0;
	dependenciesWeMustAdd.push_back(PackageTime);	// Insert the final package first
	dependenciesWeMustAdd.push_back(PackageTime);
	std::vector< pair<string,time_t> >::iterator vit;
	std::set< pair<string,time_t> >::iterator sit;
	while ( ! dependenciesWeMustAdd.empty() ) { // Main WHILE
#ifndef NDEBUG
		for (auto i : dependenciesWeMustAdd) cerr << i.first << " " << i.second << endl;
#endif
		vit = dependenciesWeMustAdd.begin();
		m_packageName = vit->first;
		PackageTime = *vit;
		dependenciesWeMustAdd.erase(vit);   // Erase the current treated package name
		set< pair<string,time_t> > directDependencies;
		if ( m_listOfDepotPackages.find(m_packageName) != m_listOfDepotPackages.end() ) {
#ifndef NDEBUG
			cerr << m_packageName << " found in m_listOfDepotPackages" << endl;
#endif
			directDependencies = m_listOfDepotPackages[m_packageName].dependencies;
#ifndef NDEBUG
			for (auto i : directDependencies ) cerr << i.first << i.second << " ";
#endif
		} else {
#ifndef NDEBUG
			cerr << m_packageName << " not found in m_listOfDepotPackages" << endl;
#endif
			if ( checkBinaryExist(m_packageName)) { // directs deps if not yet availables
#ifndef NDEBUG
				cerr << m_packageName << " binary found " << endl;
#endif
				m_packageFileName = getPackageFileName(m_packageName);
#ifndef NDEBUG
				cerr << m_packageFileName << " archive found " << endl;
#endif
			}
			if ( ! checkFileExist(m_packageFileName)) // Binary Archive not yet downloaded
				downloadPackageFileName(m_packageName); // Get it
#ifndef NDEBUG
			cerr << "getPackageDependencies(" << m_packageFileName << ")" << endl;
#endif
			directDependencies = getPackageDependencies(m_packageFileName);
#ifndef NDEBUG
			for (auto i : directDependencies ) cerr << i.first << " ";
#endif
		}
		if ( ! checkPackageNameBuildDateSame(PackageTime)) // If not yet install or not up to dated
		{
#ifndef NDEBUG
			cerr << "checkPackageNameBuildDateSame no:" <<PackageTime.first << PackageTime.second << endl;
#endif
			depencenciestoSort.push_back(PackageTime); // Add it
		}
#ifndef NDEBUG
			 else
		{
			cerr << "checkPackageNameBuildDateSame yes: " << PackageTime.first << PackageTime.second << endl;
		}
#endif
		for ( sit = directDependencies.begin(); sit != directDependencies.end();sit++) {
			if ( sit->first == PackageTime.first )
				continue;
			for ( vit = dependenciesWeMustAdd.begin(); vit != dependenciesWeMustAdd.end();++vit) {
				if ( *sit == *vit) {
					dependenciesWeMustAdd.erase(vit);
					break;
				}
			}
		}
		for ( sit = directDependencies.begin(); sit != directDependencies.end();sit++) {
			if ( PackageTime.first != sit->first ) {
				if ( ! checkPackageNameBuildDateSame(*sit))
					dependenciesWeMustAdd.push_back(*sit);
			}
		}
	}
	bool found = false ;
	for ( std::vector<pair <string,time_t> >::reverse_iterator vrit = depencenciestoSort.rbegin(); vrit != depencenciestoSort.rend();++vrit) {
		found = false ;
		for (vector<string>::const_iterator i = m_dependenciesList.begin();i != m_dependenciesList.end();i++) {
			if (*i == vrit->first) {
				found = true ;
				break;
			}
		}
		if (!found) {
#ifndef NDEBUG
			cerr << "m_dependenciesList.push_back " << vrit->first << endl;
#endif
			m_dependenciesList.push_back(vrit->first);
		}
#ifndef NDEBUG
		else cerr << "no deps founds" << endl;
#endif
	}
}
Beispiel #9
0
	bool checkDirExist(const string& dirPath)
	{
		return checkFileExist(dirPath);
	}
Beispiel #10
0
int main(int argc, char **argv){
 	int sock_fd;
 	create_and_conn(&sock_fd, "127.0.0.1", 9999);
 	while(1){
	 	message msg;
	 	printf("input the cmd(0:add  1:get  2:send [3:add 4:get 5:wc-tag])\n");
	 	int input;
	 	scanf("%d", &input);
	 	getchar();//去除stdin中的'\n'
	 	switch(input){
	 		case INIT: {
	 			//create a tag in current working folder
	 			//to indicate this is the WC
	 			char mode[] = "0444";
	 			int ret;
	 			int m = strtol(mode, 0, 8);
	 			ret = creat(WORKING_FOLDER_TAG, m);
				if(ret == -1)
				{
					perror("creat file");
				}
				break;
	 		}
	 		case TEST_ADD: {
	 			int ret;
				printf("file need to transfer:");
				char path [256];
				char realpath[256];
				scanf("%s",path);

				if(!checkFileExist(path)){
					printf("Error:%s doesn't exist!\n", path);
					goto EXIT;
				}
				/*get real path, that is, have prefix*/
				ret = getRealPath(path, realpath);
				if(ret == -1) {
					goto EXIT;
				}
				printf("real path:%s\n", realpath);


				//mes send after all is ok
				msg.cmd = TEST_ADD;
	 			ret = send(sock_fd, &msg, sizeof(msg), 0);
	 			if(ret == -1){
			 		perror("send cmd msg\n");
				}

				printf("-------------start send----------\n");
				Send(realpath, sock_fd);
				printf("-------------end send ----------\n");
				break;
				
	 		}

	 		case TEST_GET: {
	 			int ret;
				printf("file need to Get:");
				char path [256];
				char realpath[256];
				scanf("%s",path);

				/*get real path, that is, have prefix*/
				ret = getRealPath(path, realpath);
				if(ret == -1) {
					goto EXIT;//return -1;
				}
				printf("real path:%s\n", realpath);

				getchar();
				char version[32];
				scanf("%s", version);
				getchar();
				int byLatestVersion, recursive;
				scanf("%d %d", &byLatestVersion, &recursive);

				//msg send after all is ok
				msg.cmd = TEST_GET;
	 			ret = send(sock_fd, &msg, sizeof(msg), 0);
	 			if(ret == -1){
			 		perror("send cmd msg\n");
				}
				printf("-------------start Get----------\n");
				clientGetFile(sock_fd, realpath, version, recursive, byLatestVersion);
				printf("-------------end Get ----------\n");
				break;
	 		}

	 		case ADD_FILES:{
	 			msg.cmd = ADD_FILES;
	 			int ret = send(sock_fd, &msg, sizeof(msg), 0);
	 			if(ret == -1){
			 		perror("send cmd msg\n");
				}
	 			break;
	 		}
	 		case GET_FILES:{
	 			msg.cmd = GET_FILES;
			 	int ret = send(sock_fd, &msg, sizeof(msg), 0);
			 	if(ret == -1){
			 		perror("send msg\n");
				}
				//getFile(sock_fd);
	 			break;
	 		}
	 		case SEND_FILES:{
	 			msg.cmd = SEND_FILES;
			 	int ret = send(sock_fd, &msg, sizeof(msg), 0);
			 	if(ret == -1){
			 		perror("send msg\n");
				}
				//getFile(sock_fd);
	 			break;
	 		}
	 	}
	 	break;

	 	//getFile(sock_fd);
 	}
 	
EXIT:
 	close(sock_fd);
 	return 0;

}
Beispiel #11
0
void Pkginfo::run()
{
	if (m_archiveinfo) {
		pair<string, pkginfo_t> packageArchive = openArchivePackage(m_packageArchiveName) ;
		cout	<< packageArchive.first << " Description    : " << packageArchive.second.description << endl
			<< packageArchive.first << " URL            : " << packageArchive.second.url << endl
			<< packageArchive.first << " Maintainer(s)  : " << packageArchive.second.maintainer << endl
			<< packageArchive.first << " Packager(s)    : " << packageArchive.second.packager << endl
			<< packageArchive.first << " Version        : " << packageArchive.second.version << endl
			<< packageArchive.first << " Release        : " << packageArchive.second.release << endl
			<< packageArchive.first << " Architecture   : " << packageArchive.second.arch  << endl
			<< packageArchive.first << " Build date     : " << packageArchive.second.build << endl;
		if (packageArchive.second.dependencies.size() > 0 ) {
			cout << packageArchive.first << " Dependencies   : ";
			for ( auto i : packageArchive.second.dependencies) cout << i.first << i.second << " ";
			cout << endl;
		}
	}
	// Make footprint
	if (m_footprint_mode) {
		getFootprintPackage(m_arg);
	} else {
		// Modes that require the database to be opened
		Db_lock lock(m_root, false);
		getListOfPackageNames(m_root);
		if (m_installed_mode) {
			// List installed packages
			buildDatabaseWithNameVersion();
			for (auto i : m_listOfInstPackages) {
				cout << i.first << " " << i.second.version << "-" << i.second.release << endl;
			}
		} else if (m_list_mode) {
			// List package or file contents
			buildDatabaseWithDetailsInfos(false);
			if (checkPackageNameExist(m_arg)) {
				copy(m_listOfInstPackages[m_arg].files.begin(), m_listOfInstPackages[m_arg].files.end(), ostream_iterator<string>(cout, "\n"));
			} else if (checkFileExist(m_arg)) {
				pair<string, pkginfo_t> package = openArchivePackage(m_arg);
				copy(package.second.files.begin(), package.second.files.end(), ostream_iterator<string>(cout, "\n"));
			} else {
				m_actualError = NOT_INSTALL_PACKAGE_NEITHER_PACKAGE_FILE;
				treatErrors(m_arg);
			}
		} else if (m_runtimedependencies_mode) {
			/* 	Get runtimedependencies of the file found in the directory path
				get the list of installed package silently */
			buildDatabaseWithDetailsInfos(true);
			regex_t r;
			int Result;
			regcomp(&r, ".", REG_EXTENDED | REG_NOSUB);
			set<string>filenameList;
			Result = findRecursiveFile (filenameList, const_cast<char*>(m_arg.c_str()), &r, WS_DEFAULT);
			// get the list of library for all the possible files 
			set<string> librariesList;
			for (auto i : filenameList) Result = getRuntimeLibrariesList(librariesList,i);
			// get the own package  for all the elf files dependencies libraries
#ifndef NDEBUG
			for (auto i : librariesList) cerr << i <<endl;
#endif
			if ( (librariesList.size() > 0 ) && (Result > -1) ) {
				set<string> runtimeList;
				for (set<string>::const_iterator i = librariesList.begin();i != librariesList.end();++i) {
					for (packages_t::const_iterator j = m_listOfInstPackages.begin(); j != m_listOfInstPackages.end();++j) {
						bool found = false;
						for (set<string>::const_iterator k = j->second.files.begin(); k != j->second.files.end(); ++k) {
							if ( k->find('/' + *i) != string::npos) {
								string dependency = j->first + static_cast<ostringstream*>( &(ostringstream() <<  j->second.build ))->str();
								runtimeList.insert(dependency);
								break;
								found = true;
							}
						}
						if ( found == true) {
							found = false;
							break;
						}
					}
				}
				if (runtimeList.size()>0) {
#ifndef NDEBUG
					cerr << "Number of libraries founds: " << runtimeList.size() << endl;
#endif
					unsigned int s = 1;
					for ( auto i : runtimeList ) {
						cout << i << endl;
						s++;
					}
					cout << endl;
				}
			}	
		} else if (m_libraries_mode + m_runtime_mode > 0) {
			// get the list of installed package silently
			buildDatabaseWithDetailsInfos(true);
			set<string> librariesList;
			int Result = -1;
			if (checkPackageNameExist(m_arg)) {
				for (set<string>::const_iterator i = m_listOfInstPackages[m_arg].files.begin();
					i != m_listOfInstPackages[m_arg].files.end();
					++i){
					string filename('/' + *i);
					Result = getRuntimeLibrariesList(librariesList,filename);
				}
				if ( (librariesList.size() > 0 ) && (Result > -1) ) {
					if (m_runtime_mode) {
						set<string> runtimeList;
						for (set<string>::const_iterator i = librariesList.begin();
						i != librariesList.end();
						++i) {
							for (packages_t::const_iterator j = m_listOfInstPackages.begin();
								j != m_listOfInstPackages.end();
								++j){
								bool found = false;
								for (set<string>::const_iterator k = j->second.files.begin();
									k != j->second.files.end();
									++k) {
									if ( k->find('/' + *i) != string::npos) {
										runtimeList.insert(j->first);
										break;
										found = true;
									}
								}
								if (found == true) {
									found = false;
									break;
								}
							}
						}
						if (runtimeList.size()>0) {
							unsigned int s = 1;
							for (set<string>::const_iterator i = runtimeList.begin();
								i!=runtimeList.end();
								++i){
								cout << *i;
								s++;
								if (s <= runtimeList.size())
									cout << ",";
							}
							cout << endl;
						}
					} else {
						for (set<string>::const_iterator i = librariesList.begin();i != librariesList.end();++i)
							cout << *i << endl;
					}
				}
			}	
		} else if (m_epoc) {
			// get the building time of the package return 0 if not found
			buildDatabaseWithDetailsInfos(true);
			if (checkPackageNameExist(m_arg)) {
				cout << m_listOfInstPackages[m_arg].build << endl;
			} else {
				cout << "0" << endl;
			}
		} else if (m_details_mode) {
			// get all the details of a package
			buildDatabaseWithDetailsInfos(false);
			if (checkPackageNameExist(m_arg)) {
				char * c_time_s = ctime(&m_listOfInstPackages[m_arg].build);
				cout << "Name           : " << m_arg << endl
					<< "Description    : " << m_listOfInstPackages[m_arg].description << endl
					<< "URL            : " << m_listOfInstPackages[m_arg].url << endl
					<< "Maintainer(s)  : " << m_listOfInstPackages[m_arg].maintainer << endl
					<< "Packager(s)    : " << m_listOfInstPackages[m_arg].packager << endl
					<< "Version        : " << m_listOfInstPackages[m_arg].version << endl
					<< "Release        : " << m_listOfInstPackages[m_arg].release << endl
					<< "Build date     : " << c_time_s
					<< "Size           : " << m_listOfInstPackages[m_arg].size << endl
					<< "Number of Files: " << m_listOfInstPackages[m_arg].files.size()<< endl
					<< "Arch           : " << m_listOfInstPackages[m_arg].arch << endl;
				if ( m_listOfInstPackages[m_arg].dependencies.size() > 0 ) {
					cout << "Dependencies   : ";
					for ( auto i : m_listOfInstPackages[m_arg].dependencies) cout << i.first << " ";
					cout << endl;
				}
			}
		} else if (m_owner_mode) {
			// List owner(s) of file or directory
			buildDatabaseWithDetailsInfos(false);
			regex_t preg;
			if (regcomp(&preg, m_arg.c_str(), REG_EXTENDED | REG_NOSUB)) {
				m_actualError = CANNOT_COMPILE_REGULAR_EXPRESSION;
				treatErrors(m_arg);
			}
			vector<pair<string, string> > result;
			result.push_back(pair<string, string>("Package", "File"));
			unsigned int width = result.begin()->first.length(); // Width of "Package"
#ifndef NDEBUG
			cerr << m_arg << endl;
#endif
			for (auto i : m_listOfInstPackages) {
				for (auto j : i.second.files) {
					const string file('/' + j);
					if (!regexec(&preg, file.c_str(), 0, 0, 0)) {
						result.push_back(pair<string, string>(i.first, j));
						if (i.first.length() > width) {
							width = i.first.length();
						}
					}
				}
			}

			regfree(&preg);
			if (result.size() > 1) {
				for (auto i : result ) {
					cout << left << setw(width + 2) << i.first << i.second << endl;
				}
			} else {
				cout << m_utilName << ": no owner(s) found" << endl;
			}
		}
	}
}
Beispiel #12
0
int makeStartupHtml (struct ViewerApp *param)
{
    FILE           *fp;

    char           helphtmlpath[1024];
    char           imtypehtmlpath[1024];
    char           cursorhtmlpath[1024];
    
    
    char           viewhtmlpath[1024];
    char           viewtemplatepath[1024];
    
    char           planeoptionpath[1024];
    char           **arr;

    char           imfile[1024];
    char           fpath[1024];
    char           str[1024];
    char           *cptr;

    char           imcontroltemplatepath[1024];
    
    char           graylistoptionPath[1024];
    
    char           redlistoptionPath[1024];
    char           grnlistoptionPath[1024];
    char           bluelistoptionPath[1024];

    char           srctbloptionPath[1024];
    char           iminfooptionPath[1024];

    char           rootname[128];
    
    char           suffix[20];
    char           varstr[32768];
    char           status[32];

    int            l;
    int            istatus;
    int            selectedIndx;
    int            fileExist;
    int            viewhtmlExist;
    int            helphtmlExist;
    int            imtypehtmlExist;
    int            cursorhtmlExist;
   
   
    double         cdelt3;
    double         crval3;

    int            debugfile = 1;

    
    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	fprintf (fp_debug, "From makeStartupHtml\n");
	fprintf (fp_debug, "isimcube= [%d]\n", param->isimcube);
	fprintf (fp_debug, "gridvis[0]= [%d]\n", param->gridvis[0]);

	fprintf (fp_debug, "redfile= [%s] grnfile= [%s] bluefile= [%s]\n",
	    param->redfile, param->grnfile, param->bluefile);

	fprintf (fp_debug, "viewhtml= [%s]\n", param->viewhtml);
	fprintf (fp_debug, "directory= [%s]\n", param->directory);
	fprintf (fp_debug, "Make viewhtml from template\n");
        fflush (fp_debug);
    }
     

/*
    Check if viewhtml is in workspace or datadir.
*/
    if ((int)strlen(param->helphtml) > 0) {

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "\nhelphtml specified: helphtml= [%s]\n",
	        param->helphtml);
            fflush (fp_debug);
        }

        helphtmlExist = checkFileExist (param->helphtml, rootname, suffix,
	    param->datadir, fpath);
    
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, 
	        "checkFileExist(helphtml): helphtmlExist= [%d]\n", 
		helphtmlExist);
	    fprintf (fp_debug, "fpath= [%s]\n", fpath);
            fflush (fp_debug);
        }

	if (helphtmlExist) {

            sprintf (helphtmlpath, "%s/%s", param->directory, param->helphtml);

            if (strcasecmp (fpath, helphtmlpath) != 0) {

                istatus = fileCopy (fpath, helphtmlpath, param->errmsg); 
            
	        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, 
		        "helphtml copied from datadir to directory");
                    fflush (fp_debug);
                }
	    }
	    else {
                if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, "helphtmlpath= [%s] already exists\n", 
		        imtypehtmlpath);
                    fflush (fp_debug);
                }
	    }
	
	}

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "helphtmlpath= [%s]\n", helphtmlpath);
            fflush (fp_debug);
        }
    }
    
    if ((int)strlen(param->imtypehtml) > 0) {

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "\nimtypehtml specified in inparam file\n");
            fflush (fp_debug);
        }
     
        imtypehtmlExist = checkFileExist (param->imtypehtml, rootname, suffix,
	    param->datadir, fpath);
    
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, 
	        "checkFileExist(imtypehtml): imtypehtmlExist= [%d]\n", 
		imtypehtmlExist);
	    fprintf (fp_debug, "fpath= [%s]\n", fpath);
            fflush (fp_debug);
        }


	if (imtypehtmlExist) {
            
	    sprintf (imtypehtmlpath, "%s/%s", 
	        param->directory, param->imtypehtml);

            if (strcasecmp (fpath, imtypehtmlpath) != 0) {

                istatus = fileCopy (fpath, imtypehtmlpath, param->errmsg); 
            
	        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, 
		        "imtypehtml copied from datadir to directory");
                    fflush (fp_debug);
                }
	    }
	    else {
                if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, "imtypehtmlpath= [%s] already exists\n", 
		        imtypehtmlpath);
                    fflush (fp_debug);
                }
	    }
	
	}

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "imtypehtmlpath= [%s]\n", imtypehtmlpath);
            fflush (fp_debug);
        }
    }
    
    if ((int)strlen(param->cursorhtml) > 0) {

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "\ncursorhtml specified in inparam file\n");
            fflush (fp_debug);
        }
     
        cursorhtmlExist = checkFileExist (param->cursorhtml, rootname, suffix,
	    param->datadir, fpath);
    
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, 
	        "checkFileExist(cursorhtml): cursorhtmlExist= [%d]\n", 
		cursorhtmlExist);
	    fprintf (fp_debug, "fpath= [%s]\n", fpath);
            fflush (fp_debug);
        }

	if (cursorhtmlExist) {
	    
	    sprintf (cursorhtmlpath, "%s/%s", 
	        param->directory, param->cursorhtml);

            if (strcasecmp (fpath, cursorhtmlpath) != 0) {

                istatus = fileCopy (fpath, cursorhtmlpath, param->errmsg); 
            
	        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, 
		        "cursorhtml copied from datadir to directory");
                    fflush (fp_debug);
                }
	    }
	    else {
                if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, "cursorhtmlpath= [%s] already exists\n", 
		        cursorhtmlpath);
                    fflush (fp_debug);
                }
	    }
	
	}

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "cursorhtmlpath= [%s]\n", cursorhtmlpath);
            fflush (fp_debug);
        }
    }
    
    if ((int)strlen(param->viewhtml) > 0) {

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "\nviewhtml specified in inparam file\n");
            fflush (fp_debug);
        }
     

        viewhtmlExist = checkFileExist (param->viewhtml, rootname, suffix,
	    param->datadir, fpath);
    
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, 
	        "checkFileExist(viewhtml): viewhtmlExist= [%d]\n", 
		viewhtmlExist);
	    fprintf (fp_debug, "fpath= [%s]\n", fpath);
            fflush (fp_debug);
        }

	if (viewhtmlExist) {
	    sprintf (viewhtmlpath, "%s/%s", 
	        param->directory, param->viewhtml);

            istatus = fileCopy (fpath, viewhtmlpath, param->errmsg); 
            
	    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "viewhtml copied from datadir to directory");
                fflush (fp_debug);
            }
	}

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "viewhtmlpath= [%s]\n", viewhtmlpath);
            fflush (fp_debug);
        }

    }
    else {
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "Make viewhtml from template\n");
            fflush (fp_debug);
        }
     
        strcpy (str, param->viewtemplate);

        cptr = (char *)NULL;
        cptr = strrchr (str, '.');
	if (cptr != (char *)NULL) {
            *cptr = '\0';
	}

	sprintf (param->viewhtml, "%s.html", str);
	sprintf (param->viewhtmlpath, "%s/%s", param->directory, 
	    param->viewhtml);

	fileExist = checkFileExist (param->viewtemplate, rootname, suffix,
	    param->datadir, viewtemplatepath);
            
	if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, 
		"viewtemplate fileExist= [%d] in datadir= [%s])\n", 
	        fileExist, param->datadir);
	    fprintf (fp_debug, "viewtemplatepath= [%s]\n", 
		viewtemplatepath);
            fflush (fp_debug);
        }

        if (!fileExist) {
	    strcpy (param->errmsg, 
	      "Failed to find view template in either datadir\n");
            return (-1);
        }
	   
/*
    Read FitsHdr to extract special keywords: objname, filter, and pixscale
    for display.
    
    If it is a fits cube, find out nfitsplane too.
    Note: Only deal with grayfile at present.
*/
	if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "nfitsplane= [%d]\n", param->nfitsplane);
            fflush (fp_debug);
        }


        if (param->isimcube) {

            if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "here1: isimcube\n");
                fflush (fp_debug);
            }

            if (param->nfitsplane > 0) {
            
                sprintf (planeoptionpath, "%s/planeoption.txt", 
		    param->directory);

		arr = (char **)malloc (param->nfitsplane*sizeof(char *));
		for (l=0; l<param->nfitsplane; l++) {
		    
		    arr[l] = (char *)malloc (10*sizeof(char));
                    sprintf (arr[l], "%d", (l+1));
		}
                
		selectedIndx = 0;

                if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, "call writeOptionList\n");
                    fflush (fp_debug);
                }
	   
                istatus = writeOptionList (planeoptionpath,
		    param->nfitsplane, arr, selectedIndx, param->errmsg);
                
		if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, "returned writeOptionList\n");
                    fflush (fp_debug);
                }
	   
	    }
	}


/*
    If nim_gray > 1, make imlistoption interface for replace image
*/
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "nim_gray= [%d]\n", param->nim_gray);
            fflush (fp_debug);
        }

        if (param->nim_gray > 1) {

            sprintf (graylistoptionPath, "%s/graylistoption.txt", 
	        param->directory); 
	    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "graylistoptionPath= [%s]\n", 
	            graylistoptionPath);
                fflush (fp_debug);
            }

            fp = (FILE *)NULL;
	    param->errmsg[0] = '\0';
	    if ((fp = fopen(graylistoptionPath, "w+")) == (FILE *)NULL) {
                sprintf (param->errmsg, 
		    "Failed to create file [%s] in workspace", 
		    graylistoptionPath);
	        return (-1);
	    }

	    
	    fprintf (fp, "<option vallue=\"\" selected=\"selected\">\n");
	    fprintf (fp, "</option>\n");

            for (l=0; l<param->nim_gray; l++) {
	
	        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, "l= [%d] imfile= [%s]\n", 
		        l, param->imfile[l]);
                    fflush (fp_debug);
                }

	        fprintf (fp, "<option vallue=\"%s\">%s</option>\n", 
		    param->imfile[l], param->imfile[l]);
	    }

	    fclose (fp);
        }
        else {
            redlistoptionPath[0] = '\0';
            grnlistoptionPath[0] = '\0';
            bluelistoptionPath[0] = '\0';
        }


/*
    If nsrctbl > 1, make srctbloption interface for adding srctbl
*/
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "nsrctbl= [%d]\n", param->nsrctbl);
            fflush (fp_debug);
        }

        if (param->nsrctbl > 0) {

            if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "\nwrite srctblOption file for html page\n");
                fflush (fp_debug);
            }

            sprintf (srctbloptionPath, "%s/srctbloption.txt", param->directory); 
	    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "srctbloptionPath= [%s]\n", 
		    srctbloptionPath);
                fflush (fp_debug);
            }

            fp = (FILE *)NULL;
	    param->errmsg[0] = '\0';
	    if ((fp = fopen(srctbloptionPath, "w+")) == (FILE *)NULL) {
                sprintf (param->errmsg, 
		    "Failed to create file [%s] in workspace",
		    srctbloptionPath);
	        return (-1);
	    }
    
            if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "here2\n");
                fflush (fp_debug);
            }


	    fprintf (fp, "<option vallue=\"\" selected=\"selected\">\n");
	    fprintf (fp, "</option>\n");
        
	    for (l=0; l<param->nsrctbl; l++) {
	
	        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, "l= [%d] srctblfile= [%s]\n", 
		        l, param->srctblfile[l]);
                    fflush (fp_debug);
                }

	        fprintf (fp, "<option vallue=\"%s\">%s</option>\n", 
		    param->srctblfile[l], param->srctblfile[l]);
	    }

	    fclose (fp);
        }


/*
    If niminfo >= 1, make iminfooption interface for adding iminfo
*/
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "niminfo= [%d]\n", param->niminfo);
            fflush (fp_debug);
        }

        if (param->niminfo > 0) {

            if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "here3\n");
                fflush (fp_debug);
            }

            sprintf (iminfooptionPath, "%s/iminfooption.txt", param->directory); 
	    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "iminfooptionPath= [%s]\n", 
		    iminfooptionPath);
                fflush (fp_debug);
            }

            fp = (FILE *)NULL;
	    param->errmsg[0] = '\0';
	    if ((fp = fopen(iminfooptionPath, "w+")) == (FILE *)NULL) {
                sprintf (param->errmsg, 
		    "Failed to create file [%s] in workspace",
	            iminfooptionPath);
	        return (-1);
	    }

	    fprintf (fp, "<option vallue=\"\" selected=\"selected\">\n");
	    fprintf (fp, "</option>\n");
        
	    for (l=0; l<param->niminfo; l++) {
	
	        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	            fprintf (fp_debug, "l= [%d] iminfofile= [%s]\n", 
		        l, param->iminfofile[l]);
                    fflush (fp_debug);
                }

	        fprintf (fp, "<option vallue=\"%s\">%s</option>\n", 
		    param->iminfofile[l], param->iminfofile[l]);
	    }

	    fclose (fp);
        }

/*
    Make viewer html from template -- always requires a template
*/
        
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "here4\n");
            fflush (fp_debug);
        }

        if (param->isimcube) {
	    strcpy (imfile, param->imcubepath);
	}
	else {
	    strcpy (imfile, param->grayfile);
	}
        
	if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "isimcube= [%d]\n", param->isimcube);
	    fprintf (fp_debug, "imfile= [%s]\n", imfile);
	    
	    fprintf (fp_debug, "cdelt3= [%lf]\n", param->cdelt3);
	    fprintf (fp_debug, "crval3= [%lf]\n", param->crval3);
            fflush (fp_debug);
        }
       
	varcmd (varstr, 32768,
            "htmlgen",
	                        "%s",              viewtemplatepath,
	                        "%s",              param->viewhtmlpath,
	    "winname",          "%s",              param->winname,
	    "workspace",        "%s",              param->workspace,
	    "httpurl",	        "%s",              param->baseurl,
	    "isimcube",		"%d",	           param->isimcube,
	    "nplane",           "%d",              param->nfitsplane,
	    "cdelt3",           "%lf",             param->cdelt3,
	    "crval3",           "%lf",             param->crval3,
	    "imfile",           "%s",              imfile,
	    "grayfile",         "%s",              param->grayfile,
	    "imcubepath",       "%s",              param->imcubepath,
	    "redfile",          "%s",              param->redfile,
	    "grnfile",          "%s",              param->grnfile,
	    "bluefile",         "%s",              param->bluefile,
	    "jsonfile",         "%s",              param->jsonfile,
	    "planeoption",      "%s",              planeoptionpath,
	    "title",	        "%s",              param->divname,
	    "imname",	        "%s",              param->imname,
	    "divname",	        "%s",              param->divname,
	    "viewdiv",	        "%sview",          param->divname,
	    "refdiv",	        "%sref",           param->divname,
	    "canvaswidth",      "%d",              param->canvaswidth,
	    "canvasheight",     "%d",              param->canvasheight,
	    "refwidth",         "%d",              param->refwidth,
	    "refheight",        "%d",              param->refheight,
	    "viewcgiurl",       "%s",              param->viewcgiurl,
	    "tblcgiurl",        "%s",              param->tblcgiurl,
	    "tblwidth",         "%d",              param->tblwidth,
	    "tblheight",        "%d",              param->tblheight,
	    "graylistoption",   "%s",              graylistoptionPath,
	    "srctbloption",     "%s",              srctbloptionPath,
	    "iminfooption",     "%s",              iminfooptionPath,
	    "objname",     	"%s",              param->objname,
	    "filter",     	"%s",              param->filter,
	    "pixscale",     	"%s",              param->pixscale,
	    "END_PARM");


        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr);
            fflush (fp_debug);
        }
   
/*
    Add imlist, srctbl and iminfo list elements
*/
        if (param->nim_gray > 0) {
            
	    for (l=0; l<param->nim_gray; l++) {
	        sprintf (str, " \"imfile%d\" \"%s\"", l, param->imfile[l]);
		strcat (varstr, str); 
            }
        
	    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr);
	        fflush (fp_debug);
	    }
	}
        
	if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "here5\n");
            fflush (fp_debug);
        }
   

        if (param->nim_color > 0) {
            
	    for (l=0; l<param->nim_color; l++) {
	        sprintf (str, " \"rimfile%d\" \"%s\"", l, param->rimfile[l]);
		strcat (varstr, str); 
	        sprintf (str, " \"gimfile%d\" \"%s\"", l, param->gimfile[l]);
		strcat (varstr, str); 
	        sprintf (str, " \"bimfile%d\" \"%s\"", l, param->bimfile[l]);
		strcat (varstr, str); 
            }
        
	    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
                fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr);
                fflush (fp_debug);
            }
	}
	
	if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "here6\n");
            fflush (fp_debug);
        }
   

        if (param->nsrctbl > 0) {
            
	    for (l=0; l<param->nsrctbl; l++) {
	        sprintf (str, " \"srctblfile%d\" \"%s\"", 
		    l, param->srctblfile[l]);
		strcat (varstr, str); 
            }
        
	    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr);
	        fflush (fp_debug);
	    }
	}
	
	if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "here7\n");
            fflush (fp_debug);
        }
   

        if (param->niminfo > 0) {
           
	    for (l=0; l<param->niminfo; l++) {
	        sprintf (str, " \"iminfofile%d\" \"%s\"", 
		    l, param->iminfofile[l]);
		strcat (varstr, str); 
            }
        
	    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	        fprintf (fp_debug, "varstr (viewhtml)= [%s]\n", varstr);
	        fflush (fp_debug);
	    }
	}
	    
	if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	    fprintf (fp_debug, "Run varstr (viewhtml)= [%s]\n", varstr);
	    fflush (fp_debug);
	}

        istatus = svc_run (varstr);
      
        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "returned svc_run: istatus= [%d]\n", istatus);
            fflush (fp_debug);
        }
    
        strcpy( status, svc_value( "stat" ));

        if ((debugfile) && (fp_debug != (FILE *)NULL)) {
            fprintf (fp_debug, "status= [%s]\n", status);
            fflush (fp_debug);
        }
    
        if (strcasecmp( status, "error") == 0) {
	    strcpy (param->errmsg, svc_value("msg"));
	    return (-1);
        }
    }



/*
    If input paramfile provides neither tbldisphtml nor tbldisptemplate,
    return error.
*/
    if ((debugfile) && (fp_debug != (FILE *)NULL)) {
	fprintf (fp_debug, "nsrctbl= [%d] niminfo= [%d]\n", 
	    param->nsrctbl, param->niminfo);
        fflush (fp_debug);
    }

    return (0);
}
Beispiel #13
0
bool MDLInstallation(void *buf, size_t sizeBuf, PROJECT_DATA *projectDB, uint chapitre, uint tome, bool subFolder, bool haveToPutTomeAsReadable)
{
    bool wentFine = true;
    char temp[600], basePath[500], *encodedPath = getPathForProject(*projectDB);
	
	if(encodedPath == NULL)
		return true;
	
    /*Récupération des valeurs envoyés*/
	
    if(tome != INVALID_VALUE)
    {
		if(subFolder)
		{
			if(chapitre % 10)
				snprintf(basePath, 500, PROJECT_ROOT"%s/"VOLUME_PREFIX"%u/"CHAPTER_PREFIX"%u.%u/", encodedPath, tome, chapitre / 10, chapitre % 10);
			else
				snprintf(basePath, 500, PROJECT_ROOT"%s/"VOLUME_PREFIX"%u/"CHAPTER_PREFIX"%u/", encodedPath, tome, chapitre / 10);
		}
		else
		{
			if(chapitre % 10)
				snprintf(basePath, 500, PROJECT_ROOT"%s/"VOLUME_PREFIX"%u/"VOLUME_PRESHARED_DIR"/"CHAPTER_PREFIX"%u.%u/", encodedPath, tome, chapitre / 10, chapitre % 10);
			else
				snprintf(basePath, 500, PROJECT_ROOT"%s/"VOLUME_PREFIX"%u/"VOLUME_PRESHARED_DIR"/"CHAPTER_PREFIX"%u/", encodedPath, tome, chapitre / 10);
		}
    }
    else
    {
        if(chapitre % 10)
            snprintf(basePath, 500, PROJECT_ROOT"%s/"CHAPTER_PREFIX"%u.%u/", encodedPath, chapitre / 10, chapitre % 10);
        else
            snprintf(basePath, 500, PROJECT_ROOT"%s/"CHAPTER_PREFIX"%u/", encodedPath, chapitre / 10);
    }
	
    snprintf(temp, 600, "%s/"CONFIGFILE, basePath);
    if(!checkFileExist(temp))
    {
		//Décompression dans le repertoire de destination
		
        mkdirR(basePath);
        if(!checkDirExist(basePath))
            createPath(basePath);
		
        //On crée un message pour ne pas lire un chapitre en cours d'install
        char installingFile[600];
        snprintf(installingFile, sizeof(installingFile), "%sinstalling", basePath);
        FILE* ressources = fopen(installingFile, "w+");

		if(ressources != NULL)
            fclose(ressources);
		
        wentFine &= decompressChapter(buf, sizeBuf, basePath, *projectDB, chapitre / 10);

		remove(installingFile);
		
		if(wentFine && haveToPutTomeAsReadable)
			setTomeReadable(*projectDB, tome);

		if(!subFolder && !wentFine)
		{
			logR("Archive Corrompue: %ls - %d - %d", projectDB->repo->name, projectDB->projectID, chapitre);
			removeFolder(basePath);
		}
    }

	if(wentFine)
	{
		//Add a flag signaling the file wasn't read yet
		if(tome != INVALID_VALUE)
			snprintf(basePath, 500, PROJECT_ROOT"%s/"VOLUME_PREFIX"%u/", encodedPath, tome);
		
		finishInstallationAtPath(basePath);
	}

	free(encodedPath);
    return wentFine;
}
Beispiel #14
0
/** used by thread to process new request*/
void * processRequest(void * param) {
  RequestInfo *requestInfo = (RequestInfo *) param;
  int  sockFd = requestInfo->sockFd;
  char *clientIP  = requestInfo->clientIP;
  int  clientPort = requestInfo->clientPort;

  printf("start to serve request from %s:%d\n", clientIP, clientPort);
  //receive request file information
  char requestFile[1024] = {0};
  int recvStatus = recvFromSock(sockFd, requestFile, sizeof requestFile - 1, 1);
  if (recvStatus < 0) {
	printf("recv request info failed\n");
	closeSock(sockFd);
	free(requestInfo);
	return NULL;
  } else if (recvStatus == 0) {
	printf("client has closed this connection\n");
	closeSock(sockFd);
	free(requestInfo);
	return NULL;
  }
  printf("requestInfo: %s\n", requestFile);

  // check File existence and open file
  if (!checkFileExist(requestFile)) {
	printf("file doesn't exist: %s\n", requestFile);
	closeSock(sockFd);
	free(requestInfo);
	return NULL;
  }
  FILE * fd = fopen(requestFile, "r");
  if (!fd) {
	printf("open request file failed\n");
	goto cleanAndQuit;
  }

  // send requested file
  char buffer[1024];
  unsigned int requestFileSize = getFileSize(requestFile);
  unsigned int readSize = 0;
  unsigned int sentSize = 0;
  printf("start to send to client\n");
  while (readSize < requestFileSize) {
	unsigned int tempReadLen = 0;
	memset(buffer, 0, sizeof buffer);
	if ((tempReadLen = fread(buffer, sizeof(char), sizeof buffer -1, fd)) < 0) {
	  printf("read file failed %d\n", tempReadLen);
	  goto cleanAndQuit;
	}
	readSize += tempReadLen;

	//send to socket
    if (sendToSock(sockFd, buffer, tempReadLen, 1) != 1) {
	  printf("send to sock failed\n");
	  goto cleanAndQuit;
	}
	sentSize += tempReadLen;
	//printf("send to client with len %d, sumLen, %d\n", sumSentLen, sentSize);

	if (canRead(sockFd) != 1) {
	  continue;
	}
	printf("start to receive cancel/close msg\n");
	memset(buffer, 0, sizeof buffer);
    int recvLen = recvFromSock(sockFd, buffer, sizeof buffer - 1, 1);
	if (recvLen <= 0) {// the other side has close the sockfd or some error happens
	  printf("failed to recv close/cancel signal\n");
	  goto cleanAndQuit;
	}
	printf("sent %d KB data\n", sentSize / 1024);
	printf("receive cancel/close msg: %s\n", buffer);
	if (strcmp(buffer, CANCEL_MSG) == 0) {
	  printf("wait for close after receiving cancel msg\n");
	  if (waitForClose(sockFd) == 1) {
		printf("client close connection, quit right now\n");
	  } else {
		printf("waitForClose Failed, quit right now\n");
	  }
	} else {
	  printf("close after receiving close msg\n");
	}
	cleanAndQuit:
	closeSock(sockFd);
	if (requestInfo) {
	  free(requestInfo);
	}
	if (fd) {
	  fclose(fd);
	}
	return NULL;
  }
}
Beispiel #15
0
void initializeTags(void * mainCache)
{
	MUTEX_CREATE(concurentColdUpdate);
	
	sqlite3 * coldDB = NULL;
	
	//Create the tables in the main cache
	createTagsTable(mainCache);
	
	if((!checkFileExist(TAG_DB) || sqlite3_open(TAG_DB , &coldDB) != SQLITE_OK) && (!checkFileExist(WIP_TAG_DB) || sqlite3_open(WIP_TAG_DB, &coldDB) != SQLITE_OK))
	{
		//Error, we should reset it with the version we ship with then trigger an update
		resetTagsToLocal();
		
		if(!checkFileExist(TAG_DB) || sqlite3_open(TAG_DB , &coldDB) != SQLITE_OK)
		{
			alertExit("We have significant issues setting up our environment, this may be caused by permission issues, please contact us at [email protected]");
		}
	}
	
	sqlite3_stmt * requestRead, *requestWrite;
	
	//Build the tag base
	if((requestRead = createRequest(coldDB, "SELECT "DBNAMETOID(RDB_tagID)", "DBNAMETOID(RDB_tagName)" FROM "TABLE_TAGS)) != NULL)
	{
		requestWrite = tagUpdateQuery(mainCache, false);
		
		if(requestWrite != NULL)
		{
			while(sqlite3_step(requestRead) == SQLITE_ROW)
			{
				sqlite3_bind_int(requestWrite, 1, sqlite3_column_int(requestRead, 0));
				sqlite3_bind_text(requestWrite, 2, (void *) sqlite3_column_text(requestRead, 1), -1, SQLITE_STATIC);
				
				if(sqlite3_step(requestWrite) != SQLITE_DONE)
				{
#ifdef EXTENSIVE_LOGGING
					uint ID = (uint32_t) sqlite3_column_int(requestRead, 0);
					const unsigned char * text = sqlite3_column_text(requestRead, 1);
					
					if(text == NULL)
						logR("Error building the tag DB for ID %d: no text!", ID);
					else
						logR("Error building the tag DB for ID %d of text %s!", ID, text);
#endif
				}
				sqlite3_reset(requestWrite);
			}
			destroyRequest(requestWrite);
		}
		destroyRequest(requestRead);
	}
	
	//Build the category base
	if((requestRead = createRequest(coldDB, "SELECT "DBNAMETOID(RDB_CAT_ID)", "DBNAMETOID(RDB_CAT_rootID)", "DBNAMETOID(RDB_CAT_name)" FROM "TABLE_CATEGORY)) != NULL)
	{
		requestWrite = catUpdateQuery(mainCache, false);
		
		if(requestWrite != NULL)
		{
			
			while(sqlite3_step(requestRead) == SQLITE_ROW)
			{
				sqlite3_bind_int(requestWrite, 1, sqlite3_column_int(requestRead, 0));
				sqlite3_bind_int(requestWrite, 2, sqlite3_column_int(requestRead, 1));
				sqlite3_bind_text(requestWrite, 3, (void *) sqlite3_column_text(requestRead, 2), -1, SQLITE_STATIC);
				
				for(byte i = 0; i < 32; i++)
				{
					sqlite3_bind_int(requestWrite, i + 4, sqlite3_column_int(requestRead, i + 3));
				}
				
				if(sqlite3_step(requestWrite) != SQLITE_DONE)
				{
#ifdef EXTENSIVE_LOGGING
					uint ID = (uint32_t) sqlite3_column_int(requestRead, 0);
					const unsigned char * text = sqlite3_column_text(requestRead, 2);
					
					if(text == NULL)
						logR("Error building the category DB for ID %d: no text!", ID);
					else
						logR("Error building the category DB for ID %d of text %s!", ID, text);
#endif
				}
				sqlite3_reset(requestWrite);
			}
			destroyRequest(requestWrite);
		}
		destroyRequest(requestRead);
	}
	sqlite3_close(coldDB);
}