Example #1
0
// Taken from tsid
uint32_t recurse(FILE *fmatched, char *dir)
{
    uint32_t matches = 0;
    dirent *dp;
    struct stat st;
    DIR    *dirp;
    char   nbuf[MAX_PATH_LEN];
    size_t len;

    SDEBUG("Recurse into directory " << dir << endl);

    dirp=opendir(dir);

    if (dirp==NULL)
    {
        SDEBUG(dir << " unreadable\n");
        return 0;
    }

    while ((dp=readdir(dirp)) != NULL)
    {
        if (!strcmp(dp->d_name,".") || !strcmp(dp->d_name,".."))
            continue;

        len=strlen(dir);
        if (len+NLENGTH(dp)+1 < MAX_PATH_LEN-1)
        {
            strcpy(nbuf,dir);
            if (len != 0) // dir = "" means current dir on Amiga
                nbuf[len++]='/';
            strcpy(nbuf+len, dp->d_name);

            stat(nbuf, &st);

            if (S_ISDIR(st.st_mode))
                matches += recurse(fmatched, nbuf); // recurse into directory

            if (S_ISREG(st.st_mode))
                matches += analyse(fmatched, nbuf); // add the file
        }
        else
        {
            SDEBUG(dir << "/" << dp->d_name << ": pathname too long\n");
        }
    }
    closedir(dirp);
    return matches;
}
Example #2
0
Scheduler::~Scheduler() {
	XOJ_CHECK_TYPE(Scheduler);

	SDEBUG("Destroy scheduler\n", 0);

	if(this->jobRenderThreadTimerId) {
		g_source_remove(this->jobRenderThreadTimerId);
		this->jobRenderThreadTimerId = 0;
	}

	stop();

	g_mutex_free(this->jobQueueMutex);
	g_mutex_free(this->jobRunningMutex);

	g_mutex_free(this->schedulerMutex);

	g_mutex_free(this->blockRenderMutex);

	g_cond_free(this->jobQueueCond);

	Job * job = NULL;
	while (job = getNextJobUnlocked()) {
		job->unref();
	}

	if (this->blockRenderZoomTime) {
		g_free(this->blockRenderZoomTime);
	}

	XOJ_RELEASE_TYPE(Scheduler);
}
Example #3
0
// Signal that the MULTICAST_TERMINATION_REQUEST message has been processed
void MulticastRecvQueue::signal_termination_synchronization()
{
  pthread_mutex_unlock(&mutex);
  SDEBUG("signal_termination_synchronization\n");
  pthread_cond_signal(&termination_cond);
  pthread_mutex_unlock(&mutex);
}
Example #4
0
int	check_pfieldar(void) {
	ematrix		*e1,*er;
	framestruc	*fr;
	int		j,r;
	char		buf[500];
	exp_t		xx,xx2;
	sign_t		gg,gg2;
	
	e1 = check_randommatrix(1,10,5);
	sprintf(buf," (%s)*((%s)^-3+(%s)/(%s)^2)",
			pfield_printvalue_formal(NULL,90,EXPM(e1,0,1),SIGNM(e1,0,1)),
			pfield_printvalue_to(NULL,90,EXPM(e1,0,2),SIGNM(e1,0,2)),
			pfield_printvalue_to(NULL,90,EXPM(e1,0,3),SIGNM(e1,0,3)),
			pfield_printvalue_formal(NULL,90,EXPM(e1,0,4),SIGNM(e1,0,4)));
			/* (the mix of formal and regular printing is intended here) */
	r = 0;
	xx = EXPM(e1,0,3);  gg = SIGNM(e1,0,3);
	xx2 = EXPM(e1,0,2);  gg2 = SIGNM(e1,0,2);
	j = (SIGNM(e1,0,1) && SIGNM(e1,0,4))? 0:-1;
	if (j>=0)  j = pfield_mul_ch(0,1,xx,gg,-2,EXPM(e1,0,4),SIGNM(e1,0,4),&xx,&gg);
	if (j>=0)  j = pfield_mul_ch(0,1,xx,gg,1,EXPM(e1,0,1),SIGNM(e1,0,1),&xx,&gg);
	if (j>=0)  j = pfield_mul_ch(0,-3,xx2,gg2,1,EXPM(e1,0,1),SIGNM(e1,0,1),&xx2,&gg2);
	if (j>=0)  j = pfield_sum_ch(0,1,xx,gg,1,xx2,gg2,&xx,&gg);
	if (j>=0) {
		fr = frame_doinput(buf);
		er = fr?FRMATRIX(fr):NULL;
		if (!er?1: !pfield_isequal(xx,gg,EXPM(er,0,0),SIGNM(er,0,0))) {
			r = -1;
			SDEBUG(0,"BAD:  %s  =  %s : %s\n",buf,!er?"XX":pfield_printvalue(90,EXPM(er,0,0),SIGNM(er,0,0)),pfield_printvalue(90,xx,gg));
		} else  r = 1;
		if (fr)  dispose_frame_recur(fr);
	}
	dispose_ematrix(e1);
	return (perror_occured || uerror_occured)? -1:r;
}	
Example #5
0
int	check_inpfield(void) {
	ematrix		*e, *e2;
	int		i,j,r,c, n1=0,sz, ret=0;
	exp_t		xx,xx2;
	sign_t		gg,gg2;
	
	sz = (pfispartial? 4:8);
	e = check_randommatrix(sz,sz,pfispartial?2:10);
	e2 = ematrix_copydual(e);
	j = ematrix_inpfield(e);
	if (j>=0) {
		ret = 1;
		ematrix_determinant(e,&xx,&gg);
		n1 = ematrix_matrank(e);
		if (n1>sz || (gg!=0 && n1<sz))  ret = -1;
	}
	if (j>=0 && ret>=0) {
		ematrix_swaprows(e2,1,3);  ematrix_swapcols(e2,0,1);
		if (ematrix_matrank(e2)!=n1)  ret = -2;
		ematrix_determinant(e2,&xx2,&gg2);
		if (!pfield_isequal(xx,gg,xx2,gg2))  ret = -3;
		for (i=0; i<5; i++) {
			r = RANDOM()%ROWSM(e2);  c = RANDOM()%COLSM(e2);
			if (SIGNM(e2,r,c)!=0)  ematrix_pivot(e2,r,c);
		}
		if (ematrix_inpfield(e2)<0)  ret = -4;
	}
	if (ret<0)  {SDEBUG(0,"\nerr%d:  det=%s %s  rank=%d %d\n",ret,
			pfield_pvalue(14,xx,gg),pfield_pvalue(14,xx2,gg2),n1,ematrix_matrank(e2));
			EMATDEBUG(0,e," !1!\t"); EMATDEBUG(0,e2," !2!\t");}
	dispose_ematrix(e);  dispose_ematrix(e2);
	return ret;
}
static void h3600_stowaway_process_char(struct skbd_state *skbd, unsigned char data )
{
	unsigned char cooked;
	unsigned char *index;

	unsigned char key  = data & 0x7f;
	unsigned int  down = !(data & 0x80);

	SFDEBUG(1,"%#02x [%s]", key, (down?"down":" up "));

	if (key >= SKBD_KEYMAP_SIZE) {
		SDEBUG(1," --> discarding\n");
		return;
	}

	index = skbd->keycode + key * SKBD_MODIFIER_STATES;
	if ( *index == SKEY_FUNCTION ) {
		skbd->function = down;
		SDEBUG(1," --> function\n");
		return;
	}

	cooked = *index;
	if (skbd_numlock && index[SKBD_NUMLOCK_OFFSET])
		cooked = index[SKBD_NUMLOCK_OFFSET];
	if (skbd->function && index[SKBD_FUNCTION_OFFSET])
		cooked = index[SKBD_FUNCTION_OFFSET];
	
	if ( !cooked ) {
	        SDEBUG(1," --> invalid keystroke\n");
		return;
	}

	if ( (test_bit(cooked,skbd->key_down) && down)
	     || (!test_bit(cooked,skbd->key_down) && !down)) {
		SDEBUG(1," --> already set\n");
		return;
	}

	if ( down ) 
		set_bit(cooked,skbd->key_down);
	else
		clear_bit(cooked,skbd->key_down);

	SDEBUG(1," --> sending %d (%d)\n", cooked, down);
	handle_scancode(cooked, down);
}
Example #7
0
// Set queue to the error state
void MulticastRecvQueue::set_fatal_error() {
  pthread_mutex_unlock(&mutex);
  n_messages = UINT_MAX;
  SDEBUG("Fatal error occurred, waking the receiving process\n");
  pthread_cond_signal(&data_ready_cond);
  pthread_cond_signal(&termination_cond);
  pthread_mutex_unlock(&mutex);
}
void ScriptEngine::continueInferior()
{
    QTC_ASSERT(state() == InferiorStopOk, qDebug() << state());
    notifyInferiorRunRequested();
    SDEBUG("ScriptEngine::continueInferior()");
    m_stopped = false;
    m_stopOnNextLine = false;
}
Example #9
0
/* {{{ suhosin_cookie_decryptor
 */
char *suhosin_cookie_decryptor(char *raw_cookie)
{
	// SDEBUG("raw cookie: %s", raw_cookie);
	char *decrypted, *ret;
	// int j;
	char cryptkey[33];

	suhosin_generate_key(SUHOSIN7_G(cookie_cryptkey), SUHOSIN7_G(cookie_cryptua), SUHOSIN7_G(cookie_cryptdocroot), SUHOSIN7_G(cookie_cryptraddr), cryptkey);
	SDEBUG("cryptkey=%02x.%02x.%02x", cryptkey[0], cryptkey[1], cryptkey[2]);
	
	ret = decrypted = emalloc(strlen(raw_cookie)*4+1);
	raw_cookie = estrdup(raw_cookie);
	SUHOSIN7_G(raw_cookie) = estrdup(raw_cookie);

	char *strtok_buf = NULL;
	char *var, *val;
	const char *separator = ";\0";
	for (char *var = php_strtok_r(raw_cookie, separator, &strtok_buf); var; var = php_strtok_r(NULL, separator, &strtok_buf)) {
		val = strchr(var, '=');
		while (isspace(*var)) { var++; }
		if (var == val || *var == '\0') { continue; }
		if (val) {
			*val++ = '\0';
			// size_t var_len = php_url_decode(var, strlen(var));
			size_t var_len = strlen(var);
			// size_t val_len = php_url_decode(val, strlen(val));
			size_t val_len = strlen(val);
			SDEBUG("decrypting cookie |%s|%s|", var, val);
			suhosin_decrypt_single_cookie(var, var_len, val, val_len, cryptkey, &decrypted);
			SDEBUG("ret is now %s", ret);
			*decrypted++ = ';';
		} else {
			// ??
		}
	}

	*decrypted++ = 0;
	ret = erealloc(ret, decrypted-ret);
	
	SUHOSIN7_G(decrypted_cookie) = ret;
	efree(raw_cookie);
		
	return ret;
}
Example #10
0
// Wait until the MULTICAST_TERMINATION_REQUEST message will be processed
void MulticastRecvQueue::wait_termination_synchronization()
{
  pthread_mutex_lock(&mutex);
  DEBUG("wait_termination_synchronization n_messages: %d\n", n_messages);
  if (n_messages > 0 && n_messages < UINT_MAX) {
    pthread_cond_wait(&termination_cond, &mutex);
    SDEBUG("termination_cond occurred\n");
  }
  pthread_mutex_unlock(&mutex);
}
Example #11
0
int	final_check(void) {
	
	if (perror_occured || uerror_occured) {
		printf("\n\n!!!!!!!!!!!!!!! ERROR occured during computation !!!!!!!!!!!!!!\n\n");
		if (printout!=stdout)  fprintf(printout,"\n\n!!!!!!!!!!!!!!! ERROR occured during computation !!!!!!!!!!!!!!\n\n");
		if (errorout!=stdout && errorout!=stderr)  fprintf(errorout,"\n\n!!!!!!!!!!!!!!! ERROR occured during computation !!!!!!!!!!!!!!\n\n");
	} else {
		SDEBUG(1,"\n%s %s finished OK\n",PROGNAME,PROGVER);
	}
	return 0;
}
void ScriptEngine::shutdownInferior()
{
    QTC_ASSERT(state() == InferiorShutdownRequested, qDebug() << state());
    SDEBUG("ScriptEngine::shutdownInferior()");
    m_scriptEngine->setAgent(0);
    //m_scriptAgent.reset(0);
    m_stopped = false;
    m_stopOnNextLine = false;
    if (m_scriptEngine->isEvaluating())
        m_scriptEngine->abortEvaluation();
    notifyInferiorShutdownOk();
}
Example #13
0
void Scheduler::addJob(Job * job, JobPriority priority) {
	XOJ_CHECK_TYPE(Scheduler);

	g_mutex_lock(this->jobQueueMutex);

	job->ref();
	g_queue_push_tail(this->jobQueue[priority], job);
	g_cond_broadcast(this->jobQueueCond);

	SDEBUG("add job: %ld\n", (long)job);

	g_mutex_unlock(this->jobQueueMutex);
}
Example #14
0
framestruc*	yy_endframe(void) {
	framestruc	*fr;
	ematrix		*ee,*en;
	char		*nm, buf[30], **noval;
	int		sz;
	
	ee = FRMATRIX(curframe);
	ROWSM(ee) = FRMATRIXROWS(curframe);	/* the actual dimensions of the matrix */
	COLSM(ee) = FRMATRIXCOLS(curframe);
	sz = ROWSM(ee)+COLSM(ee);
	if (lerror_occured<0 && savefrm) {	/* replace the old matrix on syntax errors */
		en = savefrm;
	} else if (sz>0) {			/* the proper-size copy of the matrix, with tr==0 */
		en = ematrix_copy_ext(ee,ROWSM(ee)+1,COLSM(ee)+1,0);
		ematrix_resetid(en);
	} else  en = NULL;
	frame_setmatrix(curframe,en);
						/* fills in some name if not determined yet */
	if (!FRNAME(curframe) && FRPARENT(curframe)) {
		nm = FRNAME(FRPARENT(curframe));
		if (nm)  snprintf(buf,25,FR_DEFSUBNAME,FRNUMSONS(FRPARENT(curframe)));
		else  snprintf(buf,25,FR_DEFSUBNONAME,framelev,FRNUMSONS(FRPARENT(curframe)));
		frame_setname2(curframe,nm,buf);
	}
	if (!FRNAME(curframe))  frame_setname(curframe,FR_DEFNONAME);
	noval = NULL;
#ifndef FASTPROG
	noval = frame_getoptionval_last(curframe,"nopfcheck");  if (noval)  dispose_alist(noval);
	if (noval==NULL)
		if (sz>2 && sz<20) if (ematrix_inpfield_rand(FRMATRIX(curframe))<0) {
			EMATOUTPUT(FRMATRIX(curframe),"!\t");
			ematrix_inpfield_printed(FRMATRIX(curframe));
			LERROR("The matrix is not represented over the pfield!");
		}
	DEBUG(CURDLEV,"%*s=> Input of frame %p [%s] (fr-lev %d) finished.\n",framelev,"",curframe,FRNAME(curframe),framelev);
	if (CURDLEV+1<=DEBUGLEV)  frame_fprint_all(debugout,curframe,"\t");
	SDEBUG(CURDLEV+1,"\t-----------\n");
#endif
	if (FRPFINDEX_SAVE(curframe)>=0 && FRPFINDEX_SAVE(curframe)!=pfield_curindex()) {
			/* back to the original pfield of this frame - <0 or stored at '@inputpf XX' */
		pfield_switchto_fast(FRPFINDEX_SAVE(curframe));
		DEBUG(CURDLEV-2,"Switched input arithmetics back to pfield \"%s\"\n",pfield_curname());
	}
	fr = curframe;
	if (FRPARENT(curframe))  curframe = FRPARENT(curframe);	/* back to the parent frame */
	errhint = -1;
	mxline = FRMATRIXROWS(curframe);	/* (stored number of matrix lines for the parent frame) */
	return fr;
}
Example #15
0
int	begin_check(void) {
	int	i,j, r=0, er=0;
	
	printlev -= 4;
	SDEBUG(CURDLEV,"%s %s (%s) in \'%s\': checking program consistency...\n",PROGNAME,PROGVER,PROGDATE,pfield_curname());
	
	for (i=j=0; i<50 && r>=0; i++) {
		r = check_pfieldar();  j += r;
	}
	if (r>=0)  SDEBUG(CURDLEV,"\tpf arithm%d",j);
	else  {PROGERROR("Internal pfield arithmetic error."); er=1;}
	perror_occured = uerror_occured = 0;
	
	r = check_framerw();
	if (r>=0)  SDEBUG(CURDLEV,"\tframe r/w%d",r);
	else  {PROGERROR("Internal frame read/write error - see %smacek-test-??.",frame_autosave_pref); er=1;}
	perror_occured = uerror_occured = 0;
	
	for (i=j=0; i<50 && r>=0 && j<3; i++) {
		r = check_inpfield();  j += r;
	}
	if (r>=0)  SDEBUG(CURDLEV,"\tinpf test%d",j);
	else  {PROGERROR("Internal pfield matrix (det,rank) testing error."); er=1;}
	
	r = check_structural();
	if (r>=0)  SDEBUG(CURDLEV,"\tstruct(reg)%d",r);
	else  {PROGERROR("Internal matroidal-structure (minors) error."); er=1;}
	perror_occured = uerror_occured = 0;
	
	r = check_structuralb();
	if (r>=0)  SDEBUG(CURDLEV,"\tstruct(iso)%d",r);
	else  {PROGERROR("Internal matroidal-structure (isom or repres) error."); er=1;}
	perror_occured = uerror_occured = 0;
	
	r = check_extgener();
	if (r>=0)  SDEBUG(CURDLEV,"\text/repr%d",r);
	else  {PROGERROR("Internal matroidal-structure error when generating extensions or representations."); er=1;}
	perror_occured = uerror_occured = 0;
	
	if (!er)  SDEBUG(CURDLEV,"\n... consistency check passed OK.\n");
	printlev += 4;
	return er? -1:1;
}
Example #16
0
int	check_structuralb(void) {
	ematrix		**el, *r10,*r10b,*r10n;
	int		pi,pi5, ret = 0;
	
	el = frame_inputmatrices(" -1 1 0 0 1; 1 -1 1 0 0; 0 1 -1 1 0; 0 0 1 -1 1; 1 0 0 1 -1");
	r10 = r10b = ematrix_copy(el[0]);
	dispose_alist_mats(el);
	pi = pi5 = pfield_curindex();
#ifndef	BINARYONLY
	pfield_switchto("GF(5)");
	pi5 = pfield_curindex();
	el = frame_inputmatrices(" 4 1 0 0 1; 0 1 1 0 1; 1 4 4 1 4; 1 0 0 1 4; 0 0 1 4 1");
	r10b = ematrix_copy(el[0]);
	dispose_alist_mats(el);
	el = frame_inputmatrices(" 4 1 0 0 1; 0 1 1 0 1; 1 4 4 1 4; 1 2 0 1 4; 0 0 1 4 1");
	r10n = ematrix_copy(el[0]);
	dispose_alist_mats(el);
	pfield_switchto_fast(pi);
	
	if (RANDOM()%12==1) {
		if (!strmag_isisomorphic(r10,r10b,pi5))  ret = -12;
		if (strmag_isisomorphic(r10,r10n,pi5))  ret = -13;
		if (ret>=0)  ret += 2;
	}
	pfield_switchto_fast(pi5);
	if (RANDOM()%12==1) {
		if (strmag_isautmap(r10n,1,2))  ret = -16;
		if (!strmag_isautmap(r10n,1,5))  ret = -17;
		if (ret>=0)  ret += 1;
	}
	if (RANDOM()%30==1) {
		if (grepr_generate_all(r10n,pi5,NULL)!=2)  ret = -26;
		if (ret>=0)  ret += 2;
	}
	pfield_switchto_fast(pi);
	dispose_ematrix(r10);  dispose_ematrix(r10n);
#endif
	if (RANDOM()%30==1) {
		if (grepr_generate_all(r10b,pi5,NULL)!=1)  ret = -25;
		if (ret>=0)  ret += 1;
	}
	dispose_ematrix(r10b);
	if (ret<0)  {SDEBUG(0,"\n\tBAD  ret=%d\n",ret);}
	return (perror_occured || uerror_occured)? -1:ret;
}
Example #17
0
File: spl-err.c Project: Lezval/spl
void
vcmn_err(int ce, const char *fmt, va_list ap)
{
	char msg[MAXMSGLEN];

	if (ce == CE_PANIC)
		vpanic(fmt, ap);

	if (ce != CE_NOTE) {
		vsnprintf(msg, MAXMSGLEN - 1, fmt, ap);

		if (fmt[0] == '!')
			SDEBUG(SD_INFO, "%s%s%s",
			       ce_prefix[ce], msg, ce_suffix[ce]);
		else
			SERROR("%s%s%s", ce_prefix[ce], msg, ce_suffix[ce]);
	}
} /* vcmn_err() */
Example #18
0
File: main.c Project: CogDis/craftd
static
bool
cdadmin_HandleCommand (CDServer* server, CDPlayer* player, CDString* command)
{
	CDRegexp*        regexp  = CD_CreateRegexp("^(\\w+)(?:\\s+(.*?))?$", CDRegexpNone);
	CDRegexpMatches* matches = CD_RegexpMatch(regexp, command);

	if (!matches) {
		goto error;
	}

	SDEBUG(server, "Command> %s: %s\n", CD_StringContent(matches->item[1]), CD_StringContent(matches->item[2]));

	#include "src/auth.c"
	#include "src/workers.c"
//    #include "src/player.c"
//    #include "src/ticket.c"

	error: {
		CD_DestroyRegexpKeepString(regexp);

		if (matches) {
			CD_DestroyRegexpMatches(matches);
		}

		return true;
	}

	done: {
		CD_DestroyRegexpKeepString(regexp);

		if (matches) {
			CD_DestroyRegexpMatches(matches);
		}

		return false;
	}
}
Example #19
0
framestruc*	frame_doinput_ext(char *ins, char **insl, framestruc *infr, char *name, int rec) {
	char		*repl[2] = SPECREPLACE, buf[50],*bnm, *inp, **xin;
	int		i;
	framestruc	*frs=NULL, *f;
	
	if ((ins && insl) || (!ins && !insl) || (insl?!insl[0]:0))
		{PROGERROREXIT("Exactly one of ins, insl must be given! %p %p",ins,insl);}
	if (!rec && curframe)
		{PROGERROREXIT("The lexical scanner is not re-entrant - current frame is %p [%s]",curframe,FRNAME(curframe));}
	lerror_occured = 0;	/* clear the local error-flag */
	
	if (insl) {
			/* scans the input list of strings one by one, indexing the given name */
		DEBUG(CURDLEV-1,"Calling to scan a list of input frames...\n");  SDEBUG(CURDLEV+1,"\t-----------\n");
		for (xin=insl,i=0; *xin; xin++,i++) {
			if (name) {
				snprintf(buf,48,name,i);  buf[48] = 0;  bnm = buf;
			} else  bnm = NULL;
			f = frame_doinput_ext(*xin,NULL,NULL,bnm,1);
			if (i==0)  frs = f;	/* (only the first frame is returned!) */
		}
	} else {
			/* scans one given string, applies the replacements requested by SPECREPLACE */
		DEBUG(CURDLEV-1,"Input frame - lexical scanning \"%s\":\n",ins);
		inp = yy_specrepl(ins,repl);
			/* here the new frame (or subframe) is created for the current input */
		yy_startframe(name,infr);
		yyincl(inp,0);
		fullineno = 1;  framelev = 0;
		frame_flex();		/* this calls the lexical analyzer preprocessed by flex */
		if (framelev>0)  {LERROR("Unclosed subframe(s) on the input!");}
		FREE(inp);
		frs = yy_endframe();	/* (the frame is finished and returned here) */
	}
	if (!rec)  curframe = NULL;	/* must clear the current frame reference for the next call */
	if (lerror_occured<0 && !infr)  return NULL;	/* nothing is returned on an error (and no cleaning here) */
	return frs;
}
void ScriptEngine::importExtensions()
{
    SDEBUG("ScriptEngine::importExtensions()");
    QStringList extensions;
    const int extCount = sizeof(qtExtensionsC)/sizeof(const char *);
    for (int  e = 0; e < extCount; e++)
        extensions.append(QLatin1String(qtExtensionsC[e]));
    if (m_scriptEngine->importedExtensions().contains(extensions.front()))
        return; // true;
    QDir dir(QLatin1String("/home/apoenitz/dev/qtscriptgenerator"));
    if (!dir.cd(QLatin1String("plugins"))) {
        fprintf(stderr, "plugins folder does not exist -- did you build the bindings?\n");
        return; // false;
    }
    QStringList paths = qApp->libraryPaths();
    paths <<  dir.absolutePath();
    qApp->setLibraryPaths(paths);
    QStringList failExtensions;
    foreach (const QString &ext, extensions) {
        QScriptValue ret = m_scriptEngine->importExtension(ext);
        if (ret.isError())
            failExtensions.append(ext);
    }
Example #21
0
static int dx_bufferspace(void)
{
    DWORD play_cursor;
    int free_samples, buffer_samples;

    IDirectSoundBuffer_GetCurrentPosition(buffer, &play_cursor, NULL);
    /* We should properly distinguish between buffer empty and buffer fill
     * case. However, it's absolutely essential that the state where play and
     * write cursors overlap is read as buffer being filled with data. */
    if (play_cursor < buffer_offset) {
        free_samples = buffer_size - (buffer_offset - play_cursor);
    } else {
        free_samples = play_cursor - buffer_offset;
    }

    SDEBUG(("play=%d, ourwrite=%d, free=%d", play_cursor, buffer_offset, free_samples));

    free_samples /= (is16bit ? 2 : 1) * num_of_channels;

    /* test for underrun condition. It generally looks like we suddenly we have
     * a filled buffer instead of nearly empty one, because the play cursor
     * stepped over the write cursor. We generally have sound core calling
     * bufferspace() with every write, so we can rely on frequent calls here.
     */
    buffer_samples = buffer_size / (is16bit ? 2 : 1) / num_of_channels;
    if (free_samples < fragment_size
        && earlier_bufferspace > buffer_samples - fragment_size) {
        /* don't trigger again */
        earlier_bufferspace = 0;
        /* report underrun */
        return buffer_samples;
    }
    earlier_bufferspace = free_samples;

    return free_samples;
}
Example #22
0
int	check_structural(void) {
	ematrix		**el,*e,*ee,*eee, *r10,*r12, *k5,*k33;
	int		i,j, ret = 0;
	
	el = frame_inputmatrices(" -1 1 0 0 1; 1 -1 1 0 0; 0 1 -1 1 0; 0 0 1 -1 1; 1 0 0 1 -1");
	r10 = ematrix_copy(el[0]);
	dispose_alist_mats(el);
	el = frame_inputmatrices(" 1 1 1 0 0 0; 1 1 0 1 0 0; 1 0 0 0 1 0; 0 1 0 0 0 1; 0 0 1 0 -1 -1; 0 0 0 1 -1 -1");
	r12 = ematrix_copy(el[0]);
	dispose_alist_mats(el);
	el = frame_inputmatrices(" 1 1 0 0 0 1; 1 1 0 1 1 1; 1 0 1 1 1 1; 1 0 1 0 1 0");
	k5 = ematrix_copy(el[0]);
	dispose_alist_mats(el);
	el = frame_inputmatrices(" 1 1 0 0; 1 1 1 0; 1 1 1 1; 0 1 1 1; 0 1 0 1");
	k33 = ematrix_copy(el[0]);
	dispose_alist_mats(el);
	
	if (RANDOM()%5==1) {
		if (struct_matrixselfmaps_number(r10)!=10)  ret = -2;
		if (struct_matrixselfmaps_number(r12)!=8)  ret = -3;
		if (ret>=0)  ret++;
	}
	if (RANDOM()%6==1) {
		if (ematrix_getmhash(r10)!=EM_HASHR10)  ret = -5;
		/* (definition of EM_HASHR10 is in ../include/ematrix.h for update) */
		el = ematrix_getbases_sq(r10);
		if (ret>=0)  ret++;
		if (alist_getlength(el)!=162)  ret = -6;
		dispose_alist_mats(el);
	}
	if (RANDOM()%30==1) {
		el = ematrix_getbases_sq(r12);
		if (ret>=0)  ret++;
		if (alist_getlength(el)!=441)  ret = -7;
		dispose_alist_mats(el);
	}
	if (RANDOM()%15==1) {
		e = ematrix_copy(r10);
		i = RANDOM()%10-5;  if (i>=0)  i++;
		ee = ematrix_removematid_del(e,i);
		if (ret>=0)  ret++;
		if (!struct_isequivalent(ee,k33))  ret = -10;
		dispose_ematrix(e);  dispose_ematrix(ee);
	}
	if (RANDOM()%100==1) {
		e = ematrix_copy(r12);
		i = RANDOM()%8-4;  if (i>=0)  i++;
		ee = ematrix_removematid_contr(e,i);
		if (ret>=0)  ret += 5;
		if (struct_hasminor(ee,k5))  ret = -11;
		eee = ematrix_removematid_contr(k5,i);
		if (!struct_hasminor(ee,eee))  ret = -12;
		if (struct_isconnected(eee,3))  ret = -15;
		dispose_ematrix(e);  dispose_ematrix(ee);  dispose_ematrix(eee);
	}
	if (RANDOM()%5==1)
		if (struct_hasbwidth3(r10))  ret = -20;
	if (RANDOM()%25==1) {
		if (ret>=0)  ret += 2;
		if (struct_connectivity(r10)!=4)  ret = -21;
		if (struct_connectivity(k5)!=3)  ret = -22;
	}
	if (RANDOM()%40==1) {
		if (ret>=0)  ret += 2;
		if (!struct_hasbwidth3(r12))  ret = -26;
		if (!struct_hasdelcontr_one(r12,k33))  ret = -28;
		if (struct_hasdelcontr_one(r10,k33))  ret = -29;
	}
	if (RANDOM()%10==1) {
		e = ematrix_copydual(r10);
		i = RANDOM()%5;  j = RANDOM()%5;
		if (SIGNM(e,i,j))  ematrix_pivot(e,i,j);
		if (ret>=0)  ret++;
		if (!struct_isequivalent(e,r10))  ret = -30;
		dispose_ematrix(e);
	}
	if (RANDOM()%15==1) {
		if (ret>=0)  ret += 3;
		if (struct_matgirth(r10)!=4)  ret = -35;
		if (struct_matgirth(k5)!=3)  ret = -36;
		ematrix_transpose(k5);
		if (struct_matgirth(k5)!=4)  ret = -35;
		ematrix_transpose(k5);
	}
	
	dispose_ematrix(r10);  dispose_ematrix(r12);
	dispose_ematrix(k5);  dispose_ematrix(k33);
	if (ret<0)  {SDEBUG(0,"\n\tBAD  ret=%d\n",ret);}
	return (perror_occured || uerror_occured)? -1:ret;
}
Example #23
0
File: Worker.c Project: Youx/craftd
bool
CD_RunWorker (CDWorker* self)
{
    assert(self);

    SLOG(self->server, LOG_INFO, "worker %d started", self->id);

    while (self->working) {
        self->job = NULL;

        if (!CD_HasJobs(self->workers)) {
            pthread_mutex_lock(&self->workers->lock.mutex);

            SDEBUG(self->server, "worker %d ready", self->id);

            pthread_cond_wait(&self->workers->lock.condition, &self->workers->lock.mutex);

            pthread_mutex_unlock(&self->workers->lock.mutex);
        }

        if (!self->working) {
            break;
        }

        self->job = CD_NextJob(self->workers);

        if (!self->job) {
            SDEBUG(self->server, "no jobs for %d :<", self->id);
            continue;
        }

        SDEBUG(self->server, "worker %d running", self->id);

        if (self->job->type == CDCustomJob) {
            CDCustomJobData* data = (CDCustomJobData*) self->job->data;

            data->callback(data->data);

            CD_DestroyJob(self->job);
        }
        else if (CD_JOB_IS_PLAYER(self->job)) {
            CDClient* client;

            if (self->job->type == CDClientProcessJob) {
                client = ((CDClientProcessJobData*) self->job->data)->client;
            }
            else {
                client = (CDClient*) self->job->data;
            }

            if (!client) {
                CD_DestroyJob(self->job);
                continue;
            }

            pthread_rwlock_rdlock(&client->lock.status);
            if (client->status == CDClientDisconnect) {
                if (self->job->type != CDClientDisconnectJob) {
                    CD_DestroyJob(self->job);
                    self->job = NULL;
                    client->jobs--;
                }
            }
            pthread_rwlock_unlock(&client->lock.status);

            if (!self->job) {
                continue;
            }

            if (self->job->type == CDClientConnectJob) {
                CD_EventDispatch(self->server, "Client.connect", client);

                pthread_rwlock_wrlock(&client->lock.status);
                if (client->status != CDClientDisconnect) {
                    client->status = CDClientIdle;
                }
                pthread_rwlock_unlock(&client->lock.status);

                CD_DestroyJob(self->job);

                if (CD_BufferLength(client->buffers->input) > 0) {
                    CD_ReadFromClient(client);
                }
            }
            else if (self->job->type == CDClientProcessJob) {
                CD_EventDispatch(self->server, "Client.process", client,
                    ((CDClientProcessJobData*) self->job->data)->packet);

                CD_EventDispatch(self->server, "Client.processed", client,
                    ((CDClientProcessJobData*) self->job->data)->packet);

                pthread_rwlock_wrlock(&client->lock.status);
                if (client->status != CDClientDisconnect) {
                    client->status = CDClientIdle;
                }

                client->jobs--;
                pthread_rwlock_unlock(&client->lock.status);

                CD_DestroyJob(self->job);

                if (CD_BufferLength(client->buffers->input) > 0) {
                    CD_ReadFromClient(client);
                }
            }
            else if (self->job->type == CDClientDisconnectJob) {
                while (true) {
                    pthread_rwlock_rdlock(&client->lock.status);

                    if (client->jobs < 1) {
                        pthread_rwlock_unlock(&client->lock.status);
                        break;
                    }

                    pthread_rwlock_unlock(&client->lock.status);
                }

                CD_EventDispatch(self->server, "Client.disconnect", client, (bool) ERROR(client));

                CD_ListPush(self->server->disconnecting, (CDPointer) client);

                CD_ServerFlush(client->server, false);

                CD_DestroyJob(self->job);
            }
        }

        self->job = NULL;
    }

    return true;
}
Example #24
0
static int suhosin_check_filename(char *s, int len TSRMLS_DC)
{
	char fname[MAXPATHLEN+1];
	char *t, *h, *h2, *index, *e;
	int tlen, i, count=0;
	uint indexlen;
	ulong numindex;
	zend_bool isOk;

	/* check if filename is too long */
	if (len > MAXPATHLEN) {
		return SUHOSIN_CODE_TYPE_LONGNAME;
	}
	memcpy(fname, s, len);
	fname[len] = 0; 
	s = (char *)&fname;
	e = s + len;

	/* check if ASCIIZ attack -> not working yet (and cannot work in PHP4 + ZO) */
	if (len != strlen(s)) {
		return SUHOSIN_CODE_TYPE_0FILE;
	}
	
	/* disallow uploaded files */
	if (SG(rfc1867_uploaded_files)) {
		if (zend_hash_exists(SG(rfc1867_uploaded_files), (char *) s, e-s+1)) {
			return SUHOSIN_CODE_TYPE_UPLOADED;
		}
	}
		
	/* count number of directory traversals */
	for (i=0; i < len-3; i++) {
		if (s[i] == '.' && s[i+1] == '.' && (s[i+2] == '/' || s[i+2] == '\\')) {
			count++;
			i+=2;
		}
	}
	if (SUHOSIN_G(executor_include_max_traversal) && SUHOSIN_G(executor_include_max_traversal)<=count) {
		return SUHOSIN_CODE_TYPE_MANYDOTS;
	}
	
SDEBUG("xxx %08x %08x",SUHOSIN_G(include_whitelist),SUHOSIN_G(include_blacklist));
	/* no black or whitelist then disallow all */
	if (SUHOSIN_G(include_whitelist)==NULL && SUHOSIN_G(include_blacklist)==NULL) {
		/* disallow all URLs */
		if (strstr(s, "://") != NULL || suhosin_strcasestr(s, "data:") != NULL) {
			return SUHOSIN_CODE_TYPE_BADURL;
		}
	} else 
	/* whitelist is stronger than blacklist */
	if (SUHOSIN_G(include_whitelist)) {
		
		do {
			isOk = 0;
			
			h = strstr(s, "://");
			h2 = suhosin_strcasestr(s, "data:");
			h2 = h2 == NULL ? NULL : h2 + 4;
			t = h = (h == NULL) ? h2 : ( (h2 == NULL) ? h : ( (h < h2) ? h : h2 ) );
			if (h == NULL) break;
							
			while (t > s && (isalnum(t[-1]) || t[-1]=='_' || t[-1]=='.')) {
				t--;
			}
			
			tlen = e-t;
			
			zend_hash_internal_pointer_reset(SUHOSIN_G(include_whitelist));
			do {
				int r = zend_hash_get_current_key_ex(SUHOSIN_G(include_whitelist), &index, &indexlen, &numindex, 0, NULL);
				
				if (r==HASH_KEY_NON_EXISTANT) {
					break;
				}
				if (r==HASH_KEY_IS_STRING) {
					if (h-t <= indexlen-1 && tlen>=indexlen-1) {
						if (strncasecmp(t, index, indexlen-1)==0) {
							isOk = 1;
							break;
						}
					}
				}
				
				zend_hash_move_forward(SUHOSIN_G(include_whitelist));
			} while (1);
			
			/* not found in whitelist */
			if (!isOk) {
				return SUHOSIN_CODE_TYPE_BADURL;
			}
			
			s = h + 1;
		} while (1);
	} else {
		
		do {
			int tlen;
			
			h = strstr(s, "://");
			h2 = suhosin_strcasestr(s, "data:");
			h2 = h2 == NULL ? NULL : h2 + 4;
			t = h = (h == NULL) ? h2 : ( (h2 == NULL) ? h : ( (h < h2) ? h : h2 ) );
			if (h == NULL) break;
							
			while (t > s && (isalnum(t[-1]) || t[-1]=='_' || t[-1]=='.')) {
				t--;
			}

			tlen = e-t;

			zend_hash_internal_pointer_reset(SUHOSIN_G(include_blacklist));
			do {
				int r = zend_hash_get_current_key_ex(SUHOSIN_G(include_blacklist), &index, &indexlen, &numindex, 0, NULL);

				if (r==HASH_KEY_NON_EXISTANT) {
					break;
				}
				if (r==HASH_KEY_IS_STRING) {
					if (h-t <= indexlen-1 && tlen>=indexlen-1) {
						if (strncasecmp(t, index, indexlen-1)==0) {
							return SUHOSIN_CODE_TYPE_BLACKURL;
						}
					}
				}
				
				zend_hash_move_forward(SUHOSIN_G(include_blacklist));
			} while (1);
			
			s = h + 1;
		} while (1);
	}

	/* disallow writable files */
	if (!SUHOSIN_G(executor_include_allow_writable_files)) {
	        /* protection against *REMOTE* attacks, potential
	           race condition of access() is irrelevant */
	        if (access(s, W_OK) == 0) {
                        return SUHOSIN_CODE_TYPE_WRITABLE;
	        }
	}

	return SUHOSIN_CODE_TYPE_GOODFILE;
}
Example #25
0
// Add message to the queue
int MulticastRecvQueue::put_message(const void *message, size_t length,
    uint32_t number)
{
  assert(length <= MAX_UDP_PACKET_SIZE);
  pthread_mutex_lock(&mutex);
#ifdef DETAILED_MULTICAST_DEBUG
  DEBUG("%u, %u, %u\n", last_num, first_num, n_messages);
#endif
  if (cyclic_greater(number, last_num)) {
    bool do_wake_reader = n_messages == 0 && number == last_num + 1;
    // Check space in the buffer
    if (cyclic_less_or_equal(first_num + buffer.size(), number)) {
      // Enlarge the buffer,
      unsigned element = first_num + buffer.size() - 1;
      if (number - first_num >= (unsigned)MAX_QUEUE_SIZE) {
        DEBUG("Maximum buffer size reached (%u, %u)\n", n_messages,
          number - first_num);
        pthread_mutex_unlock(&mutex);
        return -1;
      }
      while (element != number) {
        SDEBUG("Enlarge the buffer\n");
        buffer.push_back(new MessageRecord());
        ++element;
      }
    }

    // Add the skipped messages
    uint32_t num = last_num + 1;
    while (num != number) {
      buffer[n_messages]->length = 0;
      ++num;
      ++n_messages;
    }

    // Put the message into the buffer
    buffer[n_messages]->length = length;
    memcpy(buffer[n_messages]->message, message, length);
    ++n_messages;
    last_num = number;
    first_num = number - n_messages + 1;
#ifdef DETAILED_MULTICAST_DEBUG
    DEBUG("%u, %u, %u\n", last_num, first_num, n_messages);
#endif
    if (do_wake_reader) {
      pthread_cond_signal(&data_ready_cond);
    }
  } else {
    // Retransmission received
    if (cyclic_less(number, first_num) || n_messages == 0) {
      SDEBUG("Retransmission for an already processed packet received\n");
      pthread_mutex_unlock(&mutex);
      return 0;
    }
    if (buffer[0]->length == 0 && number == first_num) {
      // Wake the receiving process up
      pthread_cond_signal(&data_ready_cond);
    }
    if (buffer[number - first_num]->length == 0) {
      // Store message if it has been missed
      buffer[number - first_num]->length = length;
      memcpy(buffer[number - first_num]->message, message, length);
    }
  }
  pthread_mutex_unlock(&mutex);
  return 0;
}
Example #26
0
int	struct_hasfan_ext(int ch, ematrix *e, ematrix *ec, int tr, int lo, int fan) {
	ematrix		*ee, *eec;
	char		buf[1000];
	int		i,k,kk, st,tt1,tt2,tt,ttm=0, br, ret, lf,
			*fn=NULL,*fnm, fnstack[104];
	
	if (ec)  if (!ISREFMAT(ec) || REFMAT(ec)!=e || ISTRANSPM(e)!=ISTRANSPM(ec))
		{ PROGERROR("When using ec, it must refer to e in the same transpose state"); ec = NULL; }
	if (ec && tr>=0) { PROGERROR("When using ec, do not use tr>=0"); tr = -1; }
	if (fan>=0 && fan<3) { PROGERROR("What is fan of length %d <3 ??",fan); fan = 3; }
	if (lo<0)  lo = tr? COLSM(e)-1:ROWSM(e)-1;
	buf[0] = 0;  kk = 0;
#ifndef FASTPROG
	DEBUG(CURDLEV+(ch<0),"Looking for %d-fans in %p [%s] %dx%d (tr=%d, lo=%d%s)...\n",
			fan,e,EMNAME(e)?EMNAME(e):"",ROWSM(e),COLSM(e),tr,lo,ec?", ec":"");
	EMATDEBUGS(CURDLEV+1,e,"\t\tf\t");  if (ec) EMATDEBUGS(CURDLEV+1+(ch<0),ec,"\t\t\t-\t");
	if (ch>=0 && tr>=0 && IFRANDDEBUGLESS(555)) {	/* (debug-check for 3-connectivity without lo) */
		ee = ematrix_copy(e);  ematrix_remove_rc(ee,tr,lo);
		if (!struct_isconnected(ee,3))  {PROGERROR("wrong - not 3-connected without lo=%d",lo); EMATDEBUG(0,ee,"!!\t");}
		dispose_ematrix(ee); }
#endif
	if (fan>ROWSM(e)+COLSM(e))  return 0;
	if (ch>2) {
		OUTPUT("Looking for %d%s in the matroid [%s] %dx%d...\n",
			fan,fan<0?" the longest fan":"-fans",EMNAME(e)?EMNAME(e):"",ROWSM(e),COLSM(e));
		if (tr>=0 || ec)  DEBUG(0,"Do not call fan printing with tr=%d>=0 or ec=%p.\n",tr,ec);
		if (fan<0)  DEBUG(CURDLEV-3,"Do not call all fan printing with fan=%d<0 (max fan).\n",fan);
	}
	if (ROWSM(e)+COLSM(e)<50)  fn = fnstack;
	else  fn = MMALLOC((ROWSM(e)+COLSM(e)+2)*2*sizeof(fn[0]));
	fnm = fn+ROWSM(e)+COLSM(e)+2;
	if (tr<0) {		/* no last line for the fan given - trying everything */
		st = 0;  tt1 = 0;  tt2 = 1;
	} else {		/* the last fan line is given, also determines tt by 3-connectivity */
		st = 1;  tt1 = tt2 = tr? 1:0;
		fn[0] = tr? ROWSM(e)+lo:lo;
		DEBUG(CURDLEV+2,".. hasfan pre-determined %s fn[0] = %d, tt=%d\n",tr?"col":"row",lo,tt1);
	}
		/**
		 * We cycle all choices of k lines and starting tt values (triad 0/triangle 1),
		 * beginning with a choice of fn[st], where st and tt1,tt2 depend on the input.
		 * One choice is a row for <ROWSM and a column +ROWSM otherwise.
		 * We record the longest fan length in lf, and the fan itself in fnm[].
		 * If we look only for a fan longer than the given value, we stop immediately
		 * after we find it, otherwise we search through all fans to find the longest one.
		 * As we generate our choice, we test the consecutive triples for being
		 * triangles/triads (by tt).
		**/
	ret = lf = 0;
	for (tt=tt1; tt<=tt2 && !ret; tt+=(ret?0:1)) {
	  k = st;  fn[k] = -1;
	  while (k>=st && !ret) {
			/* the value of fn[k] is the current choice - row for <ROWSM, column+ROWSM otherwise */
		if (++fn[k]>=ROWSM(e)+COLSM(e)) {
			--k;  continue;		/* (no more choices at this level) */
		}
		for (i=0; i<k; i++)  if (fn[i]==fn[k])  break;
		if (i<k)  continue;		/* (if fn[k] was already chosen previously) */
		if (ec) {
			if (fn[k]<ROWSM(e))  for (i=ROWSM(ec)-1; i>=0 && GETREFMROW(ec,i)!=fn[k]; i--) ;
			else  for (i=COLSM(ec)-1; i>=0 && GETREFMCOL(ec,i)!=fn[k]-ROWSM(e); i--) ;
			if (i<0)  continue;	/* (if fn[k] does not belong to ec if given) */
		}
		DEBUG(CURDLEV+2,"%*s. hasfan(%d) trying choice %s fn[%d] = %d (%d) for %s\n",2*k,"",fan,
				fn[k]<ROWSM(e)?"row":"col",k,fn[k]<ROWSM(e)?fn[k]:fn[k]-ROWSM(e),fn[k]<ROWSM(e)?ROWSID(e,fn[k]):COLSID(e,fn[k]-ROWSM(e)),(k+tt)%2?"triang":"triad");
		
		if (k>=2) {	/* looking for a triangle ((k+tt)%2==1) or triad ((k+tt)%2==0) at this level */
			br = struct_hasfan_triax((ch<-3?-1:0),e,(k+tt)%2,fn[k-2],fn[k-1],fn[k],1);
			if (br<=0)  continue;	/* if there was no triaxx, then cycle other choices */
		}
		if (++k>lf) {			/* records the longest fan found so far */
			lf = k;  ttm = tt;
			for (i=0; i<k; i++)  fnm[i] = fn[i];
			DEBUG(CURDLEV+2,"-%*s. hasfan(%d) found longer = %d\n",2*k,"",fan,lf);
		}
		if (k<fan || fan<0) {		/* to the next choice of line */
			fn[k] = -1;  continue;
		}
		if (k>ROWSM(e)+COLSM(e))  {PROGERROREXIT("Out of index range looking for a fan");}
		fn[k] = 11111;			/* fan of given length found here, plus printing */
		if (ch>=2 || CURDLEV-1+(ch<0)<=printlev) {
			sprintf(buf,"fan: (%s+..) ",ttm?"triangle":"triad");
			for (i=0; i<lf; i++)  snprintf((buf[800]=0,buf+strlen(buf)),50,"%s%d(%d), ",
					fn[i]<ROWSM(e)?"r":"c",fn[i]<ROWSM(e)?fn[i]:fn[i]-ROWSM(e),fn[i]<ROWSM(e)?ROWSID(e,fn[i]):COLSID(e,fn[i]-ROWSM(e)));
		}
		if (ch>2)  OUTPUT("\t[%s]#%d %s\n",EMNAME(e)?EMNAME(e):"",++kk,buf);
		else  ret = 1;		/* (this breaks the cycle, unless all printing is required) */
	}}
		/**
		 * If fan>0, then the fans of this length are recorded above, and they are
		 * all printed out if ch>2 is requested.
		 * On the other hand, fan<0 the longest fan is printed out below, separately.
		 * The return value is the longest fan, or the requested fan length, or 0.
		**/
	if (fan<=0)  ret = (lf>=3? lf:0);
	else  ret = (lf>=fan? fan:0);
	if (fan<0) if (ch>=2 || CURDLEV-1+(ch<0)<=printlev) {
		sprintf(buf,"longest fan: (%s+..) ",ttm?"triangle":"triad");
		for (i=0; i<lf; i++)  snprintf((buf[800]=0,buf+strlen(buf)),50,"%s%d(%d), ",
				fnm[i]<ROWSM(e)?"r":"c",fnm[i]<ROWSM(e)?fnm[i]:fnm[i]-ROWSM(e),fnm[i]<ROWSM(e)?ROWSID(e,fnm[i]):COLSID(e,fnm[i]-ROWSM(e)));
	}
	if (ch==2 || (ch>=2 && fan<0))  OUTPUT("\t[%s] %s\n",EMNAME(e)?EMNAME(e):"",buf);
	ee = eec = NULL;
#ifndef FASTPROG
	DEBUG(CURDLEV-1+(!ret)+(ch<0),"- hasfan(%d) test for %p [%s] (l %d, tr=%d%s) found max %d  %s.\n",
			fan,e,EMNAME(e)?EMNAME(e):"",lo,tr,ec?", ec":"",lf,fan>0?"":(ret?"+HAS+":"NO fan"));
	SDEBUG(CURDLEV-1+(!ret)+(ch<0),"\t\t\t ->  %s\n",buf);
			/* (debug-testing the full-test for diff basis of e) */
	if (ch>=0 && tr<0 && IFRANDDEBUG(222)) {
		ee = ematrix_copy(e);  EMSETNAME(ee,"rec-test");
		for (eec=ec, tt=0; tt<5; tt++) {
			i = random()%ROWSM(ee);  k = random()%COLSM(ee);
			if (SIGNM(ee,i,k)==0)  continue;
			if (ec!=NULL) {	/* (not to interfere with the matrix ec if given) */
				for (tt1=ROWSM(ec)-1; tt1>=0 && GETREFMROW(ec,tt1)!=i; tt1--) ;
				for (tt2=COLSM(ec)-1; tt2>=0 && GETREFMCOL(ec,tt2)!=k; tt2--) ;
				if (tt1>=0 && tt2>=0)  ematrix_pivot(ee,i,k);
			} else  ematrix_pivot(ee,i,k);
		}
		if (ec) { eec = ematrix_refer_all(ec);  ematrix_rerefer(eec,ee); }
		else if (random()%2==1)  ematrix_transpose(ee);
		if (ret!=(kk=struct_hasfan_ext(-1,ee,eec,-1,-1,fan)))  {PROGERROR("The result must be the same after pivoting (transpose)! ret=%d != %d",ret,kk);}
		if (ec) dispose_ematrix(eec);  dispose_ematrix(ee);
	}
#endif
	if (fn && fn!=fnstack)  FREE(fn);
	return ret;
}
Example #27
0
int	struct_connorder_ext(ematrix *e, int tr, int *cor, int *cp, int *cxp, int **cadj) {
	int	i,ii,j,k, r,c, cornul=0, *ud,udstack[30];
	
	if (!tr)  ematrix_transpose(e);
	if (COLSM(e)<14)  ud = udstack;
	else  ud = MMALLOC((2*COLSM(e)+2)*sizeof(ud[0]));
	if (cxp && cor)  {PROGERROR("not allowed to use cxp[] with cor[] !!"); cxp=NULL;}
	if (cor==NULL) { cornul = 1;  cor = ud+COLSM(e); }
	for (j=0; j<COLSM(e); j++)  ud[j] = cor[j] = 0;
	if (cxp)  for (j=0; j<ROWSM(e); j++)  cxp[j] = 0;
	if (cadj)  for (i=0; i<COLSM(e); i++)
		for (ii=0; ii<COLSM(e); ii++)  cadj[i][ii] = -1;
		/**
		 * We simply search the columns of e, for each one looking at the rows it
		 * has nonzero, and adding other columns which have nonzeros in this row.
		 * ud[ii] marks columns that were already reached, starting from ud[0].
		 * If k>j happens, that means we ran out of connected columns to continue
		 * the search, and we start with the first next component.
		 * (This happens always in the first run.)
		**/
	j = -1;  c = 0;  r = 1;
	for (k=0; k<COLSM(e); k++) {
		if (k>j) {
			for (ii=0; ii<COLSM(e) && ud[ii]; ii++) ;
			if (ii>=COLSM(e) || k>j+1)  {PROGERROR("must find another component here!"); break;}
			cor[++j] = ii;  ud[ii] = ++c;
			if (k>0)  r = 0;		/* next component reached in the graph -> disconnected */
		}
		for (i=0; i<ROWSM(e); i++)
		  if (SIGNM(e,i,cor[k])!=0)
			for (ii=0; ii<COLSM(e); ii++)
			  if (SIGNM(e,i,ii)!=0 && ii!=cor[k]) {
				if (!ud[ii]) {		/* next column reached in the graph */
					cor[++j] = ii;  ud[ii] = c;
				}
				if (cadj)		/* record adjacency between the columns */
					cadj[cor[k]][ii] = cadj[ii][cor[k]] = i;
			}
		if (j+1>=COLSM(e) && !cadj)  break;
	}
		/**
		 * Additional data: Store component indices for the columns and the rows
		 * of (transposed?) matrix e.
		 * These are indexed in the same way as cor[] if given (only for cp[]),
		 * or by absolute matrix line indices otherwise.
		**/
	if (cp)  for (j=0; j<COLSM(e); j++) {
		if (!cornul)  cp[j] = ud[cor[j]];
		else  cp[j] = ud[j];
	}
	if (cxp)  for (i=0; i<ROWSM(e); i++) {
		for (j=0; j<COLSM(e) && !SIGNM(e,i,j); j++) ;
		if (j<COLSM(e))  cxp[i] = ud[j];
	}
#ifndef FASTPROG
	if (DEBUGLEV>=CURDLEV+2) {
		DEBUG(CURDLEV+2,"Found%s connected col order: ",r?"":" -NO-");
		for (ii=0; ii<COLSM(e); ii++)  SDEBUG(CURDLEV+2,"%d, ",cor[ii]);
		SDEBUG(CURDLEV+2,"\n");  EMATDEBUG(CURDLEV+4,e,"\t\t\t<\t");
	}
	if (cadj && DEBUGLEV>=CURDLEV+2) {
		EMATDEBUGS(CURDLEV+2,e,"\t\tconn\t");
		DEBUG(CURDLEV+2," - cadj[][] adjacencies (-1 for no adj):\n");
		for (i=0; i<ROWSM(e); i++)  for (j=0; j<COLSM(e); j++)
			SDEBUG(CURDLEV+2,"%s% d%c",j==0?"\t\t":"",cadj[i][j],j==COLSM(e)-1?'\n':'\t');
	}
	if (j+1>=COLSM(e) && IFRANDDEBUG(33))  for (ii=0; ii<COLSM(e); ii++)
		if (!ud[ii])  {PROGERROR("wrong computation of a connected order!");}
	if (j+1<COLSM(e) && IFRANDDEBUGLESS(333)) {
		for (i=0; i<COLSM(e); i++)  for (ii=i+1; ii<COLSM(e); ii++)
			if (ud[i]!=ud[ii])  for (j=0; j<ROWSM(e); j++)
				if (SIGNM(e,j,i)!=0 && SIGNM(e,j,ii)!=0)  {PROGERROR("wrong computation of a (dis-)connected order!");}
	}
#endif
	if (ud && ud!=udstack)  FREE(ud);
	if (!tr)  ematrix_transpose(e);
	return (r?1:-1);
}
Example #28
0
gpointer Scheduler::jobThreadCallback(Scheduler * scheduler) {
	XOJ_CHECK_TYPE_OBJ(scheduler, Scheduler);

	while (scheduler->threadRunning) {
		// lock the whole scheduler
		g_mutex_lock(scheduler->schedulerMutex);

		g_mutex_lock(scheduler->blockRenderMutex);
		bool onlyNoneRenderJobs = false;
		glong diff = 1000;
		if (scheduler->blockRenderZoomTime) {
			GTimeVal time;
			g_get_current_time(&time);

			diff = g_time_val_diff(scheduler->blockRenderZoomTime, &time);
			if(diff <= 0) {
				g_free(scheduler->blockRenderZoomTime);
				scheduler->blockRenderZoomTime = NULL;
			} else {
				onlyNoneRenderJobs = true;
			}
		}
		g_mutex_unlock(scheduler->blockRenderMutex);

		g_mutex_lock(scheduler->jobQueueMutex);
		bool hasOnlyRenderJobs = false;
		Job * job = scheduler->getNextJobUnlocked(onlyNoneRenderJobs, &hasOnlyRenderJobs);
		if(job != NULL) {
			hasOnlyRenderJobs = false;
		}

		SDEBUG("get job: %ld\n", (long)job);

		if (!job) {
			// unlock the whole scheduler
			g_mutex_unlock(scheduler->schedulerMutex);

			if(hasOnlyRenderJobs) {
				if(scheduler->jobRenderThreadTimerId) {
					g_source_remove(scheduler->jobRenderThreadTimerId);
				}
				scheduler->jobRenderThreadTimerId = g_timeout_add(diff, (GSourceFunc)jobRenderThreadTimer, scheduler);
			}

			g_cond_wait(scheduler->jobQueueCond, scheduler->jobQueueMutex);
			g_mutex_unlock(scheduler->jobQueueMutex);

			continue;
		}

		SDEBUG("do job: %ld\n", (long)job);

		g_mutex_unlock(scheduler->jobQueueMutex);

		g_mutex_lock(scheduler->jobRunningMutex);

		job->execute();

		job->unref();
		g_mutex_unlock(scheduler->jobRunningMutex);

		// unlock the whole scheduler
		g_mutex_unlock(scheduler->schedulerMutex);

		SDEBUG("next\n", NULL);
	}

	SDEBUG("finished\n", NULL);

	return NULL;
}
Example #29
0
PHP_SUHOSIN_API void suhosin_log(int loglevel, char *fmt, ...)
{
	int s, r, i=0, fd;
	long written, towrite;
	int getcaller=0;
	char *wbuf;
	struct timeval tv;
	time_t now;
	struct tm tm;
#if defined(AF_UNIX)
	struct sockaddr_un saun;
#endif
#ifdef PHP_WIN32
	LPTSTR strs[2];
	unsigned short etype;
	DWORD evid;
#endif
	char buf[5000];
	char error[5000];
	char *ip_address;
	char *fname;
	char *alertstring;
	int lineno;
	va_list ap;
	TSRMLS_FETCH();

#if PHP_VERSION_ID >= 50500
	getcaller = (loglevel & S_GETCALLER) == S_GETCALLER;
#endif
	/* remove the S_GETCALLER flag */
	loglevel = loglevel & ~S_GETCALLER;

	SDEBUG("(suhosin_log) loglevel: %d log_syslog: %u - log_sapi: %u - log_script: %u", loglevel, SUHOSIN_G(log_syslog), SUHOSIN_G(log_sapi), SUHOSIN_G(log_script));

	/* dump core if wanted */
	if (SUHOSIN_G(coredump) && loglevel == S_MEMORY) {
		volatile unsigned int *x = 0;
		volatile int y = *x;
	}
	
	if (SUHOSIN_G(log_use_x_forwarded_for)) {
		ip_address = suhosin_getenv("HTTP_X_FORWARDED_FOR", 20 TSRMLS_CC);
		if (ip_address == NULL) {
			ip_address = "X-FORWARDED-FOR not set";
		}
	} else {
		ip_address = suhosin_getenv("REMOTE_ADDR", 11 TSRMLS_CC);
		if (ip_address == NULL) {
			ip_address = "REMOTE_ADDR not set";
		}
	}
	
	
	va_start(ap, fmt);
	ap_php_vsnprintf(error, sizeof(error), fmt, ap);
	va_end(ap);
	while (error[i]) {
		if (error[i] < 32) error[i] = '.';
		i++;
	}
	
	if (SUHOSIN_G(simulation)) {
		alertstring = "ALERT-SIMULATION";
	} else {
		alertstring = "ALERT";
	}
	
	if (zend_is_executing(TSRMLS_C)) {
		zend_execute_data *exdata = EG(current_execute_data);
		if (exdata) {
			if (getcaller && exdata->prev_execute_data) {
				lineno = exdata->prev_execute_data->opline->lineno;
				fname = (char *)exdata->prev_execute_data->op_array->filename;									
			} else {
				lineno = exdata->opline->lineno;
				fname = (char *)exdata->op_array->filename;				
			}
		} else {
			lineno = zend_get_executed_lineno(TSRMLS_C);
			fname = (char *)zend_get_executed_filename(TSRMLS_C);
		}
		ap_php_snprintf(buf, sizeof(buf), "%s - %s (attacker '%s', file '%s', line %u)", alertstring, error, ip_address, fname, lineno);
	} else {
		fname = suhosin_getenv("SCRIPT_FILENAME", 15 TSRMLS_CC);
		if (fname==NULL) {
			fname = "unknown";
		}
		ap_php_snprintf(buf, sizeof(buf), "%s - %s (attacker '%s', file '%s')", alertstring, error, ip_address, fname);
	}
			
	/* Syslog-Logging disabled? */
	if (((SUHOSIN_G(log_syslog)|S_INTERNAL) & loglevel)==0) {
		goto log_file;
	}	
	
#if defined(AF_UNIX)
	ap_php_snprintf(error, sizeof(error), "<%u>suhosin[%u]: %s\n", (unsigned int)(SUHOSIN_G(log_syslog_facility)|SUHOSIN_G(log_syslog_priority)),getpid(),buf);

	s = socket(AF_UNIX, SOCK_DGRAM, 0);
	if (s == -1) {
		goto log_file;
	}
	
	memset(&saun, 0, sizeof(saun));
	saun.sun_family = AF_UNIX;
	strcpy(saun.sun_path, SYSLOG_PATH);
	/*saun.sun_len = sizeof(saun);*/
	
	r = connect(s, (struct sockaddr *)&saun, sizeof(saun));
	if (r) {
		close(s);
    		s = socket(AF_UNIX, SOCK_STREAM, 0);
		if (s == -1) {
			goto log_file;
		}
	
		memset(&saun, 0, sizeof(saun));
		saun.sun_family = AF_UNIX;
		strcpy(saun.sun_path, SYSLOG_PATH);
		/*saun.sun_len = sizeof(saun);*/

		r = connect(s, (struct sockaddr *)&saun, sizeof(saun));
		if (r) { 
			close(s);
			goto log_file;
		}
	}
	send(s, error, strlen(error), 0);
	
	close(s);
#endif
#ifdef PHP_WIN32
	ap_php_snprintf(error, sizeof(error), "suhosin[%u]: %s", getpid(),buf);

	switch (SUHOSIN_G(log_syslog_priority)) {			/* translate UNIX type into NT type */
		case 1: /*LOG_ALERT:*/
			etype = EVENTLOG_ERROR_TYPE;
			break;
		case 6: /*LOG_INFO:*/
			etype = EVENTLOG_INFORMATION_TYPE;
			break;
		default:
			etype = EVENTLOG_WARNING_TYPE;
	}
	evid = loglevel;
	strs[0] = error;
	/* report the event */
	if (log_source == NULL) {
		log_source = RegisterEventSource(NULL, "Suhosin-" SUHOSIN_EXT_VERSION);
	}
	ReportEvent(log_source, etype, (unsigned short) SUHOSIN_G(log_syslog_priority), evid, NULL, 1, 0, strs, NULL);
	
#endif
log_file:
	/* File-Logging disabled? */
	if ((SUHOSIN_G(log_file) & loglevel)==0) {
		goto log_sapi;
	}
	
	if (!SUHOSIN_G(log_filename) || !SUHOSIN_G(log_filename)[0]) {
		goto log_sapi;
	}
	fd = open(SUHOSIN_G(log_filename), O_CREAT|O_APPEND|O_WRONLY, 0640);
	if (fd == -1) {
	    suhosin_log(S_INTERNAL, "Unable to open logfile: %s", SUHOSIN_G(log_filename));
	    return;
	}

	gettimeofday(&tv, NULL);
	now = tv.tv_sec;
	php_gmtime_r(&now, &tm);
	ap_php_snprintf(error, sizeof(error), "%s %2d %02d:%02d:%02d [%u] %s\n", month_names[tm.tm_mon], tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, getpid(),buf);
	towrite = strlen(error);
	wbuf = error;
	php_flock(fd, LOCK_EX);
	while (towrite > 0) {
		written = write(fd, wbuf, towrite);
		if (written < 0) {
			break;
		}
		towrite -= written;
		wbuf += written;
	}
	php_flock(fd, LOCK_UN);
	close(fd);

log_sapi:
	/* SAPI Logging activated? */
	SDEBUG("(suhosin_log) log_syslog: %u - log_sapi: %u - log_script: %u - log_phpscript: %u", SUHOSIN_G(log_syslog), SUHOSIN_G(log_sapi), SUHOSIN_G(log_script), SUHOSIN_G(log_phpscript));
	if (((SUHOSIN_G(log_sapi)|S_INTERNAL) & loglevel)!=0) {
#if PHP_VERSION_ID < 50400
		sapi_module.log_message(buf);
#else
		sapi_module.log_message(buf TSRMLS_CC);
#endif
	}
	if ((SUHOSIN_G(log_stdout) & loglevel)!=0) {
		printf("%s\n", buf);
	}

/*log_script:*/
	/* script logging activaed? */
	if (((SUHOSIN_G(log_script) & loglevel)!=0) && SUHOSIN_G(log_scriptname)!=NULL) {
		char cmd[8192], *cmdpos, *bufpos;
		FILE *in;
		int space;
		struct stat st;
		
		char *sname = SUHOSIN_G(log_scriptname);
		while (isspace(*sname)) ++sname;
		if (*sname == 0) goto log_phpscript;
		
		if (VCWD_STAT(sname, &st) < 0) {
			suhosin_log(S_INTERNAL, "unable to find logging shell script %s - file dropped", sname);
			goto log_phpscript;
		}
		if (access(sname, X_OK|R_OK) < 0) {
			suhosin_log(S_INTERNAL, "logging shell script %s is not executable - file dropped", sname);
			goto log_phpscript;					
		}
		
		/* TODO: clean up this code to calculate size of output dynamically */
		ap_php_snprintf(cmd, sizeof(cmd) - 20, "%s %s \'", sname, loglevel2string(loglevel));
		space = sizeof(cmd) - strlen(cmd) - 20;
		cmdpos = cmd + strlen(cmd);
		bufpos = buf;
		if (space <= 1) return;
		while (space > 2 && *bufpos) {
			if (*bufpos == '\'') {
				if (space<=5) break;
				*cmdpos++ = '\'';
				*cmdpos++ = '\\';
				*cmdpos++ = '\'';
				*cmdpos++ = '\'';
				bufpos++;
				space-=4;
			} else {
				*cmdpos++ = *bufpos++;
				space--;
			}
		}
		*cmdpos++ = '\'';
		*cmdpos++ = ' ';
		*cmdpos++ = '2';
		*cmdpos++ = '>';
		*cmdpos++ = '&';
		*cmdpos++ = '1';
		*cmdpos = 0;
		
		if ((in=VCWD_POPEN(cmd, "r"))==NULL) {
			suhosin_log(S_INTERNAL, "Unable to execute logging shell script: %s", sname);
			goto log_phpscript;
		}
		/* read and forget the result */
		while (1) {
			int readbytes = fread(cmd, 1, sizeof(cmd), in);
			if (readbytes<=0) {
				break;
			}
			if (strncmp(cmd, "sh: ", 4) == 0) {
				/* assume this is an error */
				suhosin_log(S_INTERNAL, "Error while executing logging shell script: %s", sname);
				pclose(in);
				goto log_phpscript;
			}
		}
		pclose(in);
	}
log_phpscript:
	if ((SUHOSIN_G(log_phpscript) & loglevel)!=0 && EG(in_execution) && SUHOSIN_G(log_phpscriptname) && SUHOSIN_G(log_phpscriptname)[0]) {
		zend_file_handle file_handle;
		zend_op_array *new_op_array;
		zval *result = NULL;
		
		long orig_execution_depth = SUHOSIN_G(execution_depth);
#if PHP_VERSION_ID < 50400
		zend_bool orig_safe_mode = PG(safe_mode);
#endif
		char *orig_basedir = PG(open_basedir);
		
		char *phpscript = SUHOSIN_G(log_phpscriptname);
SDEBUG("scriptname %s", SUHOSIN_G(log_phpscriptname));				
#ifdef ZEND_ENGINE_2
		if (zend_stream_open(phpscript, &file_handle TSRMLS_CC) == SUCCESS) {
#else
		if (zend_open(phpscript, &file_handle) == SUCCESS && ZEND_IS_VALID_FILE_HANDLE(&file_handle)) {
			file_handle.filename = phpscript;
			file_handle.free_filename = 0;
#endif		
			if (!file_handle.opened_path) {
				file_handle.opened_path = estrndup(phpscript, strlen(phpscript));
			}
			new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE TSRMLS_CC);
			zend_destroy_file_handle(&file_handle TSRMLS_CC);
			if (new_op_array) {
				HashTable *active_symbol_table = EG(active_symbol_table);
				zval *zerror, *zerror_class;
				
				if (active_symbol_table == NULL) {
					active_symbol_table = &EG(symbol_table);
				}
				EG(return_value_ptr_ptr) = &result;
				EG(active_op_array) = new_op_array;
				
				MAKE_STD_ZVAL(zerror);
				MAKE_STD_ZVAL(zerror_class);
				ZVAL_STRING(zerror, buf, 1);
				ZVAL_LONG(zerror_class, loglevel);

				zend_hash_update(active_symbol_table, "SUHOSIN_ERROR", sizeof("SUHOSIN_ERROR"), (void **)&zerror, sizeof(zval *), NULL);
				zend_hash_update(active_symbol_table, "SUHOSIN_ERRORCLASS", sizeof("SUHOSIN_ERRORCLASS"), (void **)&zerror_class, sizeof(zval *), NULL);
				
				SUHOSIN_G(execution_depth) = 0;
				if (SUHOSIN_G(log_phpscript_is_safe)) {
#if PHP_VERSION_ID < 50400
					PG(safe_mode) = 0;
#endif
					PG(open_basedir) = NULL;
				}
				
				zend_execute(new_op_array TSRMLS_CC);
				
				SUHOSIN_G(execution_depth) = orig_execution_depth;
#if PHP_VERSION_ID < 50400				
				PG(safe_mode) = orig_safe_mode;
#endif
				PG(open_basedir) = orig_basedir;
				
#ifdef ZEND_ENGINE_2
				destroy_op_array(new_op_array TSRMLS_CC);
#else
				destroy_op_array(new_op_array);
#endif
				efree(new_op_array);
#ifdef ZEND_ENGINE_2
				if (!EG(exception))
#endif			
				{
					if (EG(return_value_ptr_ptr)) {
						zval_ptr_dtor(EG(return_value_ptr_ptr));
						EG(return_value_ptr_ptr) = NULL;
					}
				}
			} else {
				suhosin_log(S_INTERNAL, "Unable to execute logging PHP script: %s", SUHOSIN_G(log_phpscriptname));
				return;
			}
		} else {
			suhosin_log(S_INTERNAL, "Unable to execute logging PHP script: %s", SUHOSIN_G(log_phpscriptname));
			return;
		}
	}

}
Example #30
0
void PdbEngine::executeRunToLine(const ContextData &data)
{
    Q_UNUSED(data)
    SDEBUG("FIXME:  PdbEngine::runToLineExec()");
}