예제 #1
0
 void node(const osmium::Node& node) {
     try {
         add_location(m_old_index.get(node.id()));
     } catch (...) {
     }
     try {
         add_location(node.location());
     } catch (...) {
     }
 }
예제 #2
0
 void way(const osmium::Way& way) {
     for (const auto& node_ref : way.nodes()) {
         try {
             add_location(m_old_index.get(node_ref.ref()));
         } catch (...) {
         }
         try {
             add_location(m_tmp_index.get(node_ref.ref()));
         } catch (...) {
         }
     }
 }
예제 #3
0
		void environment::spawn_player(point2 location)
		{
			// player props
			auto weapon = std::make_shared<body_component::item_type>();
			weapon->add({ rl::effect::weapon_damage, 0x00, 50 });
			weapon->add({ rl::effect::equipment, static_cast<unsigned int>(rl::equipment_slot::hand_main) });
			weapon->set_name("Copper Sword");
			weapon->set_tag("copper_sword");

			// make player
			auto task = m_factory->produce();
			auto img = task->add_appearance('@', { 1, 1, 1 });
			auto pawn = task->add_location(location);
			auto body = task->add_body(100, 100);
			auto character = task->add_character();

			// setup
			body->set_name("You");
			body->set_tag("player");
			body->join_faction(1);
			body->add(weapon);
			body->equip(weapon);

			character->add_skill("sk_bash");
			character->add_skill("sk_panacea");
			character->add_skill("sk_teleport");
			character->add_skill("sk_fireball");
			character->add_skill("sk_indigo");

			m_terrain.add(task->assemble(persistency::permanent));

			impersonate(pawn);
		}
예제 #4
0
void City::add_staging_area(Location loc, int* inventories, int capacity)
{
	clear_intermediates();

	DumpsterSize sizes[] = {smallest, small, big, biggest};
	location l = add_location(loc);
	for (int j = 0; j < 4; j++)
	{
		add_stop(new Action
		{
			Store,
			sizes[j],
			none,
			0,
			sh_time_look_ahead,
			STAGE_TIME,
			l
		});
		add_stop(new Action
		{
			UnStore,
			none,
			sizes[j],
			0,
			sh_time_look_ahead,
			STAGE_TIME,
			l
		});
	}

	staging_areas.insert(std::pair<int, StagingArea>{l, StagingArea{l, capacity, inventories}});
}
예제 #5
0
		void environment::start()
		{
			end();

			m_time = 0;
			m_running = true;

			m_world.resize(settings::world_width, settings::world_height);
			m_world.generate(m_settings.seed());

			spawn_player(m_world.spawn() * point2(settings::cell_width, settings::cell_height));

			// ui
			tie_map();
			m_ui->deactivate("title");
			m_ui->activate("ingame");

			// make chest
			auto chest = m_factory->produce();
			chest->add_appearance('$', { 1, 1, 1 });
			chest->add_location({ 2, 2 });
			auto body = chest->add_body(250, 150);
			body->set_name("Iron chest");
			chest->add_container();
			m_terrain.add(*chest);

			auto ore = std::make_shared<body_component::item_type>();
			ore->add({ rl::effect::ore_power, 0x00, 10 });
			ore->add({ rl::effect::value, 0x00, 5 });
			ore->add({ rl::effect::weight, 0x00, 1 });
			ore->set_name("Copper ore");
			ore->set_tag("ore_copper");
			auto vein = m_factory->produce();
			vein->add_appearance('0');
			vein->add_location({ 3, 3 });
			vein->add_body();
			auto v = vein->add_resource();
			v->deposit(ore);
			m_terrain.add(*vein);

			auto anvil = m_factory->produce();
			anvil->add_appearance('t');
			anvil->add_location({ 3, 0 });
			anvil->add_body();
			anvil->add_container();
			m_terrain.add(*anvil);
		}
예제 #6
0
City::City() :
	start_action {new Action},
	distances{(double *) malloc (sizeof (*distances))},
	intermediate_actions{nullptr}
{
	add_location(Location{});
	start_action->set_index(START_INDEX);
}
예제 #7
0
void LocationsMgr::add_locations( const CfgSections& cfg )
{
	for( auto itr=cfg.begin() ; itr!=cfg.end() ; ++itr )
		try {
			add_location( itr->first , itr->second );
		} catch( config_error& e ) {
			sz_log(1,"Invalid configuration at %s: %s" , itr->first.c_str() , e.what() );
		}
}
예제 #8
0
void City::add_land_fill(Location loc)
{
	clear_intermediates();

	DumpsterSize sizes[] = {smallest, small, big, biggest};
	location l = add_location(loc);
	for (int j = 0; j < 4; j++)
	{
		add_stop(new Action
		{
			Dump,
			sizes[j],
			sizes[j],
			0,
			sh_time_look_ahead,
			LANDFILL_TIME,
			l
		});
	}
}
예제 #9
0
파일: cpl_run.c 프로젝트: 2pac/kamailio
/* UPDATED + CHECKED
 */
static inline char *run_location( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	char  *p;
	unsigned char  prio;
	unsigned char  clear;
	str url;
	int i;

	clear = NO_VAL;
	prio = 10;
	url.s = (char*)UNDEF_CHAR;
	url.len = 0;

	/* sanity check */
	if (NR_OF_KIDS(intr->ip)>1) {
		LM_ERR("LOCATION node suppose to have max "
			"one child, not %d!\n",NR_OF_KIDS(intr->ip));
		goto script_error;
	}

	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p,attr_name,n,intr,script_error);
		switch (attr_name) {
			case URL_ATTR:
				url.len = n;
				get_str_attr( p, url.s, url.len, intr, script_error,1);
				break;
			case PRIORITY_ATTR:
				if ( n>10)
					LM_WARN("invalid value (%u) found"
						" for param. PRIORITY in LOCATION node -> using "
						"default (%u)!\n",n,prio);
				else
					prio = n;
				break;
			case CLEAR_ATTR:
				if (n!=YES_VAL && n!=NO_VAL)
					LM_WARN("invalid value (%u) found"
						" for param. CLEAR in LOCATION node -> using "
						"default (%u)!\n",n,clear);
				else
					clear = n;
				break;
			default:
				LM_ERR("unknown attribute (%d) in "
					"LOCATION node\n",attr_name);
				goto script_error;
		}
	}

	if (url.s==(char*)UNDEF_CHAR) {
		LM_ERR("param. URL missing in LOCATION node\n");
		goto script_error;
	}

	if (clear)
		empty_location_set( &(intr->loc_set) );
	if (add_location( &(intr->loc_set), &url, 0, prio, 0/*no dup*/ )==-1) {
		LM_ERR("unable to add location to set :-(\n");
		goto runtime_error;
	}
	/* set the flag for modifying the location set */
	intr->flags |= CPL_LOC_SET_MODIFIED;

	return get_first_child(intr->ip);
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
예제 #10
0
파일: cpl_run.c 프로젝트: 2pac/kamailio
/* UPDATED + CHECKED
 */
static inline char *run_lookup( struct cpl_interpreter *intr )
{
	unsigned short attr_name;
	unsigned short n;
	unsigned char  clear;
	char *p;
	char *kid;
	char *failure_kid = 0;
	char *success_kid = 0;
	char *notfound_kid = 0;
	int  i;
	time_t      tc;
	urecord_t*  r;
	ucontact_t* contact;

	clear = NO_VAL;

	/* check the params */
	for( i=NR_OF_ATTR(intr->ip),p=ATTR_PTR(intr->ip) ; i>0 ; i-- ) {
		get_basic_attr(p,attr_name,n,intr,script_error);
		switch (attr_name) {
			case CLEAR_ATTR:
				if (n!=YES_VAL && n!=NO_VAL)
					LM_WARN("invalid value (%u) found"
						" for param. CLEAR in LOOKUP node -> using "
						"default (%u)!\n",n,clear);
				else
					clear = n;
				break;
			default:
				LM_ERR("unknown attribute (%d) in LOOKUP node\n",attr_name);
				goto script_error;
		}
	}

	/* check the kids */
	for( i=0 ; i<NR_OF_KIDS(intr->ip) ; i++ ) {
		kid = intr->ip + KID_OFFSET(intr->ip,i);
		check_overflow_by_ptr( kid+SIMPLE_NODE_SIZE(kid), intr, script_error);
		switch ( NODE_TYPE(kid) ) {
			case SUCCESS_NODE :
				success_kid = kid;
				break;
			case NOTFOUND_NODE:
				notfound_kid = kid;
				break;
			case FAILURE_NODE:
				failure_kid = kid;
				break;
			default:
				LM_ERR("unknown output node type"
					" (%d) for LOOKUP node\n",NODE_TYPE(kid));
				goto script_error;
		}
	}

	kid = failure_kid;

	if (cpl_env.lu_domain) {
		/* fetch user's contacts via usrloc */
		tc = time(0);
		cpl_fct.ulb.lock_udomain( cpl_env.lu_domain, &intr->user );
		i = cpl_fct.ulb.get_urecord( cpl_env.lu_domain, &intr->user, &r);
		if (i < 0) {
			/* failure */
			LM_ERR("failed to query usrloc\n");
			cpl_fct.ulb.unlock_udomain( cpl_env.lu_domain, &intr->user );
		} else if (i > 0) {
			/* not found */
			LM_DBG("'%.*s' Not found in usrloc\n",
				intr->user.len, intr->user.s);
			cpl_fct.ulb.unlock_udomain( cpl_env.lu_domain, &intr->user );
			kid = notfound_kid;
		} else {
			contact = r->contacts;
			/* skip expired contacts */
			while ((contact) && (contact->expires <= tc))
				contact = contact->next;
			/* any contacts left? */
			if (contact) {
				/* clear loc set if requested */
				if (clear)
					empty_location_set( &(intr->loc_set) );
				/* start adding locations to set */
				do {
					LM_DBG("adding <%.*s>q=%d\n",
						contact->c.len,contact->c.s,(int)(10*contact->q));
					if (add_location( &(intr->loc_set), &contact->c, 
					&contact->received, (int)(10*contact->q),
					CPL_LOC_DUPL|
						((contact->cflags&cpl_fct.ulb.nat_flag)?CPL_LOC_NATED:0)
					)==-1) {
						LM_ERR("unable to add location to set :-(\n");
						cpl_fct.ulb.unlock_udomain( cpl_env.lu_domain, &intr->user );
						goto runtime_error;
					}
					contact = contact->next;
				}while( contact && cpl_env.lu_append_branches);
				/* set the flag for modifying the location set */
				intr->flags |= CPL_LOC_SET_MODIFIED;
				/* we found a valid contact */
				kid = success_kid;
			} else {
				/* no valid contact found */
				kid = notfound_kid;
			}
			cpl_fct.ulb.unlock_udomain( cpl_env.lu_domain, &intr->user );
		}

	}

	if (kid)
		return get_first_child(kid);
	return DEFAULT_ACTION;
runtime_error:
	return CPL_RUNTIME_ERROR;
script_error:
	return CPL_SCRIPT_ERROR;
}
예제 #11
0
파일: cpl.c 프로젝트: NormB/opensips
/* Params:
 *   str1 - as unsigned int - can be CPL_RUN_INCOMING or CPL_RUN_OUTGOING
 *   str2 - as unsigned int - flags regarding state(less)|(ful)
 */
static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
{
	struct cpl_interpreter  *cpl_intr;
	str  username = {0,0};
	str  domain = {0,0};
	str  loc;
	str  script;

	/* get the user_name */
	if ( ((unsigned long)str1)&CPL_RUN_INCOMING ) {
		/* if it's incoming -> get the destination user name */
		if (get_dest_user( msg, &username, &domain)==-1)
			goto error0;
	} else {
		/* if it's outgoing -> get the origin user name */
		if (get_orig_user( msg, &username, &domain)==-1)
			goto error0;
	}

	/* get the script for this user */
	if (get_user_script(&username, cpl_env.use_domain?&domain:0,
	&script, &cpl_bin_col)==-1)
		goto error0;

	/* has the user a non-empty script? if not, return normally, allowing the
	 * script execution to continue */
	if ( !script.s || !script.len )
		return 2;

	/* build a new script interpreter */
	if ( (cpl_intr=new_cpl_interpreter(msg,&script))==0 )
		goto error1;
	/* set the flags */
	cpl_intr->flags =(unsigned int)((unsigned long)str1)|((unsigned long)str2);
	/* build user AOR */
	if (build_user_AOR( &username, &domain, &(cpl_intr->user), 0)!=0 )
		goto error2;
	/* for OUTGOING we need also the destination user for init. with him
	 * the location set */
	if ( ((unsigned long)str1)&CPL_RUN_OUTGOING ) {
		/* build user initial location -> get the destination user name */
		if (get_dest_user( msg, &username, &domain)==-1)
			goto error2;
		if (build_user_AOR( &username, &domain, &loc, 1)!=0 )
			goto error2;
		if (add_location( &(cpl_intr->loc_set), &loc, 0, 10,CPL_LOC_DUPL)==-1){
			shm_free(loc.s);
			goto error2;
		}
		shm_free(loc.s);
	}

	/* run the script */
	switch (cpl_run_script( cpl_intr )) {
		case SCRIPT_DEFAULT:
			if ( cpl_intr->flags&CPL_DO_NOT_FREE )
				cpl_intr->flags |= CPL_ENDED;
			else
				free_cpl_interpreter( cpl_intr );
			return 1; /* execution of ser's script will continue */
		case SCRIPT_END:
			if ( cpl_intr->flags&CPL_DO_NOT_FREE )
				cpl_intr->flags |= CPL_ENDED;
			else
				free_cpl_interpreter( cpl_intr );
		case SCRIPT_TO_BE_CONTINUED:
			return 0; /* break the SER script */
		case SCRIPT_RUN_ERROR:
		case SCRIPT_FORMAT_ERROR:
			goto error2;
	}

	return 1;
error2:
	if ( cpl_intr->flags&CPL_DO_NOT_FREE )
		cpl_intr->flags |= CPL_ENDED;
	else
		free_cpl_interpreter( cpl_intr );
	return -1;
error1:
	shm_free(script.s);
error0:
	return -1;
}
static void
cc_privacy_panel_init (CcPrivacyPanel *self)
{
  GError    *error;
  GtkWidget *widget;
  GtkWidget *frame;
  guint res;

  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, CC_TYPE_PRIVACY_PANEL, CcPrivacyPanelPrivate);
  g_resources_register (cc_privacy_get_resource ());

  self->priv->cancellable = g_cancellable_new ();
  self->priv->builder = gtk_builder_new ();

  error = NULL;
  res = gtk_builder_add_from_resource (self->priv->builder,
                                       "/org/gnome/control-center/privacy/privacy.ui",
                                       &error);

  if (res == 0)
    {
      g_warning ("Could not load interface file: %s",
                 (error != NULL) ? error->message : "unknown error");
      g_clear_error (&error);
      return;
    }

  self->priv->recent_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "recent_dialog"));
  self->priv->screen_lock_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "screen_lock_dialog"));
  self->priv->location_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "location_dialog"));
  self->priv->trash_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "trash_dialog"));
  self->priv->software_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "software_dialog"));
  self->priv->abrt_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "abrt_dialog"));

  frame = WID ("frame");
  widget = gtk_list_box_new ();
  gtk_list_box_set_selection_mode (GTK_LIST_BOX (widget), GTK_SELECTION_NONE);
  gtk_container_add (GTK_CONTAINER (frame), widget);
  self->priv->list_box = widget;
  gtk_widget_show (widget);
  self->priv->location_apps_list_box = WID ("location_apps_list_box");
  gtk_list_box_set_header_func (GTK_LIST_BOX (self->priv->location_apps_list_box),
                                cc_list_box_update_header_func,
                                NULL, NULL);
  self->priv->location_apps_frame = WID ("location_apps_frame");
  self->priv->location_apps_label = WID ("location_apps_label");
  self->priv->location_icon_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);

  g_signal_connect_swapped (widget, "row-activated",
                            G_CALLBACK (activate_row), self);

  gtk_list_box_set_header_func (GTK_LIST_BOX (widget),
                                cc_list_box_update_header_func,
                                NULL, NULL);

  self->priv->lockdown_settings = g_settings_new ("org.gnome.desktop.lockdown");
  self->priv->lock_settings = g_settings_new ("org.gnome.desktop.screensaver");
  self->priv->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
  self->priv->notification_settings = g_settings_new ("org.gnome.desktop.notifications");
  self->priv->location_settings = g_settings_new ("org.gnome.system.location");

  add_screen_lock (self);
  add_location (self);
  add_usage_history (self);
  add_trash_temp (self);
  add_software (self);
  add_abrt (self);

  g_signal_connect (self->priv->lockdown_settings, "changed",
                    G_CALLBACK (on_lockdown_settings_changed), self);
  update_lock_screen_sensitivity (self);

  widget = WID ("privacy_vbox");
  gtk_container_add (GTK_CONTAINER (self), widget);
}
예제 #13
0
파일: cvs2sql.c 프로젝트: Rjoydip/libwww
int main (int argc, char ** argv)
{
    HTSQL *	sql = NULL;
    char *	sqlserver = DEFAULT_SQL_SERVER;
    char *	sqldb = DEFAULT_SQL_DB;
    char *	sqluser = DEFAULT_SQL_USER;
    char *	sqlpw = DEFAULT_SQL_PW;
    char *	cvsuser = DEFAULT_CVS_USER;
    time_t	cvsdate = -1;
    FILE * fin = stdin;
    char *	input_buffer[BUFSIZE];
    HTChunk *	loginfo = HTChunk_new(BUFSIZE);
    int		arg = 0;
    BOOL	create_db = YES;

    /* Initiate libwww */
    HTLibInit(APP_NAME, APP_VERSION);

    /* Scan command line for parameters */
    for (arg=1; arg<argc; arg++) {
        if (*argv[arg] == '-') {

            if (!strcmp(argv[arg], "-h") || !strcmp(argv[arg], "-?")) {
                VersionInfo();
                Cleanup(0, sql, loginfo);

            } else if (!strcmp(argv[arg], "-v")) {
                HTSetTraceMessageMask("q");

            } else if (!strcmp(argv[arg], "-nocreate")) {
                create_db = NO;

            } else if (!strncmp(argv[arg], "-sqldb", 5)) {
                sqldb = (arg+1 < argc && *argv[arg+1] != '-') ?
                        argv[++arg] : DEFAULT_SQL_DB;

            } else if (!strncmp(argv[arg], "-sqlpassword", 5)) {
                sqlpw = (arg+1 < argc && *argv[arg+1] != '-') ?
                        argv[++arg] : DEFAULT_SQL_PW;

            } else if (!strncmp(argv[arg], "-sqlserver", 5)) {
                sqlserver = (arg+1 < argc && *argv[arg+1] != '-') ?
                            argv[++arg] : DEFAULT_SQL_SERVER;

            } else if (!strncmp(argv[arg], "-sqluser", 5)) {
                sqluser = (arg+1 < argc && *argv[arg+1] != '-') ?
                          argv[++arg] : DEFAULT_SQL_USER;

            } else if (!strncmp(argv[arg], "-cvsuser", 5)) {
                cvsuser = (arg+1 < argc && *argv[arg+1] != '-') ?
                          argv[++arg] : DEFAULT_CVS_USER;

            } else if (!strncmp(argv[arg], "-cvsdate", 5)) {
                cvsdate = (arg+1 < argc && *argv[arg+1] != '-') ?
                          HTParseTime(argv[++arg], NULL, NO) : -1;

            } else {
                fprintf(stderr, "Bad Argument (%s)\n", argv[arg]);
            }
        } else {
            fprintf(stderr, "Bad Argument (%s)\n", argv[arg]);
        }
    }

    /* Get an SQL object */
    if ((sql = HTSQL_new(sqlserver, sqluser, sqlpw, 0)) == NULL)
        Cleanup(-1, sql, loginfo);

    /* Connect to the SQL server */
    if (HTSQL_connect(sql) != YES) Cleanup(-1, sql, loginfo);

    /* Select our database */
    if (HTSQL_selectDB(sql, sqldb) != YES) Cleanup(-1, sql, loginfo);

    /* Create our tables */
    if (create_db) createTables(sql, 0);

    /* Read the arguments from stdin */
    for (;;) {
        int status = fread(input_buffer, 1, BUFSIZE, fin);
        if (status < 0) Cleanup(-1, sql, loginfo);
        if (status == 0) break;
        HTChunk_putb(loginfo, (const char *) input_buffer, status);
    }

    /* Parse the input chunk */
    {
        char * ptr = HTChunk_data(loginfo);
        char * noop1 = HTNextField(&ptr);
        char * noop2 = HTNextField(&ptr);
        char * root = HTNextField(&ptr);
        char * operation = NULL;
        char * files = NULL;
        char * comment = NULL;
        int comment_id = -1;
        int user_id = -1;
        char * p, * q;
#ifdef HT_REENTRANT
        char *lasts;					     /* For strtok_r */
#endif

        /* Find shared log message and get id */
        if ((q = HTStrCaseStr(ptr, "\nLog Message:")) != NULL) {
            comment = q+14;
            *q = '\0';
        }
        if ((comment_id = add_comment(sql, comment)) < 0)
            Cleanup(-1, sql, loginfo);

        /* Add/find user and get id */
        if ((user_id = add_user(sql, cvsuser)) < 0)
            Cleanup(-1, sql, loginfo);

        /* For each operation, find the files involved */
        while ((q = HTStrCaseStr(ptr, " Files:")) != NULL) {

            /* Find the operation */
            files = q+9;
            for (p=q; p>HTChunk_data(loginfo) && *p && *p!='\n'; p--);
            p++;
            operation = HTNextField(&p);

            /* Find the next line */
            if ((q = strchr(files, '\n')) != NULL) {
                *q++ = '\0';
                ptr = q;
            }

            /* Create the query */
            if (operation && files && comment) {
                char * file;
                int location_id = -1;

#ifdef HT_REENTRANT
                if ((file = strtok_r(files, DELIMITERS, &lasts)) != NULL) {
#else
                if ((file = strtok(files, DELIMITERS)) != NULL) {
#endif /* HT_REENTRANT */
                    do {
                        char * path = NULL;
                        StrAllocMCopy(&path, root, "/", file, NULL);

                        /* Add/find location and get id */
                        if ((location_id = add_location(sql, path)) < 0) {
                            Cleanup(-1, sql, loginfo);
                            break;
                        }

#if 0
                        fprintf(stderr, "location: `%s\', user: `%s\', operation: `%s\', comment: `%s\'\n",
                                path, cvsuser, operation, comment);
#endif

                        /* Add log entry */
                        {
                            char buf[16384];
                            char * query = HTSQL_printf(buf, 16384, "insert into %s values (%u,%u,%T,%S,%u)",
                                                        DEFAULT_SQL_LOG_TABLE,
                                                        location_id,
                                                        user_id,
                                                        cvsdate,
                                                        operation,
                                                        comment_id);
                            if (HTSQL_query(sql, query) != YES) {
                                Cleanup(-1, sql, loginfo);
                                break;
                            }
                        }

                        HT_FREE(path);
#ifdef HT_REENTRANT
                    } while ((file = (char *) strtok_r(NULL, DELIMITERS, &lasts)) != NULL);
#else
                    }
                    while ((file = strtok(NULL, DELIMITERS)) != NULL);
#endif /* HT_REENTRANT */
                }
            }
        }
    }

    return 0;
}
예제 #14
0
/* Params: 
 *   str1 - as unsigned int - can be CPL_RUN_INCOMING or CPL_RUN_OUTGOING 
 *   str2 - as unsigned int - flags regarding state(less)|(ful) 
 *   str3 - URI in SPVE structure
 */
static int cpl_invoke_script3(struct sip_msg* msg, char* str1, char* str2, char *str3)
{
	struct cpl_interpreter  *cpl_intr;
	str  username = {0,0};
	str  domain = {0,0};
	str  uri = {0,0};
	sip_uri_t puri;
	str  loc;
	str  script;

	/* get the user_name */
	if(str3==NULL) {
		if ( ((unsigned long)str1)&CPL_RUN_INCOMING ) {
			/* if it's incoming -> get the destination user name */
			if (get_dest_user( msg, &username, &domain)==-1)
				goto error0;
		} else {
			/* if it's outgoing -> get the origin user name */
			if (get_orig_user( msg, &username, &domain)==-1)
				goto error0;
		}
	} else {
		if(fixup_get_svalue(msg, (gparam_p)str3, &uri)!=0)
		{
			LM_ERR("invalid uri parameter");
			goto error0;
		}
		if (parse_uri(uri.s, uri.len, &puri) || !puri.user.len) {
			LM_ERR("unable to extract user name from URI param\n");
			return -1;
		}
		username = puri.user;
		domain = puri.host;
	}

	/* get the script for this user */
	if (get_user_script(&username, cpl_env.use_domain?&domain:0,
	&script, &cpl_bin_col)==-1)
		goto error0;

	/* has the user a non-empty script? if not, return normally, allowing the
	 * script execution to continue */
	if ( !script.s || !script.len )
		return 1;

	/* build a new script interpreter */
	if ( (cpl_intr=new_cpl_interpreter(msg,&script))==0 )
		goto error1;
	/* set the flags */
	cpl_intr->flags =(unsigned int)((unsigned long)str1)|((unsigned long)str2);
	/* build user AOR */
	if (build_user_AOR( &username, &domain, &(cpl_intr->user), 0)!=0 )
		goto error2;
	/* for OUTGOING we need also the destination user for init. with him
	 * the location set */
	if ( ((unsigned long)str1)&CPL_RUN_OUTGOING ) {
		/* build user initial location -> get the destination user name */
		if (get_dest_user( msg, &username, &domain)==-1)
			goto error2;
		if (build_user_AOR( &username, &domain, &loc, 1)!=0 )
			goto error2;
		if (add_location( &(cpl_intr->loc_set), &loc, 0, 10, 0/*no dup*/)==-1)
			goto error2;
	}

	/* run the script */
	switch (cpl_run_script( cpl_intr )) {
		case SCRIPT_DEFAULT:
			free_cpl_interpreter( cpl_intr );
			return 1; /* execution of ser's script will continue */
		case SCRIPT_END:
			free_cpl_interpreter( cpl_intr );
		case SCRIPT_TO_BE_CONTINUED:
			return 0; /* break the SER script */
		case SCRIPT_RUN_ERROR:
		case SCRIPT_FORMAT_ERROR:
			goto error2;
	}

	return 1;
error2:
	free_cpl_interpreter( cpl_intr );
	return -1;
error1:
	shm_free(script.s);
error0:
	return -1;
}
예제 #15
0
/* Params:
 *   str1 - as unsigned int - can be CPL_RUN_INCOMING or CPL_RUN_OUTGOING
 *   str2 - as unsigned int - flags regarding state(less)|(ful)
 */
static int cpl_invoke_script(struct sip_msg* msg, char* str1, char* str2)
{
	struct cpl_interpreter  *cpl_intr;
	str  user;
	str  loc;
	str  script;

	/* get the user_name */
	if ( ((unsigned long)str1)&CPL_RUN_INCOMING ) {
		/* if it's incoming -> get the destination user name */
		if (get_dest_user( msg, &user, BUILD_UH_SHM)==-1)
			goto error0;
	} else {
		/* if it's outgoing -> get the origin user name */
		if (get_orig_user( msg, &user, BUILD_UH_SHM)==-1)
			goto error0;
	}

	/* get the script for this user */
	if (get_user_script(&user, &script, 1)==-1)
		goto error1;

	/* has the user a non-empty script? if not, return normally, allowing ser to
	 * continue its script */
	if ( !script.s || !script.len ) {
		shm_free(user.s);
		return 1;
	}

	/* build a new script interpreter */
	if ( (cpl_intr=new_cpl_interpreter(msg,&script))==0 )
		goto error2;
	/* set the flags */
	cpl_intr->flags =(unsigned int)((unsigned long)str1)|((unsigned long)str2);
	/* attache the user */
	cpl_intr->user = user;
	/* for OUTGOING we need also the destination user for init. with him
	 * the location set */
	if ( ((unsigned long)str1)&CPL_RUN_OUTGOING ) {
		if (get_dest_user( msg, &loc,BUILD_UH_ADDSIP)==-1)
			goto error3;
		if (add_location( &(cpl_intr->loc_set), &loc,10,CPL_LOC_DUPL)==-1)
			goto error3;
	}

	/* since the script interpretation can take some time, it will be better to
	 * send a 100 back to prevent the UAC to retransmit
	if ( cpl_tmb.t_reply( msg, (int)100, "Running cpl script" )!=1 ) {
		LOG(L_ERR,"ERROR:cpl_invoke_script: unable to send 100 reply!\n");
		goto error3;
	}
	* this should be done from script - it's much sooner ;-) */

	/* run the script */
	switch (cpl_run_script( cpl_intr )) {
		case SCRIPT_DEFAULT:
			free_cpl_interpreter( cpl_intr );
			return 1; /* execution of ser's script will continue */
		case SCRIPT_END:
			free_cpl_interpreter( cpl_intr );
		case SCRIPT_TO_BE_CONTINUED:
			return 0; /* break the SER script */
		case SCRIPT_RUN_ERROR:
		case SCRIPT_FORMAT_ERROR:
			goto error3;
	}

	return 1;
error3:
	free_cpl_interpreter( cpl_intr );
	return -1;
error2:
	shm_free(script.s);
error1:
	shm_free(user.s);
error0:
	return -1;
}