Пример #1
0
/* forwards the msg to the given location set; if flags has set the
 * CPL_PROXY_DONE, all locations will be added as braches, otherwise, the first
 * one will set as RURI (this is ha case when this is the first proxy of the
 * message)
 * The given list of location will be freed, returning 0 insted.
 * Returns:  0 - OK
 *          -1 - error */
int cpl_proxy_to_loc_set( struct sip_msg *msg, struct location **locs,
													unsigned char flag)
{
	struct location *foo;
	struct action act;

	if (!*locs) {
		LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: empty loc set!!\n");
		goto error;
	}

	/* if it's the first time when this sip_msg is proxyed, use the first addr
	 * in loc_set to rewrite the RURI */
	if (!(flag&CPL_PROXY_DONE)) {
		DBG("DEBUG:cpl_c:cpl_proxy_to_loc_set: rewriting Request-URI with "
			"<%s>\n",(*locs)->addr.uri.s);
		/* build a new action for setting the URI */
		act.type = SET_URI_T;
		act.p1_type = STRING_ST;
		act.p1.string = (*locs)->addr.uri.s;
		act.next = 0;
		/* push the action */
		if (do_action(&act, msg) < 0) {
			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: do_action failed\n");
			goto error;
		}
		/* free the location and point to the next one */
		foo = (*locs)->next;
		free_location( *locs );
		*locs = foo;
	}

	/* add the rest of the locations as branches */
	while(*locs) {
		DBG("DEBUG:cpl_c:cpl_proxy_to_loc_set: appending brach "
			"<%.*s>\n",(*locs)->addr.uri.len,(*locs)->addr.uri.s);
		if(append_branch(msg,(*locs)->addr.uri.s,(*locs)->addr.uri.len)==-1){
			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: failed when "
				"appending branch <%s>\n",(*locs)->addr.uri.s);
			goto error;
		}
		/* free the location and point to the next one */
		foo = (*locs)->next;
		free_location( *locs );
		*locs = foo;
	}

	/* do t_forward */
	if (cpl_tmb.t_forward_nonack(msg, 0/*no proxy*/)==-1) {
		LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: t_forward_nonack "
			"failed !\n");
		goto error;
	}

	return 1;
error:
	return -1;
}
Пример #2
0
rstat op_update( dict *d, void *key, void *val ) {
    location *locator = NULL;
    set_spec sp = { 0, 1, NULL, NULL };
    rstat err = do_set( d, &locator, key, val, &sp );
    if ( locator != NULL ) free_location( d, locator );
    return err;
}
Пример #3
0
rstat op_cmp_delete( dict *d, void *key, void *old_val ) {
    location *locator = NULL;
    set_spec sp = { 0, 1, old_val, NULL };
    rstat err = do_set( d, &locator, key, NULL, &sp );
    if ( locator != NULL ) free_location( d, locator );
    return err;
}
Пример #4
0
void rtems_filesystem_eval_path_cleanup_with_parent(
  rtems_filesystem_eval_path_context_t *ctx,
  rtems_filesystem_location_info_t *parentloc
)
{
  free_location(parentloc);
  rtems_filesystem_eval_path_cleanup(ctx);
}
Пример #5
0
rstat op_cmp_update( dict *d, void *key, void *old_val, void *new_val ) {
    if ( old_val == NULL ) return error( 1, 0, DICT_API_MISUSE, "NULL can not be used as the 'old value' in compare and swap" );
    location *locator = NULL;
    set_spec sp = { 0, 1, old_val, NULL };
    rstat err = do_set( d, &locator, key, new_val, &sp );
    if ( locator != NULL ) free_location( d, locator );
    return err;
}
Пример #6
0
void rtems_filesystem_eval_path_cleanup(
  rtems_filesystem_eval_path_context_t *ctx
)
{
  free_location(&ctx->currentloc);
  rtems_filesystem_instance_unlock(&ctx->startloc->location);
  rtems_filesystem_global_location_release(ctx->startloc);
  rtems_filesystem_global_location_release(ctx->rootloc);
}
Пример #7
0
rstat op_insert( dict *d, void *key, void *val ) {
    location *locator = NULL;
    set_spec sp = { 1, 0, NULL, NULL };
    rstat err = do_set( d, &locator, key, val, &sp );
    if ( locator != NULL ) {
        free_location( d, locator );
    }
    return err;
}
Пример #8
0
rstat op_dereference( dict *d, void *key ) {
    location *loc = NULL;
    rstat err = locate_key( d, key, &loc );

    if ( !err.num && loc->sref != NULL ) err = do_deref( d, key, loc, NULL );

    if ( loc != NULL ) free_location( d, loc );
    return err;
}
Пример #9
0
rstat op_trigger( dict *d, void *key, dict_trigger *t, void *targ, void *val ) {
    location *locator = NULL;
    set_spec sp = { 1, 0, NULL, NULL, t, targ };
    rstat err = do_set( d, &locator, key, val, &sp );
    if ( locator != NULL ) {
        free_location( d, locator );
    }
    return err;
}
Пример #10
0
void rtems_filesystem_eval_path_restart(
  rtems_filesystem_eval_path_context_t *ctx,
  rtems_filesystem_global_location_t **newstartloc_ptr
)
{
  free_location(&ctx->currentloc);
  rtems_filesystem_instance_unlock(&ctx->startloc->location);
  rtems_filesystem_global_location_assign(
    &ctx->startloc,
    rtems_filesystem_global_location_obtain(newstartloc_ptr)
  );
  rtems_filesystem_instance_lock(&ctx->startloc->location);
  rtems_filesystem_location_clone(&ctx->currentloc, &ctx->startloc->location);
}
Пример #11
0
rstat op_get( dict *d, void *key, void **val ) {
    location *loc = NULL;
    rstat err = locate_key( d, key, &loc );

    if ( !err.num ) {
        if ( loc->xtrn == NULL ) {
            *val = NULL;
        }
        else {
            *val = loc->xtrn->value;
            if ( d->methods.ref )
                d->methods.ref( d, *val, 1 );
        }
    }

    // Free our locator
    if ( loc != NULL ) free_location( d, loc );

    return err;
}
int main(int argc, char **argv)
{
  int i, currentNebUser, currentUserMessage, matches = 0;
  /* print usage if needed */
  if (argc != 1)
  {
    fprintf(stderr, "No args needed");
    exit(0);
  }

  char filename[1024];
  FILE *file = NULL, *fp = NULL, *userFile = NULL, *messageFile = NULL;

  sprintf(filename, "../../Data/tableinfo.dat");
  file = fopen(filename, "rb");

  int locationNum, userNum, messageNum;
  fread(&locationNum, sizeof(int), 1, file);
  fread(&userNum, sizeof(int), 1, file);
  fread(&messageNum, sizeof(int), 1, file);
  fclose(file);

  struct timeval time_start, time_end;

  int previousBest =0;
  int bestUserID =0;
  char *matchString = "Nebraska";

  /* start time */
  gettimeofday(&time_start, NULL);

  // Get list of NE cities
  int nebraskaStart, nebraskaEnd;
  nebraskaStart = findLocationEdge(0, locationNum, matchString, -1, 0);
  nebraskaEnd = findLocationEdge(0, locationNum, matchString, 1, locationNum);
  //printf("NE Start: %d, NE End: %d", nebraskaStart, nebraskaEnd);

  for (i = nebraskaStart; i <= nebraskaEnd; i++)
  {
    /* open the corresponding file */
    sprintf(filename, "../../Data/Locations/location_%06d.dat", i);

    fp = fopen(filename,"rb");

    if (!fp) {
      fprintf(stderr, "Cannot open %s\n", filename);
      exit(0);
    }

    // Get location id from NE cities
    location_t *loc = read_location(fp);
    //printf("%s, %s\n", loc->city, loc->state);
    fclose(fp);

    //printf("%s, %s\n", loc->city, loc->state);

    // Get list of users from NE cities
    int firstNebUserAtLocation, lastNebUserAtLocation;
    firstNebUserAtLocation = findUserEdge(0, userNum, loc->locationID, -1, 0);
    lastNebUserAtLocation = findUserEdge(0, userNum, loc->locationID, 1, userNum);
    //printf("  Start: %i, End: %i\n", firstNebUserAtLocation, lastNebUserAtLocation);

    // foreach user locationStart to locationEnd
    for (currentNebUser = firstNebUserAtLocation; currentNebUser <= lastNebUserAtLocation; currentNebUser++)
    {
      // open user file at current ID in loop
      sprintf(filename, "../../Data/Users/user_%06d.dat", currentNebUser);
      userFile = fopen(filename, "rb");

      if (!userFile) {
        fprintf(stderr, "Cannot open %s\n", filename);
        exit(0);
      }

      // Get userid from NE users
      user_t *usr = read_user(userFile);
      fclose(userFile);

      // get list of messages from NE users
      int firstUserMessage, lastUserMessage;
      firstUserMessage = findMessageEdge(0, messageNum, usr->id, -1, 0);
      lastUserMessage = findMessageEdge(0, messageNum, usr->id, 1, messageNum);
      //printf("    UserMessages Start: %i, End: %i\n", firstUserMessage, lastUserMessage);
      if(firstUserMessage == -1 && lastUserMessage == -1)
      {
	printf("Warning, no messages found for user %i\n", usr->id);
      }
      else
      {
        int criteriaCount = 0;
        // foreach message associated with current user id
        for (currentUserMessage = firstUserMessage; currentUserMessage <= lastUserMessage; currentUserMessage++)
        {
          // open message file
          sprintf(filename, "../../Data/Messages/message_%07d.dat", currentUserMessage);
          messageFile = fopen(filename, "rb");

          if (!messageFile) {
            fprintf(stderr, "Cannot open %s\n", filename);
            exit(0);
          }

          message_t *msg = read_message(messageFile);
          fclose(messageFile);

          // check time; increment
          if (msg->hour == 8 || ((msg->hour == 9) && (msg->minute == 0)))
          {
            criteriaCount++;
          }
        }
	if (criteriaCount > previousBest)
	{
	  previousBest = criteriaCount;
	  bestUserID = usr->id;
	}
      }
    }

    free_location(loc);
  }

  /* end time */
  gettimeofday(&time_end, NULL);

  float totaltime = (time_end.tv_sec - time_start.tv_sec)
  + (time_end.tv_usec - time_start.tv_usec) / 1000000.0f;

  printf("\n\nUserID  %i and Number of Messages %i \n", bestUserID, previousBest);
  printf("\n\nProcess time %f seconds\n", totaltime);

  return 0;
}
Пример #13
0
/* forwards the msg to the given location set; if flags has set the
 * CPL_PROXY_DONE, all locations will be added as branches, otherwise, the 
 * first one will set as RURI (this is ha case when this is the first proxy 
 * of the message)
 * The given list of location will be freed, returning 0 instead.
 * Returns:  0 - OK
 *          -1 - error */
int cpl_proxy_to_loc_set( struct sip_msg *msg, struct location **locs,
													unsigned char flag)
{
	struct location *foo;
	struct action act;
	struct run_act_ctx ra_ctx;
	int bflags;

	if (!*locs) {
		LM_ERR("empty loc set!!\n");
		goto error;
	}

	/* if it's the first time when this sip_msg is proxied, use the first addr
	 * in loc_set to rewrite the RURI */
	if (!(flag&CPL_PROXY_DONE)) {
		LM_DBG("rewriting Request-URI with <%s>\n",(*locs)->addr.uri.s);
		/* build a new action for setting the URI */
		memset(&act, '\0', sizeof(act));
		act.type = SET_URI_T;
		act.val[0].type = STRING_ST;
		act.val[0].u.string = (*locs)->addr.uri.s;
		init_run_actions_ctx(&ra_ctx);
		/* push the action */
		if (do_action(&ra_ctx, &act, msg) < 0) {
			LM_ERR("do_action failed\n");
			goto error;
		}
		/* build a new action for setting the DSTURI */
		if((*locs)->addr.received.s && (*locs)->addr.received.len) {
			LM_DBG("rewriting Destination URI "
				"with <%s>\n",(*locs)->addr.received.s);
			if (set_dst_uri(msg, &(*locs)->addr.received) < 0) {
				LM_ERR("Error while setting the dst uri\n");
				goto error;
			}
			/* dst_uri changes, so it makes sense to re-use the current uri for
				forking */
			ruri_mark_new(); /* re-use uri for serial forking */
		}
		/* is the location NATED? */
		if ((*locs)->flags&CPL_LOC_NATED)
			setbflag( 0, cpl_fct.ulb.nat_flag );
		/* free the location and point to the next one */
		foo = (*locs)->next;
		free_location( *locs );
		*locs = foo;
	}

	/* add the rest of the locations as branches */
	while(*locs) {
		bflags = ((*locs)->flags&CPL_LOC_NATED) ? cpl_fct.ulb.nat_flag : 0 ;
		LM_DBG("appending branch <%.*s>, flags %d\n",
			(*locs)->addr.uri.len, (*locs)->addr.uri.s, bflags);
		if(append_branch(msg, &(*locs)->addr.uri,
				 &(*locs)->addr.received, 0,
				 Q_UNSPECIFIED, bflags, 0, 0, 0, 0, 0)==-1){
			LM_ERR("failed when appending branch <%s>\n",
			       (*locs)->addr.uri.s);
			goto error;
		}
		/* free the location and point to the next one */
		foo = (*locs)->next;
		free_location( *locs );
		*locs = foo;
	}

	/* run what proxy route is set */
	if (cpl_env.proxy_route) {
		/* do not alter route type - it might be REQUEST or FAILURE */
		run_top_route( main_rt.rlist[cpl_env.proxy_route], msg, 0);
	}

	/* do t_forward */
	if (cpl_fct.tmb.t_relay(msg, 0, 0)==-1) {
		LM_ERR("t_relay failed !\n");
		goto error;
	}

	return 0;
error:
	return -1;
}
Пример #14
0
/* forwards the msg to the given location set; if flags has set the
 * CPL_PROXY_DONE, all locations will be added as branches, otherwise, the first
 * one will set as RURI (this is ha case when this is the first proxy of the
 * message)
 * The given list of location will be freed, returning 0 instead.
 * Returns:  0 - OK
 *          -1 - error */
int cpl_proxy_to_loc_set( struct sip_msg *msg, struct location **locs,
													unsigned char flag)
{
	struct location *foo;
	struct action act;

	if (!*locs) {
		LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: empty loc set!!\n");
		goto error;
	}

	/* if it's the first time when this sip_msg is proxied, use the first addr
	 * in loc_set to rewrite the RURI */
	if (!(flag&CPL_PROXY_DONE)) {
		DBG("DEBUG:cpl_c:cpl_proxy_to_loc_set: rewriting Request-URI with "
			"<%s>\n",(*locs)->addr.uri.s);
		/* build a new action for setting the URI */
		memset(&act, 0, sizeof(act));
		act.type = SET_URI_T;
		act.val[0].type = STRING_ST;
		act.val[0].u.string = (*locs)->addr.uri.s;
		act.next = 0;
		/* push the action */
		if (do_action(&act, msg) < 0) {
			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: do_action failed\n");
			goto error;
		}
		/* is the location NATED? */
		if ((*locs)->flags&CPL_LOC_NATED) setflag(msg,cpl_env.nat_flag);
		/* free the location and point to the next one */
		foo = (*locs)->next;
		free_location( *locs );
		*locs = foo;
	}

	/* add the rest of the locations as branches */
	while(*locs) {
		DBG("DEBUG:cpl_c:cpl_proxy_to_loc_set: appending branch "
			"<%.*s>\n",(*locs)->addr.uri.len,(*locs)->addr.uri.s);
		if(append_branch(msg,(*locs)->addr.uri.s,(*locs)->addr.uri.len,0, 0, Q_UNSPECIFIED, 0)==-1){
			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: failed when "
				"appending branch <%s>\n",(*locs)->addr.uri.s);
			goto error;
		}
		/* is the location NATED? */
		if ((*locs)->flags&CPL_LOC_NATED) setflag(msg,cpl_env.nat_flag);
		/* free the location and point to the next one */
		foo = (*locs)->next;
		free_location( *locs );
		*locs = foo;
	}

	/* run what proxy route is set */
	if (cpl_env.proxy_route) {
		if (run_actions( main_rt.rlist[cpl_env.proxy_route], msg)<0) {
			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: "
				"Error in do_action for proxy_route\n");
		}
	}

	/* do t_forward */
	if ( flag&CPL_IS_STATEFUL ) {
		/* transaction exists */
		if (cpl_fct.tmb.t_forward_nonack(msg, 0/*no proxy*/)==-1) {
			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: t_forward_nonack "
				"failed !\n");
			goto error;
		}
	} else {
		/* no transaction -> build & fwd */
		if (cpl_fct.tmb.t_relay(msg, 0, 0)==-1) {
			LOG(L_ERR,"ERROR:cpl_c:cpl_proxy_to_loc_set: t_relay failed !\n");
			goto error;
		}
	}

	return 0;
error:
	return -1;
}
Пример #15
0
/* forwards the msg to the given location set; if flags has set the
 * CPL_PROXY_DONE, all locations will be added as branches, otherwise, the 
 * first one will set as RURI (this is ha case when this is the first proxy 
 * of the message)
 * The given list of location will be freed, returning 0 instead.
 * Returns:  0 - OK
 *          -1 - error */
int cpl_proxy_to_loc_set( struct sip_msg *msg, struct location **locs,
													unsigned char flag)
{
	struct location *foo;
	int bflags;
	int r;

	if (!*locs) {
		LM_ERR("empty loc set!!\n");
		goto error;
	}

	/* use the first addr in loc_set to rewrite the RURI */
	LM_DBG("rewriting Request-URI with <%s>\n",(*locs)->addr.uri.s);
	/* set RURI*/
	if ( set_ruri( msg, &((*locs)->addr.uri))==-1 ) {
		LM_ERR("failed to set new RURI\n");
		goto error;
	}
	/* set DST URI */
	if((*locs)->addr.received.s && (*locs)->addr.received.len) {
		LM_DBG("rewriting Destination URI "
			"with <%s>\n",(*locs)->addr.received.s);
		if (set_dst_uri( msg, &((*locs)->addr.received) ) ) {
			LM_ERR("failed to set destination URI\n");
			goto error;
		}
	}
	/* is the location NATED? */
	bflags = ((*locs)->flags&CPL_LOC_NATED) ? cpl_fct.ulb.nat_flag : 0 ;
	setb0flags(bflags);
	/* free the location and point to the next one */
	foo = (*locs)->next;
	free_location( *locs );
	*locs = foo;

	/* add the rest of the locations as branches */
	while(*locs) {
		bflags = ((*locs)->flags&CPL_LOC_NATED) ? cpl_fct.ulb.nat_flag : 0 ;
		LM_DBG("appending branch <%.*s>, flags %d\n",
			(*locs)->addr.uri.len, (*locs)->addr.uri.s, bflags);
		if(append_branch(msg, &(*locs)->addr.uri, &(*locs)->addr.received,0,
		Q_UNSPECIFIED, bflags, 0)==-1){
			LM_ERR("failed when appending branch <%s>\n",(*locs)->addr.uri.s);
			goto error;
		}
		/* free the location and point to the next one */
		foo = (*locs)->next;
		free_location( *locs );
		*locs = foo;
	}

	/* run what proxy route is set */
	if (cpl_env.proxy_route) {
		/* do not alter route type - it might be REQUEST or FAILURE */
		run_top_route( rlist[cpl_env.proxy_route].a, msg);
	}

	/* do t_forward */
	if ((r = cpl_fct.tmb.t_relay(msg, 0, 0, 0, 0, 0, 0)) < 0) {
		LM_ERR("t_relay failed! error=%d\n",r);
		goto error;
	}

	return 0;
error:
	return -1;
}
Пример #16
0
rstat op_reference( dict *orig, void *okey, set_spec *osp, dict *dest, void *dkey, set_spec *dsp ) {
    rstat out = rstat_ok;
    dev_assert( dsp->swap_from == NULL );
    location *oloc = NULL;
    location *dloc = NULL;

    // Find existing pairs
    out = locate_key( orig, okey, &oloc );
    if ( out.bit.error ) goto OP_REFERENCE_CLEANUP;
    out = locate_key( dest, dkey, &dloc );
    if ( out.bit.error ) goto OP_REFERENCE_CLEANUP;

    if ( oloc->set->immutable || dloc->set->immutable ) {
        out = rstat_imute;
        goto OP_REFERENCE_CLEANUP;
    }

    // No current value, and cannot insert
    if (( !oloc->sref || !oloc->xtrn ) && !osp->insert ) {
        out = rstat_trans;
        goto OP_REFERENCE_CLEANUP;
    }
    if (( !dloc->sref || !dloc->xtrn ) && !dsp->insert ) {
        out = rstat_trans;
        goto OP_REFERENCE_CLEANUP;
    }

    // Current value, but cannot update
    if ( dloc->xtrn && !dsp->update ) {
        out = rstat_trans;
        goto OP_REFERENCE_CLEANUP;
    }

    if ( !oloc->sref ) {
        out = do_set( orig, &oloc, okey, NULL, osp );

        // Error on all but rebalance issues.
        if ( out.bit.error && !out.bit.rebal )
            goto OP_REFERENCE_CLEANUP;
    }

    if ( !dloc->usref ) {
        out = do_set( dest, &dloc, dkey, NULL, dsp );

        // Error on all but rebalance issues.
        if ( out.bit.error && !out.bit.rebal )
            goto OP_REFERENCE_CLEANUP;
    }

    dev_assert( oloc->sref );
    dev_assert( dloc->usref );

    dev_assert( !blocked_null( oloc->sref ));
    dev_assert( !blocked_null( dloc->usref ));

    out = do_deref( dest, dkey, dloc, oloc->usref->sref );

    OP_REFERENCE_CLEANUP:

    if ( oloc != NULL ) free_location( orig, oloc );
    if ( dloc != NULL ) free_location( dest, dloc );

    return out;
}