Esempio n. 1
0
int main(int argc,char **argv) 
{
	char *p;
	int len;

	p = vmlog_concat3("foo","","bar",&len);
	NOTNULL(p);
	IS(len,6);
	TRUE(strcmp(p,"foobar") == 0);

	p = vmlog_concat3("","","",&len);
	NOTNULL(p);
	IS(len,0);
	TRUE(strcmp(p,"") == 0);

	p = vmlog_concat3("This is a"," stupid ","test.",&len);
	NOTNULL(p);
	IS(len,strlen("This is a stupid test."));
	TRUE(strcmp(p,"This is a stupid test.") == 0);

	p = vmlog_concat4len("eins",2,"zwei",4,"drei",0,"vier",4,&len);
	NOTNULL(p);
	IS(len,10);
	TRUE(strcmp(p,"eizweivier") == 0);
	
	return 0;
}
Esempio n. 2
0
static void
eek_symbol_real_serialize (EekSerializable *self,
                           GVariantBuilder *builder)
{
    EekSymbolPrivate *priv = EEK_SYMBOL_GET_PRIVATE(self);
#define NOTNULL(s) ((s) != NULL ? (s) : "")
    g_variant_builder_add (builder, "s", NOTNULL(priv->name));
    g_variant_builder_add (builder, "s", NOTNULL(priv->label));
    g_variant_builder_add (builder, "u", priv->category);
    g_variant_builder_add (builder, "u", priv->modifier_mask);
    g_variant_builder_add (builder, "s", NOTNULL(priv->icon_name));
    g_variant_builder_add (builder, "s", NOTNULL(priv->tooltip));
#undef NOTNULL
}
Esempio n. 3
0
static
int32 mtx_cur_col_to_csr_slow(mtx_matrix_t mtx,
				    int32 col,
				    mtx_range_t *rng,
				    real64 *value,
				    int32 *index)
{
  struct element_t *elt;
  int32 *tocur;
  int32 cur;
  int i = 0;

  elt = mtx->hdr.col[mtx->perm.col.cur_to_org[col]];
  tocur = mtx->perm.row.org_to_cur;

  for( ; NOTNULL(elt); elt = elt->next.row ) {
    cur = tocur[elt->row];
    if (in_range(rng,cur)) {
      index[i] = cur;
      value[i] = elt->value;
      i++;
    }
  }
  return i;
}
Esempio n. 4
0
/* state change of children handled here */
static void sigchld_handler(int sig)
{
	pid_t child_pid;
	jobs **job;
	int status;

	/*
	 * There can be multiple SIGCHLD at once, not necessarily they will all be handled,
	 * so we reap all the children in non-blocking mode that takes care of the pending child
	 * whose SIGCHLD is not attended
	 */

	/* SIGCHLD should be blocked in critical section of modifying joblist */
	/* thy shall NOT pass */
	while ((child_pid = waitpid(-1, &status, WNOHANG|WUNTRACED|WCONTINUED)) > 0) {
		if (WIFEXITED(status)) {
			deljob(child_pid);
		}

		else if (WIFSIGNALED(status)) {
			job = getjob(child_pid, 0);
			if (NOTNULL(job)) {
				shell_printf(SHELLPRINT_CHKSS | SHELLPRINT_CHKTERM,
						TERMSTR_GREEN("SIGCHLD: ")"[%d] (%d) killed by signal %d\n",
						(*job)->jid, (*job)->pid[0], WTERMSIG(status));
				deljob(child_pid);
			}
		}

		else if (WIFSTOPPED(status)) {
			job = getjob(child_pid, 0);
			if (NOTNULL(job)) {
				(*job)->state = ST;
				shell_printf(SHELLPRINT_CHKSS | SHELLPRINT_CHKTERM,
						TERMSTR_GREEN("SIGCHLD : ")"[%d] (%d) stopped by signal %d\n",
						(*job)->jid, (*job)->pid[0], WSTOPSIG(status));
			}
		}

		else if (WIFCONTINUED(status)) {
			job = getjob(child_pid, 0);
			if (NOTNULL(job))
				(*job)->state = BG;
		}
	}
	/* thy shall pass */
}
Esempio n. 5
0
static Array *merge_and_count (Array *left, Array *right)
{
    NOTNULL(left);
    NOTNULL(right);
    
    Array *merged = NULL;
    uint64_t split_inversions = 0;
    size_t index_left = 0;
    size_t index_right = 0;
    size_t index_merged = 0;
    
    merged = array_new (left->h.length + right->h.length);
    
    while ((left->h.length - index_left) || (right->h.length - index_right))
    {
        if ((right->h.length - index_right) < 1)
        {
            merged->data [index_merged ++] = left->data [index_left ++];
        }
        else if ((left->h.length - index_left) < 1)
        {
            merged->data [index_merged ++] = right->data [index_right ++];
        }
        else if (left->data [index_left] < right->data [index_right])
        {
            merged->data [index_merged ++] = left->data [index_left ++];
        }
        else if (left->data [index_left] > right->data [index_right])
        {
            merged->data [index_merged ++] = right->data [index_right ++];
            
            split_inversions += left->h.length - index_left;
        }
        else
        {
            merged->data [index_merged ++] = left->data [index_left ++];
            merged->data [index_merged ++] = right->data [index_right ++];
        }
    }
    
    merged->h.inversions = split_inversions + left->h.inversions + right->h.inversions;
    
    array_free (left);
    array_free (right);
    
    return merged;
}
Esempio n. 6
0
PCollective CollectiveBuilder::build() {
  Collective* c = new Collective(NOTNULL(level), config, tribe, credit, name);
  for (auto& elem : creatures)
    c->addCreature(elem.creature, elem.traits);
  for (Vec2 v : squares)
    c->claimSquare(Position(v, level));
  return PCollective(c);
}
Esempio n. 7
0
Stopwatch *stopwatch_free (Stopwatch *stopwatch)
{
    NOTNULL(stopwatch);
    
    mem_free (stopwatch);
    
    return NULL;
}
Esempio n. 8
0
void stopwatch_start (Stopwatch *stopwatch)
{
    NOTNULL(stopwatch);
    
    int ret = 0;
    
    ret = gettimeofday (&stopwatch->start, NULL);
    
    assert(ret == 0);
}
Esempio n. 9
0
/* ctrl+c */
static void sigint_handler(int sig)
{
	jobs **job;

	job = get_fgjob();

	if (NOTNULL(job)) {
		if (kill(-(*job)->pid[0], SIGINT) < 0)
			ERR_EXIT("kill");
	}
}
Esempio n. 10
0
static uint64_t count_inversions (Vector *vector)
{
    NOTNULL(vector);
    NOTNULL(vector->numbers);
    
    Thread_context root_context = {0};
    uint64_t inversions = 0;
    
    root_context.length = vector->length;
    root_context.numbers = vector->numbers;
    
    sort_threaded (&root_context);
    
    NOTNULL(root_context.merged);
    
    inversions = root_context.merged->h.inversions;
    
    array_free (root_context.merged);
    
    return inversions;
}
Esempio n. 11
0
int MobileSvc::GetUserMobileBindInfo(const char* pUid, const char* jsonString, std::stringstream& out)
{
	JSON_PARSE_RETURN("[MobileSvc::GetUserMobileBindInfo]bad format:", jsonString, 1);

	char sql[1024];
	sprintf(sql, "SELECT T.USER_ID,T.mobile ,T.country, T.mobile_verified ,T2.LOCAL_BAL, t2.inter_bal FROM T00_USER T"\
		" LEFT OUTER JOIN t02_user_sms_bal T2 "\
		" ON T.USER_ID=T2.USER_ID"
		" WHERE T.USER_ID = '%s'", pUid);
	MySql *psql = CREATE_MYSQL;
	CHECK_MYSQL_STATUS(psql->Query(sql)&&psql->NextRow(), 3);

	const char* userid = psql->GetField("USER_ID");
	const char* telno = psql->GetField("mobile");
	const char* countryno = psql->GetField("country");
	const char* smsstatus = psql->GetField("mobile_verified");
	const char* smscount = psql->GetField("LOCAL_BAL");
	const char* inter = psql->GetField("inter_bal");

	out<<FormatString("{userid:\"%s\",smsstatus:%d,countryno:\"%s\",telno:\"%s\",nsms:%d}",
		NOTNULL(userid),
		atoi(NOTNULL(smsstatus)),
		NOTNULL(countryno),
		NOTNULL(telno),
		atoi(NOTNULL(smscount))+atoi(NOTNULL(inter)));

	RELEASE_MYSQL_RETURN(psql, 0);
}
Esempio n. 12
0
static void *sort_threaded (void *arg)
{
    NOTNULL(arg);
    
    Thread_context *context = (Thread_context *) arg;
    
    if ((context->depth >= THREAD_DEPTH) || (context->length < 1000))
    {
        context->merged = sort_recursive (context->length, context->numbers);
    }
    else
    {
        pthread_t thread_left = 0;
        pthread_t thread_right = 0;
        Thread_context context_left = {0};
        Thread_context context_right = {0};
        size_t length_left = 0;
        pthread_attr_t thread_attributes = {0};
        
        context_left.depth = context->depth + 1;
        context_right.depth = context->depth + 1;
        
        length_left = context->length / 2;
        
        context_left.length = length_left;
        context_left.numbers = context->numbers;
        
        context_right.length = context->length - length_left;
        context_right.numbers = context->numbers + length_left;
        
        pthread_attr_init (&thread_attributes);
        pthread_attr_setdetachstate (&thread_attributes, PTHREAD_CREATE_JOINABLE);
        
        pthread_create (&thread_left, &thread_attributes, sort_threaded, &context_left);
        pthread_create (&thread_right, &thread_attributes, sort_threaded, &context_right);
        
        pthread_attr_destroy (&thread_attributes);
        
        pthread_join (thread_left, NULL);
        pthread_join (thread_right, NULL);
        
        context->merged = merge_and_count (context_left.merged, context_right.merged);
    }
    
    if (context->depth)
    {
        pthread_exit (NULL);
    }
    
    return NULL;
}
Esempio n. 13
0
/* removes job from the joblist by pid,
 * silently returns if job absent */
void deljob(pid_t pid)
{
	jobs **job, *target;

	job = getjob(pid, 0);

	/* getjob can return (job **)NULL or &(job *)NULL */
	if (NOTNULL(job)) {
		target = *job;
		/* order is IMPORTANT, we dont want to free neighbour's next
		 * so update neighbour first then kill the target */
		*job = (*job)->next;
		free(target);
	}
}
Esempio n. 14
0
/*
 * the basic wait for foreground used by fg cmd and basic
 * non bg cmd in the shell. Make sure SIGCHLD is blocked
 * to avoid race conditions that make the joblist unreliable.
 * No terminal control or printing if subshell
 * */
void wait_fg(jobs **job)
{
	int status, i;

	/* thy shall NOT pass */

	for (i=0; NOTNULL(job); i++) {
		if (!subshell_flag && tcsetpgrp(TERMFD, (*job)->pid[0]) < 0)
			perror("tcsetpgrp");
		while (waitpid((*job)->pid[i], &status, WUNTRACED) == 0)
			;

		if (WIFEXITED(status)) {
			if (!subshell_flag && tcsetpgrp(TERMFD, getpid()) < 0)
				perror("tcsetpgrp");
			if ((*job)->pid[i+1] == 0) {
				deljob((*job)->pid[0]);
				break;
			}
		}

		else if (WIFSIGNALED(status)) {
			if (!subshell_flag && tcsetpgrp(TERMFD, getpid()) < 0)
				perror("tcsetpgrp");
			shell_printf(SHELLPRINT_CHKSS | SHELLPRINT_CHKTERM,
					"[%d] (%d) killed by signal %d\n", (*job)->jid, (*job)->pid[0],
					WTERMSIG(status));
			deljob((*job)->pid[0]);
			break;
		}

		else if (WIFSTOPPED(status)) {
			if (!subshell_flag && tcsetpgrp(TERMFD, getpid()) < 0)
				perror("tcsetpgrp");
			shell_printf(SHELLPRINT_CHKSS | SHELLPRINT_CHKTERM,
					"[%d] (%d) stopped by signal %d\n", (*job)->jid,
					(*job)->pid[0], WSTOPSIG(status));
			(*job)->state = ST;
			break;
		}
	}
	/* thy shall pass */
}
Esempio n. 15
0
/* what >bg and >fg run */
void do_bgfg(char **cmd, int state)
{
	jobs **job;
	sigset_t msk;

	MASK_SIG(SIG_BLOCK, SIGCHLD, msk);

	if (!cmd[1]) {
		job = get_lastjob();
	}
	else if (*cmd[1]=='%' && atoi(cmd[1]+1)) {
		job = getjob(0, atoi(cmd[1]+1));
	}
	else {
		ERRMSG("Invalid argument\n");
		return;
	}

	/* thy shall NOT pass */

	if (NOTNULL(job)) {
		(*job)->state = state;

		if (kill(-(*job)->pid[0], SIGCONT) < 0)
			ERR_EXIT("kill");

		if (state == BG) {
			shell_printf(SHELLPRINT_CHKSS | SHELLPRINT_CHKTERM,
					"[%d] (%d) %s\n", (*job)->jid, (*job)->pid[0], (*job)->cmdline);
		}
		else {
			shell_printf(SHELLPRINT_CHKSS | SHELLPRINT_CHKTERM,
					"%s\n", (*job)->cmdline);
			wait_fg(job);
		}
	}
	else {
		ERRMSG("Invalid job\n");
	}

	/* thy shall pass */
	MASK_SIG(SIG_UNBLOCK, SIGCHLD, msk);
}
Esempio n. 16
0
uint64_t stopwatch_stop (Stopwatch *stopwatch)
{
    NOTNULL(stopwatch);
    
    int ret = 0;
    uint64_t usec_start = 0;
    uint64_t usec_finish = 0;
    
    ret = gettimeofday (&stopwatch->finish, NULL);
    
    assert(ret == 0);
    
    usec_start = (((uint64_t) stopwatch->start.tv_sec) * 1000000LL + stopwatch->start.tv_usec);
    usec_finish = (((uint64_t) stopwatch->finish.tv_sec) * 1000000LL + stopwatch->finish.tv_usec);
    
    stopwatch->elapsed = (usec_finish - usec_start) / 1000;
    stopwatch->usec = (usec_finish - usec_start) % 1000;
    
    return stopwatch->elapsed;
}
Esempio n. 17
0
static
int32 mtx_cur_row_to_csr(mtx_matrix_t mtx,
			       int32 row,
			       real64 *value,
			       int32 *index)
{
  struct element_t *elt;
  int32 *tocur;
  int i = 0;

  tocur = mtx->perm.col.org_to_cur;
  elt = mtx->hdr.row[mtx->perm.row.cur_to_org[row]];

  for( ; NOTNULL(elt); elt = elt->next.col) {
    index[i] = tocur[elt->col];
    value[i] = elt->value;
    i++;
  }
  return i;
}
Esempio n. 18
0
static Array *sort_recursive (size_t length, uint32_t *numbers)
{
    NOTNULL(numbers);
    
    Array *sorted = NULL;
    
    if (length > 2)
    {
        size_t length_left = length / 2;
        
        sorted = merge_and_count (sort_recursive (length_left, numbers),
                                  sort_recursive (length - length_left, numbers + length_left));
    }
    else if (length == 2)
    {
        sorted = array_new (2);
        
        if (numbers [0] < numbers [1])
        {
            sorted->data [0] = numbers [0];
            sorted->data [1] = numbers [1];
        }
        else
        {
            sorted->data [0] = numbers [1];
            sorted->data [1] = numbers [0];
            
            sorted->h.inversions = 1;
        }
    }
    else if (length == 1)
    {
        sorted = array_new (1);
        
        sorted->data [0] = numbers [0];
    }
        
    return sorted;
}
Esempio n. 19
0
static int send_policychange_request(am_net_t *conn, char **token, const char *notifyurl) {
    static const char *thisfunc = "send_policychange_request():";
    size_t post_sz, post_data_sz;
    char *post = NULL, *post_data = NULL;
    int status = AM_ERROR;
    struct request_data *req_data;

    if (conn == NULL || conn->data == NULL || token == NULL ||
            !ISVALID(*token)) return AM_EINVAL;

    req_data = (struct request_data *) conn->data;

    post_data_sz = am_asprintf(&post_data,
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            "<RequestSet vers=\"1.0\" svcid=\"Policy\" reqid=\"1\">"
            "<Request><![CDATA["
            "<PolicyService version=\"1.0\">"
            "<PolicyRequest requestId=\"1\" appSSOToken=\"%s\">"
            "<RemovePolicyListener notificationURL=\"%s\" serviceName=\"iPlanetAMWebAgentService\"/>"
            "</PolicyRequest>"
            "</PolicyService>]]>"
            "</Request>"
            "<Request><![CDATA["
            "<PolicyService version=\"1.0\">"
            "<PolicyRequest requestId=\"2\" appSSOToken=\"%s\">"
            "<AddPolicyListener notificationURL=\"%s\" serviceName=\"iPlanetAMWebAgentService\"/>"
            "</PolicyRequest>"
            "</PolicyService>]]>"
            "</Request>"
            "</RequestSet>",
            *token, NOTNULL(notifyurl), *token, NOTNULL(notifyurl));
    if (post_data == NULL) return AM_ENOMEM;

    post_sz = am_asprintf(&post, "POST %s/policyservice HTTP/1.1\r\n"
            "Host: %s:%d\r\n"
            "User-Agent: "MODINFO"\r\n"
            "Accept: text/xml\r\n"
            "Connection: Close\r\n"
            "Content-Type: text/xml; charset=UTF-8\r\n"
            "%s"
            "Content-Length: %d\r\n\r\n"
            "%s", conn->uv.path, conn->uv.host, conn->uv.port,
            NOTNULL(conn->req_headers), post_data_sz, post_data);
    if (post == NULL) {
        free(post_data);
        return AM_ENOMEM;
    }

#ifdef DEBUG
    AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes:\n%s", thisfunc, post_sz, post);
#else
    AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes", thisfunc, post_sz);
#endif
    if (conn->log != NULL) {
#ifdef DEBUG
        conn->log("%s sending %d bytes:\n%s", thisfunc, post_sz, post);
#else
        conn->log("%s sending %d bytes", thisfunc, post_sz);
#endif                
    }

    status = am_net_write(conn, post, post_sz);
    free(post_data);
    free(post);

    if (status == AM_SUCCESS) {
        wait_for_event(req_data->event, 0);
    }

    AM_LOG_DEBUG(conn->instance_id, "%s authenticate response status code: %d\n%s",
            thisfunc, conn->http_status, LOGEMPTY(req_data->data));
    if (conn->log != NULL) {
        conn->log("%s authenticate response status code: %d\n%s", thisfunc,
                conn->http_status, LOGEMPTY(req_data->data));
    }

    AM_LOG_DEBUG(conn->instance_id, "%s status: %s", thisfunc, am_strerror(status));
    am_free(req_data->data);
    req_data->data = NULL;
    return status;
}
Esempio n. 20
0
static
void mtx_eliminate_row2(mtx_matrix_t mtx,
			mtx_matrix_t upper_mtx,
			mtx_range_t *rng,
			int32 row,
			real64 *vec,
			real64 *pivots,
			int32 *inserted,
			mem_store_t eltbuffer)
{
  struct element_t *elt;
  struct mtx_linklist *diag, *right=NULL, *ptr;
  int32 *tocur;
  real64 multiplier;
  int k, j;
  mtx_coord_t nz;

  (void)rng;  /*  stop gcc whine about unused parameter  */

  /*
   * Move all non-zeros from current row to full array.
   * The full array would have been initialized before,
   * we must put it back in the clean state when we leave.
   * All operations are done over mtx_ALL_COLS.
   */
  /*
   * we use the following code fragment instead of :
   * 	mtx_cur_row_vec(mtx,row,vec,mtx_ALL_COLS);
   * so that we can put the elements in the correct place.
   */

  diag = (struct mtx_linklist *)mem_get_element(eltbuffer);
  diag->index = row;
  diag->prev = NULL;
  inserted[row] = 1;

  /*
   * the insertion for this phase.
   */
  tocur = mtx->perm.col.org_to_cur;
  elt = mtx->hdr.row[mtx->perm.row.cur_to_org[row]];
  ptr = diag;
  for ( ;NOTNULL(elt); elt = elt->next.col) {
    if (elt->value == 0.0) {
      continue;			/* hard zeros */
    }
    k = tocur[elt->col];
    vec[k] = elt->value;
    if (k < row) {		/* the less than is critical */
      (void)insert_link(diag,k,eltbuffer);
      inserted[k] = 1;
    }
    else if (k > row) {
      right = add_link(right,k,eltbuffer);
      inserted[k] = 1;
    }
    else
      continue;
  }

  mtx_clear_row(mtx,row,mtx_ALL_COLS);

  /* we shuold be trapping for these 0 multipliers before. !!! */

  for (ptr = diag->prev; NOTNULL(ptr); ) {
    k = ptr->index;
    multiplier = vec[k]/pivots[k];
    if (multiplier==D_ZERO) {
      ptr = ptr->prev;
      /* FPRINTF(stderr,"0 multiplier found at %d\n",k); */
      continue;
    }
#ifdef NOP_DEBUG
    mtx_number_ops++;
#endif /* NOP_DEBUG */
    elt = mtx->hdr.row[mtx->perm.row.cur_to_org[k]];
    for ( ;NOTNULL(elt); elt = elt->next.col) {
      j = tocur[elt->col];
      if (!inserted[j]) {
	if (j < k)
	  (void)insert_link(ptr,j,eltbuffer);
	else
	  right = add_link(right,j,eltbuffer);
	inserted[j] = 1;
      }
      vec[j] = vec[j] - multiplier * elt->value;
#ifdef NOP_DEBUG
    mtx_number_ops++;
#endif /* NOP_DEBUG */
    }
    vec[k] = multiplier;	/* backpatch multiplier */
    ptr = ptr->prev;
  }

  /*
   * Map the data back to the appropriate matrices.
   */

  /*
   * Fill up the upper_matrix with the multipliers.
   */
  nz.row = row;
  for (ptr = diag->prev; NOTNULL(ptr); ptr = ptr->prev) {
    nz.col = ptr->index;
    if (vec[nz.col] != D_ZERO) {		/* dont fill hard 0's */
      mtx_fill_value(upper_mtx,&nz,vec[nz.col]);
    }
    vec[nz.col] = D_ZERO;
    inserted[nz.col] = 0;
  }

  /*
   * Fill the diagonal back to the regular matrix.
   */
  nz.col = row;
  if (vec[nz.col] != D_ZERO) {			/* dont fill hard 0's */
    mtx_fill_value(mtx,&nz,vec[nz.col]);
  }
  vec[row] = D_ZERO;
  inserted[row] = 0;

  /*
   * Fill the lower matrix with the stuff to the right of
   * diagonal.
   */
  for (ptr = right; NOTNULL(ptr); ptr = ptr->prev) {
    nz.col = ptr->index;
    if (fabs(vec[nz.col]) > 1.0e-16) {	/* THIS NEEDS A DROP TOL DEFINE */
      mtx_fill_value(mtx,&nz,vec[nz.col]);
    }
    vec[nz.col] = D_ZERO;
    inserted[nz.col] = 0;
  }
}
Esempio n. 21
0
void mtx_householder_transform_region(mtx_matrix_t mtx,
                                      const real64 coef,
                                      const mtx_sparse_t *sp,
                                      const mtx_region_t *reg,
                                      real64 droptol,
                                      boolean transpose)
{
  int32 *ctoorg;
  struct element_t *elt;
  real64 u,mult;
  int32 ku, kr, numcols, kcol;
  register int32 org;

  /* the following are reuseable buffers we must zero before releasing */
  char *mv;               /* mark buffer, should we need it, droptol */
  struct element_t **ev;  /* elt buffer for row addition */
  real64 *hrow;     /* u^T . A */
  int32 *irow;      /* list of nonzeros in hrow */

#if MTX_DEBUG
  if(!mtx_check_matrix(mtx)) return;
#endif

  if (coef==D_ZERO) return; /* adding 0 rather silly */
  if (reg==mtx_ENTIRE_MATRIX ||
      reg->col.low > reg->col.high || reg->row.low > reg->row.high) {
    FPRINTF(g_mtxerr,"Error: (mtx.c) Bogus Householder region given.\n");
    return;
  }
  if (sp==NULL) {
    FPRINTF(g_mtxerr,"Error: (mtx.c) Bogus Householder u given.\n");
    return;
  }
  if (sp->len == 0) return; /* I - k00t = I */
  if (ISNULL(sp->idata) || ISNULL(sp->data)) {
    FPRINTF(g_mtxerr,"Error: (mtx.c) Bogus Householder u data given.\n");
    return;
  }
  if (droptol != D_ZERO || transpose) {
    FPRINTF(g_mtxerr,
      "Error: (mtx.c) Householder droptol and transpose not done.\n");
    return;
  }
  mv = mtx_null_mark(mtx->order);
  if (ISNULL(mv)) {
    FPRINTF(g_mtxerr,"Error: (mtx.c) Householder. Insufficient memory.\n");
    return;
  }
  ev = mtx_null_vector(mtx->order);
  if (ISNULL(ev)) {
    FPRINTF(g_mtxerr,"Error: (mtx.c) Householder. Insufficient memory.\n");
    mtx_null_mark_release();
    return;
  }
  hrow = mtx_null_sum(mtx->order);
  if (ISNULL(hrow)) {
    FPRINTF(g_mtxerr,"Error: (mtx.c) Householder. Insufficient memory.\n");
    mtx_null_mark_release();
    mtx_null_vector_release();
    return;
  }
  irow = mtx_null_index(reg->col.high - reg->col.low +1);
  if (ISNULL(irow)) {
    FPRINTF(g_mtxerr,"Error: (mtx.c) Householder. Insufficient memory.\n");
    mtx_null_mark_release();
    mtx_null_vector_release();
    mtx_null_sum_release();
    return;
  }
  /* are we happy yet? ! */

  ctoorg = mtx->perm.col.cur_to_org;

  /* accumulate the dot products for the stuff in the region.no range check! */
  /* in I- tau u u^T . A this is hrow=u^T.A. idata[ku] is an org row index. */
  for (ku=0; ku < sp->len; ku++) {
    u = sp->data[ku];
    if (u != D_ZERO) {
      elt = mtx->hdr.row[sp->idata[ku]];
      while (NOTNULL(elt)) {
        hrow[elt->col] += u*elt->value; /* 15% */
        elt = elt->next.col;            /* 4% */
      }
    }
  }
  /* accumulate the indices needed to drive zeroing */
  kr = 0;
  for (ku = reg->col.low; ku <= reg->col.high; ku++) {
    org = ctoorg[ku];
    if (hrow[org]!=D_ZERO) {
      irow[kr] = org; /* collect index */
      ev[org] = DUMELT; /* init elt array with bogus ptr */
      kr++;
    }
  }
  /* irow 0..kr-1 now has the org col indexes of nonzero elements in hrow,ev */
  numcols = kr;
  /* now add hh transform to rows of A in u, cases with and without coef = 1 */
  if (coef == D_ONE) {
    for (ku=0; ku < sp->len; ku++) {
      if (sp->data[ku] != D_ZERO) {
        mult = -sp->data[ku];
        org = sp->idata[ku];
        /* expand row of interest into locations of interest */
        elt = mtx->hdr.row[org];
        while (NOTNULL(elt)) {
          if (NOTNULL(ev[elt->col])) ev[elt->col] = elt;   /* 11% */
          elt = elt->next.col;                             /* 4% */
        }
        /* run through irow doing the math (finally) */
        for (kr=0; kr < numcols; kr++) {
          kcol = irow[kr];                             /* 2 */
          if (ev[kcol] > DUMELT) {                     /* 12% */
            ev[kcol]->value += mult*hrow[kcol];        /* 14% */
            ev[kcol] = DUMELT;                         /* 9% */
            /* reinit ev col */
          } else {
            mtx_create_element_value(mtx, org, kcol, mult*hrow[kcol]); /*6*/
            /* let ev[irow[kr]] col stay DUMELT */
          }
        }
      }
    }
  } else {
    for (ku=0; ku < sp->len; ku++) {
      mult = -sp->data[ku]*coef;
      if (mult != D_ZERO) {
        org = sp->idata[ku];
        /* expand row of interest into locations of interest */
        elt = mtx->hdr.row[org];
        while (NOTNULL(elt)) {
          if (NOTNULL(ev[elt->col])) ev[elt->col] = elt;
          elt = elt->next.col;
        }
        /* run through irow doing the math (finally) */
        for (kr=0; kr < numcols; kr++) {
          kcol = irow[kr];
          if (ev[kcol] > DUMELT) {
            ev[kcol]->value += mult*hrow[kcol];
            ev[kcol] = DUMELT;
            /* reinit ev col */
          } else {
            mtx_create_element_value(mtx, org, kcol, mult*hrow[kcol]);
            /* let ev[irow[kr]] col stay DUMELT */
          }
        }
      }
    }
  }
  /* end case coef != 1 */
  for (kr=0; kr < numcols; kr++) {
    ev[irow[kr]] = NULL;
    hrow[irow[kr]] = D_ZERO;
    irow[kr] = 0;
  }
  /* pack up and go home */
  mtx_null_mark_release();
  mtx_null_vector_release();
  mtx_null_sum_release();
  mtx_null_index_release();
  return;
}
Esempio n. 22
0
void Level::Builder::putCreature(Vec2 pos, PCreature creature) {
  creature->setPosition(transform(pos));
  creatures.push_back(NOTNULL(std::move(creature)));
}
Esempio n. 23
0
static int send_attribute_request(am_net_t *conn, char **token, char **pxml, size_t *pxsz,
        const char *user, const char *realm) {
    static const char *thisfunc = "send_attribute_request():";
    size_t post_sz;
    char *post = NULL;
    int status = AM_ERROR;
    struct request_data *req_data;
    char *token_enc;
    char *realm_enc = url_encode(realm);
    char *user_enc = url_encode(user);

    if (conn == NULL || conn->data == NULL || token == NULL ||
            !ISVALID(*token) || !ISVALID(realm) || !ISVALID(user)) return AM_EINVAL;

    token_enc = url_encode(*token);
    req_data = (struct request_data *) conn->data;

    post_sz = am_asprintf(&post, "GET %s/identity/xml/read?"
            "name=%s&attributes_names=realm&attributes_values_realm=%s&attributes_names=objecttype"
            "&attributes_values_objecttype=Agent&admin=%s HTTP/1.1\r\n"
            "Host: %s:%d\r\n"
            "User-Agent: "MODINFO"\r\n"
            "Accept: text/xml\r\n"
            "%s"
            "Connection: Keep-Alive\r\n\r\n",
            conn->uv.path,
            user_enc, realm_enc, token_enc,
            conn->uv.host, conn->uv.port, NOTNULL(conn->req_headers));
    if (post == NULL) {
        AM_FREE(realm_enc, user_enc, token_enc);
        return AM_ENOMEM;
    }

#ifdef DEBUG
    AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes:\n%s", thisfunc, post_sz, post);
#else
    AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes", thisfunc, post_sz);
#endif
    if (conn->log != NULL) {
#ifdef DEBUG
        conn->log("%s sending %d bytes:\n%s", thisfunc, post_sz, post);
#else
        conn->log("%s sending %d bytes", thisfunc, post_sz);
#endif                
    }

    status = am_net_write(conn, post, post_sz);
    free(post);

    if (status == AM_SUCCESS) {
        wait_for_event(req_data->event, 0);
    }

    AM_LOG_DEBUG(conn->instance_id, "%s response status code: %d\n%s",
            thisfunc, conn->http_status, LOGEMPTY(req_data->data));
    if (conn->log != NULL) {
        conn->log("%s response status code: %d\n%s", thisfunc,
                conn->http_status, LOGEMPTY(req_data->data));
    }

    if (status == AM_SUCCESS && conn->http_status == 200 && ISVALID(req_data->data)) {
        if (stristr(req_data->data, "exception") != NULL) {
            status = AM_ERROR;
        } else {
            if (pxml != NULL) {
                *pxml = malloc(req_data->data_size + 1);
                if (*pxml != NULL) {
                    memcpy(*pxml, req_data->data, req_data->data_size);
                    (*pxml)[req_data->data_size] = 0;
                } else {
                    status = AM_ENOMEM;
                }
            }
            if (pxsz != NULL) *pxsz = req_data->data_size;
        }
    }

    AM_LOG_DEBUG(conn->instance_id, "%s status: %s", thisfunc, am_strerror(status));
    AM_FREE(req_data->data, realm_enc, user_enc, token_enc);
    req_data->data = NULL;
    return status;
}
Esempio n. 24
0
static int send_session_request(am_net_t *conn, char **token, const char *notifyurl,
        struct am_namevalue **session_list) {
    static const char *thisfunc = "send_session_request():";
    size_t post_sz, post_data_sz, token_sz;
    char *post = NULL, *post_data = NULL, *token_in = NULL, *token_b64;
    int status = AM_ERROR;
    struct request_data *req_data;

    if (conn == NULL || conn->data == NULL || token == NULL ||
            !ISVALID(*token)) return AM_EINVAL;

    token_sz = am_asprintf(&token_in, "token:%s", *token);
    token_b64 = base64_encode(token_in, &token_sz);

    req_data = (struct request_data *) conn->data;

    post_data_sz = am_asprintf(&post_data,
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            "<RequestSet vers=\"1.0\" svcid=\"Session\" reqid=\"0\">"
            "<Request><![CDATA["
            "<SessionRequest vers=\"1.0\" reqid=\"1\" requester=\"%s\">"
            "<GetSession reset=\"true\">"
            "<SessionID>%s</SessionID>"
            "</GetSession>"
            "</SessionRequest>]]>"
            "</Request>"
            "<Request><![CDATA["
            "<SessionRequest vers=\"1.0\" reqid=\"2\" requester=\"%s\">"
            "<AddSessionListener>"
            "<URL>%s</URL>"
            "<SessionID>%s</SessionID>"
            "</AddSessionListener>"
            "</SessionRequest>]]>"
            "</Request>"
            "</RequestSet>",
            NOTNULL(token_b64), *token, NOTNULL(token_b64), notifyurl, *token);
    if (post_data == NULL) {
        AM_FREE(token_b64, token_in);
        return AM_ENOMEM;
    }

    post_sz = am_asprintf(&post, "POST %s/sessionservice HTTP/1.1\r\n"
            "Host: %s:%d\r\n"
            "User-Agent: "MODINFO"\r\n"
            "Accept: text/xml\r\n"
            "Connection: Keep-Alive\r\n"
            "Content-Type: text/xml; charset=UTF-8\r\n"
            "%s"
            "Content-Length: %d\r\n\r\n"
            "%s", conn->uv.path, conn->uv.host, conn->uv.port,
            NOTNULL(conn->req_headers), post_data_sz, post_data);
    if (post == NULL) {
        AM_FREE(post_data, token_b64, token_in);
        return AM_ENOMEM;
    }

#ifdef DEBUG
    AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes:\n%s", thisfunc, post_sz, post);
#else
    AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes", thisfunc, post_sz);
#endif
    if (conn->log != NULL) {
#ifdef DEBUG
        conn->log("%s sending %d bytes:\n%s", thisfunc, post_sz, post);
#else
        conn->log("%s sending %d bytes", thisfunc, post_sz);
#endif                
    }

    status = am_net_write(conn, post, post_sz);
    AM_FREE(post, post_data, token_b64, token_in);

    if (status == AM_SUCCESS) {
        wait_for_event(req_data->event, 0);
    }

    AM_LOG_DEBUG(conn->instance_id, "%s response status code: %d\n%s",
            thisfunc, conn->http_status, LOGEMPTY(req_data->data));
    if (conn->log != NULL) {
        conn->log("%s response status code: %d\n%s", thisfunc,
                conn->http_status, LOGEMPTY(req_data->data));
    }

    if (status == AM_SUCCESS && conn->http_status == 200 && ISVALID(req_data->data)) {
        if (session_list != NULL) {
            *session_list = am_parse_session_xml(conn->instance_id, req_data->data, req_data->data_size);
        }
    }

    AM_LOG_DEBUG(conn->instance_id, "%s status: %s", thisfunc, am_strerror(status));
    am_free(req_data->data);
    req_data->data = NULL;
    return status;
}
Esempio n. 25
0
int am_agent_session_request(unsigned long instance_id, const char *openam,
        const char *token, const char *user_token, const char *notif_url) {
    char *post = NULL, *post_data = NULL;
    am_net_t n;
    size_t post_sz;
    int status = AM_ERROR;

    struct request_data ld;

    if (!ISVALID(token) || !ISVALID(user_token) ||
            !ISVALID(openam) || !ISVALID(notif_url)) return AM_EINVAL;

    memset(&ld, 0, sizeof(struct request_data));

    memset(&n, 0, sizeof(am_net_t));
    n.instance_id = instance_id;
    n.timeout = AM_NET_CONNECT_TIMEOUT;
    n.url = openam;

    ld.event = create_event();
    if (ld.event == NULL) return AM_ENOMEM;

    n.data = &ld;
    n.on_connected = on_connected_cb;
    n.on_close = on_close_cb;
    n.on_data = on_agent_request_data_cb;
    n.on_complete = on_complete_cb;

    if (am_net_connect(&n) == 0) {
        char *token_in = NULL;
        size_t token_sz = am_asprintf(&token_in, "token:%s", token);
        char *token_b64 = base64_encode(token_in, &token_sz);

        size_t post_data_sz = am_asprintf(&post_data,
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                "<RequestSet vers=\"1.0\" svcid=\"Session\" reqid=\"0\">"
                "<Request><![CDATA["
                "<SessionRequest vers=\"1.0\" reqid=\"1\" requester=\"%s\">"
                "<GetSession reset=\"true\">"
                "<SessionID>%s</SessionID>"
                "</GetSession>"
                "</SessionRequest>]]>"
                "</Request>"
                "<Request><![CDATA["
                "<SessionRequest vers=\"1.0\" reqid=\"2\" requester=\"%s\">"
                "<AddSessionListener>"
                "<URL>%s</URL>"
                "<SessionID>%s</SessionID>"
                "</AddSessionListener>"
                "</SessionRequest>]]>"
                "</Request>"
                "</RequestSet>",
                NOTNULL(token_b64), user_token, NOTNULL(token_b64), notif_url, user_token);

        AM_FREE(token_in, token_b64);

        if (post_data != NULL) {
            post_sz = am_asprintf(&post, "POST %s/sessionservice HTTP/1.1\r\n"
                    "Host: %s:%d\r\n"
                    "User-Agent: "MODINFO"\r\n"
                    "Accept: text/xml\r\n"
                    "Connection: close\r\n"
                    "Content-Type: text/xml; charset=UTF-8\r\n"
                    "Content-Length: %d\r\n\r\n"
                    "%s", n.uv.path, n.uv.host, n.uv.port, post_data_sz, post_data);
            if (post != NULL) {
                status = am_net_write(&n, post, post_sz);
                free(post);
                post = NULL;
            }
            free(post_data);
            post_data = NULL;
        }

    }

    if (status == AM_SUCCESS) {
        wait_for_event(ld.event, 0);
    } else {
        am_net_diconnect(&n);
    }

    am_net_close(&n);
    close_event(ld.event);

    am_free(ld.data);
    return status;
}
Esempio n. 26
0
int am_agent_policy_request(unsigned long instance_id, const char *openam,
        const char *token, const char *user_token, const char *req_url,
        const char *notif_url, const char *scope, const char *cip, const char *pattr,
        const char *server_id, struct am_ssl_options *info,
        struct am_namevalue **session_list,
        struct am_policy_result **policy_list) {

    static const char *thisfunc = "am_agent_policy_request():";
    char *post = NULL, *post_data = NULL;
    am_net_t n;
    size_t post_sz;
    int status = AM_ERROR;
    int session_status = AM_SUCCESS;
    struct request_data req_data;

    if (!ISVALID(token) || !ISVALID(user_token) || !ISVALID(notif_url) || !ISVALID(scope) ||
            !ISVALID(req_url) || !ISVALID(openam) || !ISVALID(cip)) {
        return AM_EINVAL;
    }

    memset(&req_data, 0, sizeof(struct request_data));
    memset(&n, 0, sizeof(am_net_t));
    n.instance_id = instance_id;
    n.timeout = AM_NET_CONNECT_TIMEOUT;
    n.url = openam;
    if (info != NULL) {
        memcpy(&n.ssl.info, info, sizeof(struct am_ssl_options));
    }

    if (ISVALID(server_id)) {
        am_asprintf(&n.req_headers, "Cookie: amlbcookie=%s\r\n", server_id);
    }

    req_data.event = create_event();
    if (req_data.event == NULL) {
        return AM_ENOMEM;
    }

    n.data = &req_data;
    n.on_connected = on_connected_cb;
    n.on_close = on_close_cb;
    n.on_data = on_agent_request_data_cb;
    n.on_complete = on_complete_cb;

    if (am_net_connect(&n) == 0) {
        char *token_in = NULL;
        size_t token_sz = am_asprintf(&token_in, "token:%s", token);
        char *token_b64 = base64_encode(token_in, &token_sz);

        size_t post_data_sz = am_asprintf(&post_data,
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                "<RequestSet vers=\"1.0\" svcid=\"Session\" reqid=\"0\">"
                "<Request><![CDATA["
                "<SessionRequest vers=\"1.0\" reqid=\"1\" requester=\"%s\">"
                "<GetSession reset=\"true\">" /* reset the idle timeout */
                "<SessionID>%s</SessionID>"
                "</GetSession>"
                "</SessionRequest>]]>"
                "</Request>"
                "<Request><![CDATA["
                "<SessionRequest vers=\"1.0\" reqid=\"2\" requester=\"%s\">"
                "<AddSessionListener>"
                "<URL>%s</URL>"
                "<SessionID>%s</SessionID>"
                "</AddSessionListener>"
                "</SessionRequest>]]>"
                "</Request>"
                "</RequestSet>",
                NOTNULL(token_b64), user_token, NOTNULL(token_b64), notif_url, user_token);

        AM_FREE(token_in, token_b64);

        if (post_data != NULL) {
            post_sz = am_asprintf(&post, "POST %s/sessionservice HTTP/1.1\r\n"
                    "Host: %s:%d\r\n"
                    "User-Agent: "MODINFO"\r\n"
                    "Accept: text/xml\r\n"
                    "Connection: Keep-Alive\r\n"
                    "Content-Type: text/xml; charset=UTF-8\r\n"
                    "%s"
                    "Content-Length: %d\r\n\r\n"
                    "%s", n.uv.path, n.uv.host, n.uv.port,
                    NOTNULL(n.req_headers), post_data_sz, post_data);
            if (post != NULL) {
                AM_LOG_DEBUG(instance_id, "%s sending request:\n%s", thisfunc, post);
                status = am_net_write(&n, post, post_sz);
                free(post);
                post = NULL;
            }
            free(post_data);
            post_data = NULL;
        }

        if (status == AM_SUCCESS) {
            wait_for_event(req_data.event, 0);
        }

        AM_LOG_DEBUG(instance_id, "%s response status code: %d", thisfunc, n.http_status);

        if (status == AM_SUCCESS && n.http_status == 200 && ISVALID(req_data.data)) {
            size_t req_url_sz = strlen(req_url);
            char *req_url_escaped = malloc(req_url_sz * 6 + 1); /* worst case */
            if (req_url_escaped != NULL) {
                memcpy(req_url_escaped, req_url, req_url_sz);
                xml_entity_escape(req_url_escaped, req_url_sz);
            }

            AM_LOG_DEBUG(instance_id, "%s response:\n%s", thisfunc, req_data.data);

            if (strstr(req_data.data, "<Exception>") != NULL && strstr(req_data.data, "Invalid session ID") != NULL) {
                session_status = AM_INVALID_SESSION;
            }
            if (strstr(req_data.data, "<Exception>") != NULL && strstr(req_data.data, "Application token passed in") != NULL) {
                session_status = AM_INVALID_AGENT_SESSION;
            }
            if (session_status == AM_SUCCESS && session_list != NULL) {
                *session_list = am_parse_session_xml(instance_id, req_data.data, req_data.data_size);
            }

            req_data.data_size = 0;
            free(req_data.data);
            req_data.data = NULL;

            /* TODO:
             * <AttributeValuePair><Attribute name=\"requestDnsName\"/><Value>%s</Value></AttributeValuePair>
             */
            post_data_sz = am_asprintf(&post_data,
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                    "<RequestSet vers=\"1.0\" svcid=\"Policy\" reqid=\"3\">"
                    "<Request><![CDATA[<PolicyService version=\"1.0\">"
                    "<PolicyRequest requestId=\"4\" appSSOToken=\"%s\">"
                    "<GetResourceResults userSSOToken=\"%s\" serviceName=\"iPlanetAMWebAgentService\" resourceName=\"%s\" resourceScope=\"%s\">"
                    "<EnvParameters><AttributeValuePair><Attribute name=\"requestIp\"/><Value>%s</Value></AttributeValuePair></EnvParameters>"
                    "<GetResponseDecisions>"
                    "%s"
                    "</GetResponseDecisions>"
                    "</GetResourceResults>"
                    "</PolicyRequest>"
                    "</PolicyService>]]>"
                    "</Request>"
                    "</RequestSet>",
                    token, user_token, NOTNULL(req_url_escaped), scope,
                    cip, NOTNULL(pattr));

            am_free(req_url_escaped);

            post_sz = am_asprintf(&post, "POST %s/policyservice HTTP/1.1\r\n"
                    "Host: %s:%d\r\n"
                    "User-Agent: "MODINFO"\r\n"
                    "Accept: text/xml\r\n"
                    "Content-Type: text/xml; charset=UTF-8\r\n"
                    "Content-Length: %d\r\n"
                    "%s"
                    "Connection: close\r\n\r\n"
                    "%s", n.uv.path, n.uv.host, n.uv.port,
                    post_data_sz, NOTNULL(n.req_headers), post_data);

            if (post != NULL) {
                AM_LOG_DEBUG(instance_id, "%s sending request:\n%s", thisfunc, post);
                status = am_net_write(&n, post, post_sz);
                free(post);
            }
        } else {
            status = n.error != AM_SUCCESS ? n.error : AM_ERROR;
        }
    }

    if (status == AM_SUCCESS) {
        wait_for_event(req_data.event, 0);
    } else {
        AM_LOG_DEBUG(instance_id, "%s disconnecting", thisfunc);
        am_net_diconnect(&n);
    }

    AM_LOG_DEBUG(instance_id, "%s response status code: %d", thisfunc, n.http_status);

    if (status == AM_SUCCESS && n.http_status == 200 && ISVALID(req_data.data)) {
        AM_LOG_DEBUG(instance_id, "%s response:\n%s", thisfunc, req_data.data);

        if (strstr(req_data.data, "<Exception>") != NULL) {
            if (strstr(req_data.data, "SSO token is invalid") != NULL) {
                session_status = AM_INVALID_SESSION;
            } else if (strstr(req_data.data, "Application sso token is invalid") != NULL) {
                session_status = AM_INVALID_AGENT_SESSION;
            }
        }

        if (session_status == AM_SUCCESS && policy_list != NULL) {
            *policy_list = am_parse_policy_xml(instance_id, req_data.data, req_data.data_size,
                    am_scope_to_num(scope));
        }
    }

    am_net_close(&n);
    close_event(req_data.event);

    am_free(req_data.data);
    return session_status != AM_SUCCESS ? session_status : status;
}
Esempio n. 27
0
Jukebox* View::getJukebox() {
  return NOTNULL(jukebox);
}
Esempio n. 28
0
void testValueCheck() {
  CHECK(3 == CHECKEQ(1 + 2, 3));
  string* s = new string("wefpok");
  CHECK(s == NOTNULL(s));
}
Esempio n. 29
0
void runner_change_callback( resolver* RS, const char* key, size_t key_len, const char* val, size_t val_len )
{
	if( g_changeStack >= MAX_CHANGE_STACK )
	{
		fprintf( stderr, "ERROR: exceeded change stack (%d changes)\n", MAX_CHANGE_STACK );
		return;
	}
	g_changeStack++;
#define ISKEY( s ) ( key_len == sizeof(s)-1 && !memcmp( s, key, sizeof(s)-1 ) )
#define PARSEINT() str_to_int( val )
#define PARSEENUM( enumstr ) enumstr_to_int( val, enumstr )
#define NOTNULL() ( val_len && ( val[0] != '0' || val[1] != 0 ) )
	
	X_DBG( printf( "CHANGE \"%.*s\" = \"%.*s\"\n", key_len, key, val_len, val ) );
	
	if( ISKEY( "quit" ) ){ if( NOTNULL() ) win_quit(); }
	else if( ISKEY( "run" ) ){ if( NOTNULL() ) runner_run( val ); }
	else if( ISKEY( "test" ) )
	{
		if( NOTNULL() )
		{
			if( g_inTest )
			{
				fprintf( stderr, "ERROR: 'test' action recursion, cannot start testing in testing progress callback\n" );
				return;
			}
			g_inTest = 1;
			runner_fsproc( 1 );
			g_inTest = 0;
		}
	}
	else if( ISKEY( "window.width" ) ){ g_window_width = PARSEINT(); g_requested_changes |= REQCHG_WINDOWSIZE; }
	else if( ISKEY( "window.height" ) ){ g_window_height = PARSEINT(); g_requested_changes |= REQCHG_WINDOWSIZE; }
	else if( ISKEY( "window.image" ) ){ win_set_background_image( PARSEINT() ); }
	else if( ISKEY( "window.title" ) )
	{
		win_set_title( val );
	}
	else if( key_len && *key == '#' )
	{
		/* CONTROL SETTINGS */
		const char* nkey = NULL;
		int ctlid = str_to_int_ext( key + 1, &nkey );
		if( ctlid < 0 )
		{
			fprintf( stderr, "ERROR: invalid control id=%d\n", ctlid );
			goto end;
		}
		if( ctlid > MAX_CONTROLS )
		{
			fprintf( stderr, "ERROR: exceeded MAX_CONTROLS with id=%d\n", ctlid );
			goto end;
		}
		if( ctlid >= g_numControls )
			win_ctl_resize( ctlid + 1 );
		
		key_len -= nkey - key;
		key = nkey;
		runner_change_ctl_handler( RS, &g_controls[ ctlid ], key, key_len, val, val_len );
		
	}
	else if( key_len >= sizeof("event.control")-1 && !strncmp( key, "event.control", sizeof( "event.control" )-1 ) )
	{
		key += sizeof("event.control")-1;
		key_len -= sizeof("event.control")-1;
		runner_change_ctl_handler( RS, g_event_control, key, key_len, val, val_len );
	}
	
end:
	g_changeStack--;
}
Esempio n. 30
0
int am_agent_logout(unsigned long instance_id, const char *openam,
        const char *token, const char *server_id,
        struct am_ssl_options *info, void(*log)(const char *, ...)) {
    static const char *thisfunc = "am_agent_logout():";
    am_net_t conn;
    int status = AM_ERROR;
    size_t post_sz, post_data_sz;
    char *post = NULL, *post_data = NULL;
    struct request_data req_data;

    if (!ISVALID(token) || !ISVALID(openam)) return AM_EINVAL;

    memset(&req_data, 0, sizeof(struct request_data));
    memset(&conn, 0, sizeof(am_net_t));
    conn.log = log;
    conn.instance_id = instance_id;
    conn.timeout = AM_NET_CONNECT_TIMEOUT;
    conn.url = openam;
    if (info != NULL) {
        memcpy(&conn.ssl.info, info, sizeof(struct am_ssl_options));
    }

    if (ISVALID(server_id)) {
        am_asprintf(&conn.req_headers, "Cookie: amlbcookie=%s\r\n", server_id);
    }

    req_data.event = create_event();
    if (req_data.event == NULL) return AM_ENOMEM;

    conn.data = &req_data;
    conn.on_connected = on_connected_cb;
    conn.on_close = on_close_cb;
    conn.on_data = on_agent_request_data_cb;
    conn.on_complete = on_complete_cb;

    if (am_net_connect(&conn) == 0) {
        post_data_sz = am_asprintf(&post_data,
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                "<RequestSet vers=\"1.0\" svcid=\"auth\" reqid=\"0\">"
                "<Request><![CDATA["
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?><AuthContext version=\"1.0\">"
                "<Request authIdentifier=\"%s\">"
                "<Logout/></Request></AuthContext>]]>"
                "</Request></RequestSet>",
                token);
        if (post_data != NULL) {
            post_sz = am_asprintf(&post, "POST %s/authservice HTTP/1.1\r\n"
                    "Host: %s:%d\r\n"
                    "User-Agent: "MODINFO"\r\n"
                    "Accept: text/xml\r\n"
                    "Connection: Close\r\n"
                    "Content-Type: text/xml; charset=UTF-8\r\n"
                    "%s"
                    "Content-Length: %d\r\n\r\n"
                    "%s", conn.uv.path, conn.uv.host, conn.uv.port,
                    NOTNULL(conn.req_headers), post_data_sz, post_data);
            if (post != NULL) {
                AM_LOG_DEBUG(instance_id, "%s sending request:\n%s", thisfunc, post);
                if (log != NULL) {
                    log("%s sending request:\n%s", thisfunc, post);
                }
                status = am_net_write(&conn, post, post_sz);
                free(post);
            }
            free(post_data);
        }
    }

    if (status == AM_SUCCESS) {
        wait_for_event(req_data.event, 0);
    } else {
        AM_LOG_DEBUG(instance_id, "%s disconnecting", thisfunc);
        if (log != NULL) {
            log("%s disconnecting", thisfunc);
        }
        am_net_diconnect(&conn);
    }

    AM_LOG_DEBUG(instance_id, "%s response status code: %d", thisfunc, conn.http_status);
    if (log != NULL) {
        log("%s response status code: %d", thisfunc, conn.http_status);
    }

    am_net_close(&conn);
    close_event(req_data.event);

    am_free(req_data.data);
    return status;
}