Exemple #1
0
static void
ch_remove_tempfiles(char *suffix, int count)
{
	char name[256];
	int i;

	for (i = 0 ; i <= count ; i++) {
		sprintf(name,"graph_%d",i);
		tempfile_unlink(suffix, name);
	}
}
Exemple #2
0
static void session_free(struct session *session)
{
	g_free(session->url);
	if( session->laddr )
		g_free(session->laddr);
	switch( session->type )
	{
	case session_type_download:
		if( session->action.download.file )
		{
			tempfile_unlink(session->action.download.file);
			tempfile_free(session->action.download.file);
			session->action.download.file = NULL;
			if( session->action.download.ctxcon != NULL )
				connection_unref(session->action.download.ctxcon);
		}
		break;

	case session_type_upload:
		curl_formfree(session->action.upload.formpost);
		curl_slist_free_all(session->action.upload.headers);
		if( session->action.upload.username != NULL )
			g_free(session->action.upload.username);
		if( session->action.upload.password != NULL )
			g_free(session->action.upload.password);
		if( session->action.upload.callback != NULL )
			g_free(session->action.upload.callback);
		if( session->action.upload.userdata != NULL )
			g_free(session->action.upload.userdata);
		if( session->action.upload.file != NULL )
			tempfile_free(session->action.upload.file);
		break;
	}


	g_free(session);

}
Exemple #3
0
static GList *
process_boundaries_finish(GList *boundaries_list)
{
	//fprintf(stderr,"process_boundaries_finish:001\n");

	GList *l, *sl, *l2, *ln;
	GList *ret = NULL;
	l = boundaries_list;
	char *f1_name = NULL;
	char *f2_name = NULL;
	long long b_counter_1 = 0;
	long long nodes_counter_ = 0;
	long long ways_counter_ = 0;

	while (l)
	{
		struct boundary *boundary = l->data;
		int first = 1;
		FILE *f = NULL, *fu = NULL;

		b_counter_1++;
		if ((b_counter_1 % 500) == 0)
		{
			fprintf(stderr,"boundaries_f1:B:%lld\n", b_counter_1);
		}

		//fprintf(stderr,"process_boundaries_finish:002\n");

		// only lowercase country code
		if (boundary->iso2)
		{
			int i99;
			for (i99 = 0; boundary->iso2[i99]; i99++)
			{
				boundary->iso2[i99] = tolower(boundary->iso2[i99]);
			}
		}
		// only lowercase country code

		if (boundary->country)
		{
			//fprintf(stderr,"process_boundaries_finish:003\n");

			char *name = g_strdup_printf("country_%s_poly", boundary->iso2);
			f1_name = g_strdup_printf("country_%s_poly", boundary->iso2);
			f = tempfile("", name, 1);
			g_free(name);
		}



		// calc bounding box
		first = 1;
		nodes_counter_ = 0;
		ways_counter_ = 0;
		sl = boundary->segments;
		while (sl)
		{
			struct geom_poly_segment *gs = sl->data;
			struct coord *c = gs->first;
			while (c <= gs->last)
			{
				if (first)
				{
					boundary->r.l = *c;
					boundary->r.h = *c;
					first = 0;
				}
				else
				{
					bbox_extend(c, &boundary->r);
				}
				c++;
				nodes_counter_++;
			}
			sl = g_list_next(sl);
			ways_counter_++;
		}

		//fprintf(stderr, "relid:%lld\n", item_bin_get_relationid(boundary->ib));
		//fprintf(stderr, "ways:%lld nodes:%lld\n", ways_counter_, nodes_counter_);

		boundary->sorted_segments = geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side);
		sl = boundary->sorted_segments;

		first = 1;
		while (sl)
		{
			//fprintf(stderr,"process_boundaries_finish:004.1\n");

			struct geom_poly_segment *gs = sl->data;
			struct coord *c = gs->first;

			/*
			while (c <= gs->last)
			{
				if (first)
				{
					boundary->r.l = *c;
					boundary->r.h = *c;
					first = 0;
				}
				else
				{
					bbox_extend(c, &boundary->r);
				}
				c++;

				//fprintf(stderr,"process_boundaries_finish:004.2 lx=%d ly=%d hx=%d hy=%d\n",boundary->r.l.x,boundary->r.l.y,boundary->r.h.x,boundary->r.h.y);

			}
			*/

			if (f)
			{
				struct item_bin *ib = item_bin_2;
				item_bin_init(ib, type_selected_line);
				item_bin_add_coord(ib, gs->first, gs->last - gs->first + 1);
				item_bin_write(ib, f);
			}

			if (boundary->country)
			{
				if (!coord_is_equal(*gs->first, *gs->last))
				{
					if (!fu)
					{
						char *name = g_strdup_printf("country_%s_broken", boundary->iso2);
						f2_name = g_strdup_printf("country_%s_broken", boundary->iso2);
						fprintf(stderr, "*BROKEN* country_%s_broken\n", boundary->iso2);
						fu = tempfile("", name, 1);
						g_free(name);
					}
					struct item_bin *ib = item_bin_2;
					item_bin_init(ib, type_selected_point);
					item_bin_add_coord(ib, gs->first, 1);
					item_bin_write(ib, fu);

					item_bin_init(ib, type_selected_point);
					item_bin_add_coord(ib, gs->last, 1);
					item_bin_write(ib, fu);
				}
			}
			sl = g_list_next(sl);

			if (f2_name)
			{
				tempfile_unlink("", f2_name);
				g_free(f2_name);
				f2_name = NULL;
			}
		}

		ret = process_boundaries_insert(ret, boundary);
		l = g_list_next(l);

		if (f)
		{
			fclose(f);
		}

		if (fu)
		{
			if (boundary->country)
			{
				//osm_warning("relation", item_bin_get_relationid(boundary->ib), 0, "Broken country polygon '%s'\n", boundary->iso2);
				fprintf(stderr, "*BROKEN* country polygon '%s' relid=%lld\n", boundary->iso2, item_bin_get_relationid(boundary->ib));
			}
			fclose(fu);
		}

		if (f1_name)
		{
			tempfile_unlink("", f1_name);
			g_free(f1_name);
			f1_name = NULL;
		}
	}
#if 0
	printf("hierarchy\n");
#endif

	// boundaries_list = g_list_sort(boundaries_list, boundary_bbox_compare); // disable sorting, does not seem to do any good

// children stuff totally broken!!!
#if 0
	b_counter_1 = 0;
	l = boundaries_list;
	while (l)
	{
		b_counter_1++;
		if ((b_counter_1 % 500) == 0)
		{
			fprintf(stderr,"boundaries_f2:B:%lld\n", b_counter_1);
		}

		struct boundary *boundary = l->data;
		ln = l2 = g_list_next(l);
		while (l2)
		{
			struct boundary *boundary2 = l2->data;
			if (bbox_contains_bbox(&boundary2->r, &boundary->r))
			{
				boundaries_list = g_list_remove(boundaries_list, boundary);
				boundary2->children = g_list_append(boundary2->children, boundary);
				break;
			}
			l2 = g_list_next(l2);
		}
		l = ln;
	}
#endif
// children stuff totally broken!!!

	// -- DEBUG --
	// -- DEBUG --
	// -- DEBUG --
	// dump_hierarchy(boundaries_list,""); // --> prints huge amounts of data!! be careful
	// -- DEBUG --
	// -- DEBUG --
	// -- DEBUG --

	return boundaries_list;
}
Exemple #4
0
void emulate_ctx_free(void *data)
{
	struct emu_emulate_ctx *ctx = data;

	GHashTableIter iter;
	gpointer key, value;

	g_hash_table_iter_init (&iter, ctx->files);
	while( g_hash_table_iter_next (&iter, &key, &value) )
	{
		g_debug("file key %p %i value %p \n", key, *(int *)key, value);
		struct tempfile *tf = value;
		if( tf->fh == NULL )
		{ /* file was closed by shellcode */
			struct incident *i = incident_new("dionaea.download.complete");
			incident_value_string_set(i, "path", g_string_new(tf->path));
			if( ctx->ctxcon )
				incident_value_con_set(i, "con", ctx->ctxcon);
			incident_value_string_set(i, "url", g_string_new("emulate://"));
			incident_report(i);
			incident_free(i);
		}else
			tempfile_close(tf);
		tempfile_unlink(tf);
		tempfile_free(tf);
	}
	g_hash_table_destroy(ctx->files);

	g_hash_table_iter_init (&iter, ctx->processes);
	while( g_hash_table_iter_next (&iter, &key, &value) )
	{
		g_debug("process key %p %i value %p \n", key, *(int *)key, value);
	}
	g_hash_table_destroy(ctx->processes);

	g_hash_table_iter_init (&iter, ctx->sockets);
	while( g_hash_table_iter_next (&iter, &key, &value) )
	{
		struct connection *con = value;
		g_debug("connection key %p %i value %p type %s state %s socket %i\n", key, *(int *)key, value, 
				connection_type_to_string(con->type),
				connection_state_to_string(con->state),
				con->socket);
		if( con->socket != -1 )
		{/* avoid callbacks from connection_close() */
			close(con->socket);
			con->socket = -1;
		}

		g_free(key);

		con->protocol.ctx = NULL;
		con->events.free.repeat = .5;
		connection_free(con);
	}
	g_hash_table_destroy(ctx->sockets);

	if( ctx->time != NULL )
		g_timer_destroy(ctx->time);

	emu_free(ctx->emu);
	emu_env_free(ctx->env);
	g_mutex_clear(&ctx->mutex);
	if( ctx->ctxcon != NULL )
		connection_unref(ctx->ctxcon);
	g_free(ctx);
}
Exemple #5
0
/* Check for completed transfers, and remove their easy handles */
static void check_run_count(void)
{
	g_debug("%s queued %i active %i", __PRETTY_FUNCTION__, curl_runtime.queued, curl_runtime.active);
	if( curl_runtime.queued > curl_runtime.active )
	{
		char *eff_url=NULL;
		CURLMsg *msg;
		int msgs_left;
		struct session *session=NULL;
		CURL*easy;

		g_debug("REMAINING: %d", curl_runtime.queued);
		easy=NULL;
		while( (msg = curl_multi_info_read(curl_runtime.multi, &msgs_left)) )
		{
			if( msg->msg == CURLMSG_DONE )
			{
				curl_runtime.queued--;

				easy=msg->easy_handle;
				curl_easy_getinfo(easy, CURLINFO_PRIVATE, (char **)&session );
				curl_easy_getinfo(easy, CURLINFO_EFFECTIVE_URL, &eff_url);

				switch( session->type )
				{
				case session_type_download:
					if( msg->data.result == CURLE_OK )
					{
						g_info("DOWNLOAD DONE: %s => (%d) %s", eff_url, msg->data.result, session->error);
						tempfile_close(session->action.download.file);

						struct incident *i = incident_new("dionaea.download.complete");
						incident_value_string_set(i, "path", g_string_new(session->action.download.file->path));
						incident_value_string_set(i, "url", g_string_new(session->url));
						if( session->action.download.ctxcon )
							incident_value_con_set(i, "con", session->action.download.ctxcon);

						incident_report(i);
						incident_free(i);
					} else
					{
						g_warning("DOWNLOAD FAIL: %s => (%d) %s", eff_url, msg->data.result, session->error);
						tempfile_close(session->action.download.file);
					}
					break;

				case session_type_upload:
					if( msg->data.result == CURLE_OK )
					{
						g_info("UPLOAD DONE: %s => (%d) %s", eff_url, msg->data.result, session->error);

						if( session->action.upload.callback == NULL )
							break;
						
						tempfile_close(session->action.upload.file);
						// if we have a callback, call the callback
						struct incident *i = incident_new(session->action.upload.callback);
						incident_value_string_set(i, "path", g_string_new(session->action.upload.file->path));
						if( session->action.upload.userdata != NULL )
							incident_value_string_set(i, "_userdata", g_string_new(session->action.upload.userdata));
						incident_report(i);
						incident_free(i);
						tempfile_unlink(session->action.upload.file);
					} else
					{
						g_warning("UPLOAD FAIL: %s => (%d) %s", eff_url, msg->data.result, session->error);

						if( session->action.upload.callback == NULL )
							break;

						tempfile_close(session->action.upload.file);
						tempfile_unlink(session->action.upload.file);
					}
					break;
				}

				curl_multi_remove_handle(curl_runtime.multi, easy);
				curl_easy_cleanup(easy);
				session_free(session);
			}
		}
	}
}