Exemplo n.º 1
0
/* Retrieves the task specification and initializes the agent with it.
* Then it gets the agent name, cleans it and sends it to the environment.
*/
int performInit(int sd, int argc, const char* agent_params[])
{
  const char* agent_name;
  char* clean_agent_name;
  // Send Get_TASK command
  int rc = sendTokenOnSocket(sd, CMD_GETTASK);

  // Retrieve the number of states and actions
  if(rc >= 0) rc = getIntFromSocket(sd, &numStates);
  if(rc >= 0) rc = getIntFromSocket(sd, &numActions);
  if(rc >= 0) rc = agent_init(numStates, numActions, argc, agent_params);
  if(rc >= 0)
  {
    agent_name = agent_get_name();
    if(!agent_name) agent_name = "Unnamed";
    clean_agent_name = strdup(agent_name);
    clean_name(clean_agent_name);
    // Send START_LOG command and the agent name
    rc = sendTokenOnSocket(sd, CMD_STARTLOG);
    if(rc >= 0) rc = sendTokenOnSocket(sd, clean_agent_name);
    free(clean_agent_name);
  }

  return rc;
}
Exemplo n.º 2
0
 result_type operator()( const T& dummy )
 {
    assert( which == m.which_to_name.size() );
    std::string name = clean_name( fc::get_typename<T>::name() );
    m.name_to_which[ name ] = which;
    m.which_to_name.push_back( name );
 }
Exemplo n.º 3
0
/**
 *
 * It dumps attachments to /tmp
 *
 **/
void
util_attachments_to_files(CamelMimeMessage *message) {
   gint parts, i = 0;

   char *store_dir;
   CamelDataWrapper *content = NULL;

   content = camel_medium_get_content_object((CamelMedium *) message);
   if (!content || !CAMEL_IS_MULTIPART(content))
      return;

   parts = camel_multipart_get_number(CAMEL_MULTIPART(content));
   if (parts < 1)
      return;

   store_dir = "/tmp"; // TODO home

   for (i = 1; i < parts; i++) {
      gchar *filename = NULL;
      gchar *path = NULL;
      gchar *tmp = NULL;
      const gchar *orig_filename = NULL;
      CamelMimePart *mime_part = camel_multipart_get_part(CAMEL_MULTIPART(content), i);

      orig_filename = camel_mime_part_get_filename(mime_part);
      g_debug("Orig filename : %s\n", orig_filename);
      if (orig_filename == NULL) {
         g_print("Esto es un adjunto distinto.");
         orig_filename = camel_mime_part_get_description(mime_part);
      }
      if (!orig_filename)
         continue;

      tmp = clean_name((const guchar *) orig_filename);

      filename = g_strdup_printf("%s-%s", "evosugar", tmp);
      path = g_build_filename(store_dir, filename, NULL);
      g_debug("Attach. to file : %s\n", path);
      BREAKPOINT;
      // TODO should be done in another thread
      if (em_utils_save_part_to_file(NULL, path, mime_part)) {
         gchar *uri;
         BREAKPOINT;
         uri = g_filename_to_uri(path, NULL, NULL);
         BREAKPOINT;
         g_free(uri);
      }
      BREAKPOINT;
      g_free(tmp);
      BREAKPOINT;
      g_free(filename);
      BREAKPOINT;
      g_free(path);
      BREAKPOINT;
   }

   //g_free (store_dir);
}
Exemplo n.º 4
0
		// clean messy text coming from the writers
		void clean()
		{
			if( !cleaned ) {
				clean_name();
				clean_log_text();
				clean_path();
				
				cleaned = true;
			}
		}
Exemplo n.º 5
0
Arquivo: clidfs.c Projeto: ekohl/samba
static void cli_set_mntpoint(struct cli_state *cli, const char *mnt)
{
	char *name = clean_name(NULL, mnt);
	if (!name) {
		return;
	}
	TALLOC_FREE(cli->dfs_mountpoint);
	cli->dfs_mountpoint = talloc_strdup(cli, name);
	TALLOC_FREE(name);
}
Exemplo n.º 6
0
static void cli_set_mntpoint(struct cli_state *cli, const char *mnt)
{
	TALLOC_CTX *frame = talloc_stackframe();
	char *name = clean_name(frame, mnt);
	if (!name) {
		TALLOC_FREE(frame);
		return;
	}
	TALLOC_FREE(cli->dfs_mountpoint);
	cli->dfs_mountpoint = talloc_strdup(cli, name);
	TALLOC_FREE(frame);
}
Exemplo n.º 7
0
static void cli_cm_set_mntpoint( struct cli_state *c, const char *mnt )
{
	struct client_connection *p;
	int i;

	for ( p=connections,i=0; p; p=p->next,i++ ) {
		if ( strequal(p->cli->desthost, c->desthost) && strequal(p->cli->share, c->share) )
			break;
	}
	
	if ( p ) {
		pstrcpy( p->mount, mnt );
		clean_name(p->mount);
	}
}
Exemplo n.º 8
0
char *tf_resource(const char *rel) {
  char *nb;
  if (!rel) return NULL;
  if (*rel == '/') {
    nb = tf_strdup(rel);
  }
  else {
    char *bd = tf_base_dir();
    size_t bl = strlen(bd);
    size_t rl = strlen(rel);
    nb = tf_alloc(bl + rl + 1);
    memcpy(nb, bd, bl);
    memcpy(nb + bl, rel, rl + 1);
  }
  clean_name(nb);
  return nb;
}
Exemplo n.º 9
0
/* ********************************************************************* */
int clean_name(char *name)
{
   int len = strlen(name);
   char *tname = (char *) calloc(len+1, sizeof(char));
   if(tname == NULL)
   {
      eprintf("\n ERROR: memory allocation error");
      return(FAIL);
   }
   strcpy(tname, name);
   if(clean_name(tname, name)!= OK)
   {
      eprintf("\n ERROR: cleaning Name");
      return(FAIL);
   }
   free(tname);
   return(OK);
}
Exemplo n.º 10
0
static void
do_ForEachFile(
	const Fchar *fn,
	void (*proc)(const Fchar *, const char *, const struct stat *),
	int max_depth
) {
	Fchar fname[MAX_FILE_NAME_LENGTH];
	Fchar separator;

	Fnamecpy(fname, (!fn || !*fn) ? str2Fname(".") : fn);
	separator = get_separator(fname);
	if (!separator) {
		(*proc)(fname, "both / and \\ used as separators", 0);
		return;
	}

	clean_name(fname, separator);
	do_FEF(fname, proc, -1, (struct ino_link *)0, separator, max_depth);
}
Exemplo n.º 11
0
static char *abs_name(char *name) {
  if (!name) tf_die("name == NULL");
  char *nb;
  if (name[0] == '/') {
    nb = tf_strdup(name);
  }
  else {
    char cwd[1024];
    if (!getcwd(cwd, sizeof(cwd))) abort();
    size_t nlen = strlen(name);
    size_t clen = strlen(cwd);
    size_t len = clen + nlen + 2;
    nb = tf_alloc(len);
    memcpy(nb, cwd, clen);
    nb[clen] = '/';
    memcpy(nb + clen + 1, name, nlen + 1);
  }
  clean_name(nb);
  return nb;
}
Exemplo n.º 12
0
static void task_state_process_state_process(struct ltt_module *mod,
                                             struct parse_result *res, int pass)
{
    char *s;
    uint32_t pid, parent_pid, type, mode, submode, status, tgid;

    if (sscanf(res->values, " pid = %d, parent_pid = %d, name = \"%m[^\"]\", "
               "type = %d, mode = %d, submode = %d, status = %d, tgid = %d",
               &pid, &parent_pid, &s, &type, &mode, &submode, &status,
               &tgid) != 8) {
        PARSE_ERROR(mod, res->values);
        return;
    }
	if (pass == 1) {
		find_or_add_task_trace(clean_name(s), pid, tgid)/*[0].group = 0*/;
	}
    if (pass == 2) {
        //XXX
		if (status == 1) 
        	emit_trace(find_task_trace(pid), (union ltt_value)LT_S0);
    }
	free(s);
}
Exemplo n.º 13
0
/* do a single node status */
static bool do_node_status(struct nbt_name_socket *nbtsock,
			   const char *addr, uint16_t port)
{
	struct nbt_name_status io;
	NTSTATUS status;

	io.in.name.name = "*";
	io.in.name.type = NBT_NAME_CLIENT;
	io.in.name.scope = NULL;
	io.in.dest_addr = addr;
	io.in.dest_port = port;
	io.in.timeout = 1;
	io.in.retries = 2;

	status = nbt_name_status(nbtsock, nbtsock, &io);
	if (NT_STATUS_IS_OK(status)) {
		int i;
		printf("Node status reply from %s\n",
		       io.out.reply_from);
		for (i=0;i<io.out.status.num_names;i++) {
			d_printf("\t%-16s <%02x>  %s\n", 
				 clean_name(nbtsock, io.out.status.names[i].name),
				 io.out.status.names[i].type,
				 node_status_flags(nbtsock, io.out.status.names[i].nb_flags));
		}
		printf("\n\tMAC Address = %02X-%02X-%02X-%02X-%02X-%02X\n",
		       io.out.status.statistics.unit_id[0],
		       io.out.status.statistics.unit_id[1],
		       io.out.status.statistics.unit_id[2],
		       io.out.status.statistics.unit_id[3],
		       io.out.status.statistics.unit_id[4],
		       io.out.status.statistics.unit_id[5]);
		return true;
	}

	return false;
}
Exemplo n.º 14
0
static void
fill_model_rec(CamelMimeMessage *msg, CamelMimePart *part, GtkTreeStore *model, GtkTreeIter *parent, GString *name)
{
	CamelDataWrapper *containee;
	int parts, i;
	char *type;
	GtkTreeIter iter;
	int len = name->len;
	CamelContentType *mime;

	containee = camel_medium_get_content_object((CamelMedium *)part);
	if (containee == NULL)
		return;

	mime = ((CamelDataWrapper *)containee)->mime_type;
	type = camel_content_type_simple(mime);

	if (CAMEL_IS_MULTIPART(containee)) {
		gtk_tree_store_append(model, &iter, parent);
		g_string_append_printf(name, ".multipart");
		gtk_tree_store_set(model, &iter, 0, FALSE, 1, type, 2, name->str, 3, name->str, 4, part, -1);

		parts = camel_multipart_get_number((CamelMultipart *)containee);
		for (i = 0; i < parts; i++) {
			CamelMimePart *mpart = camel_multipart_get_part((CamelMultipart *)containee, i);

			g_string_truncate(name, len);
			g_string_append_printf(name, ".%d", i);
			fill_model_rec(msg, mpart, model, &iter, name);
		}
	} else if (CAMEL_IS_MIME_MESSAGE(containee)) {
		gtk_tree_store_append(model, &iter, parent);
		g_string_append_printf(name, ".msg");
		gtk_tree_store_set(model, &iter, 0, FALSE, 1, type, 2, name->str, 3, name->str, 4, part, -1);
		fill_model_rec(msg, (CamelMimePart *)containee, model, &iter, name);
	} else {
		char *filename = NULL;
		const char *ext = NULL, *tmp;
		int save = FALSE;

		gtk_tree_store_append(model, &iter, parent);
		tmp = camel_mime_part_get_filename(part);
		if (tmp) {
			filename = clean_name(tmp);
			ext = strrchr(filename, '.');
		}
		tmp = camel_mime_part_get_disposition(part);
		if (tmp && !strcmp(tmp, "attachment"))
			save = TRUE;

		if (camel_content_type_is(mime, "text", "*")) {
			if (ext == NULL) {
				if ((ext = mime->subtype) == NULL || !strcmp(ext, "plain"))
					ext = "text";
			}
		} else if (camel_content_type_is(mime, "image", "*")) {
			if (ext == NULL) {
				if ((ext = mime->subtype) == NULL)
					ext = "image";
			}
			save = TRUE;
		}

		g_string_append_printf(name, ".%s", ext);
		gtk_tree_store_set(model, &iter, 0, save, 1, type, 2, filename?filename:name->str, 3, filename?NULL:name->str, 4, part, -1);
		g_free(filename);
	}
	g_free(type);

	g_string_truncate(name, len);
}
Exemplo n.º 15
0
gboolean
foreach_func_rel_attachments(GtkTreeModel *model,
      GtkTreePath *path,
      GtkTreeIter *iter,
      gchar *email_id) {

   gboolean on;
   gchar *name;

   BREAKPOINT;

   gtk_tree_model_get(model, iter, 0, &on, 1, &name, -1);
   if (on) {
      BREAKPOINT;
      struct ns1__note_USCOREattachment note;
      struct name_USCOREvalue_USCORElist list;
      list.__size = 2;
      list.__ptr = malloc((list.__size) * sizeof (struct ns1__name_USCOREvalue));
      list.__ptr[0] = (struct ns1__name_USCOREvalue*) malloc(sizeof (struct ns1__name_USCOREvalue));
      list.__ptr[0]->name = "name";
      list.__ptr[0]->value = name;
      list.__ptr[1] = (struct ns1__name_USCOREvalue*) malloc(sizeof (struct ns1__name_USCOREvalue));
      list.__ptr[1]->name = "description";
      list.__ptr[1]->value = "Imported from evosugar";
      BREAKPOINT;

      g_debug("Linkando mail\n");
      BREAKPOINT;
      char *id = scrm_set_entry(gconf_get_server(), scrm_session.id, &list, "Notes");
      BREAKPOINT;
      GError *gerror;

      BREAKPOINT;
      g_debug("Name : %s\n", name);
      if (name != NULL) { // TODO might be bug because of buggy attachment parsing
         gchar *full_filename = g_build_filename("/tmp", g_strdup_printf("%s-%s", "evosugar", clean_name(name)), NULL);
         BREAKPOINT;
         g_debug("HH");
         g_debug("FULL FILENAME %s\n", full_filename);
         /*
            GMappedFile *gmappedfile = g_mapped_file_new(full_filename,
            FALSE, &gerror);
            */
         BREAKPOINT;
         //g_print("Resultado de la lectura %d \n", gerror.code);
         //gchar *str_file = g_mapped_file_get_contents(gmappedfile);
         gchar *str_file;
         //g_print("BLOB %s \n", str_file);
         BREAKPOINT;
         //gsize *size_file = g_mapped_file_get_length(gmappedfile);
         //g_print("MIDE :... %s\n",size_file);

         gsize size_file;
         gboolean ok = g_file_get_contents(full_filename, &str_file, &size_file, &gerror);
         g_debug("Lectura con exito : %d \n", ok);
         struct ns1__note_USCOREattachment note_attach;
         note_attach.filename = name;
         note_attach.id = id;
         BREAKPOINT;
         note_attach.file = g_base64_encode(str_file, size_file);
         char *response_id = set_note_attachment(gconf_get_server(), scrm_session.id,
               &note_attach);

         //g_debug("note id %s \n", response_id);

         relate_note_to_module(gconf_get_server(), scrm_session.id, response_id, "Emails", email_id);
         unlink(full_filename); // delete file
      }
      return 0;

   }


   return FALSE; /* do not stop walking the store, call us with next row */
}
Exemplo n.º 16
0
	void _Log::clean(){
		clean_name();
		clean_log_text();
		clean_image_path();
		clean_sound_path();
	}
Exemplo n.º 17
0
int main(int argc, char *argv[])
{
	FILE *ipf, *opf;
	char *lname, *uname;
	int ch, col;

	/* Check the command line */
	if (argc != 3) 
	{
		fprintf(stderr, "Usage:\n\n%s <input file> <output file>\n", argv[0]);
		exit(1);
	}

	/* Open the input and output files */
	ipf = fopen(argv[1], "rb");
	if (!ipf) 
	{
		fprintf(stderr, "Failed to open input file: %s\n", argv[1]);
		exit(1);
	}

	opf = fopen(argv[2], "wb");
	if (!opf) 
	{
		fprintf(stderr, "Failed to open input file: %s\n", argv[1]);
		exit(1);
	}

	// Get the inclusion guard and variable base names
	lname = clean_name(get_filename(argv[1]));
	uname = to_upper(lname);

	fprintf(opf, "#ifndef %s_H\n", uname);
	fprintf(opf, "#define %s_H\n\n", uname);
	
	fprintf(opf, "static const unsigned char %s_data[] = {\n", lname);

	/* Loop through each input byte and write it to the vector   */
	/* Stick a \n in once we get to a suitable point (8 bytes). */
	col = 1;
	while ((ch = fgetc(ipf)) != EOF) 
	{
		if (col >= 48) 
		{
			fputc('\n', opf);
			col = 1;
		}
		fprintf(opf, "0x%.2x, ", ch);
		col += 6;
 
	}
	fprintf(opf, "\n");
	fprintf(opf, "};\n\n");

	/* wxImage accessor */
	fprintf(opf, "#include \"wx/mstream.h\"\n\n");
	fprintf(opf, "static wxImage *%s_img()\n", lname);
	fprintf(opf, "{\n");
	fprintf(opf, "	if (!wxImage::FindHandler(wxT(\"PNG file\")))\n");
	fprintf(opf, "		wxImage::AddHandler(new wxPNGHandler());\n");
	fprintf(opf, "	static wxImage *img_%s = new wxImage();\n", lname);
	fprintf(opf, "	if (!img_%s || !img_%s->IsOk())\n", lname, lname);
	fprintf(opf, "	{\n");
	fprintf(opf, "		wxMemoryInputStream img_%sIS(%s_data, sizeof(%s_data));\n", lname, lname, lname);
	fprintf(opf, "		img_%s->LoadFile(img_%sIS, wxBITMAP_TYPE_PNG);\n", lname, lname);
	fprintf(opf, "	}\n");
	fprintf(opf, "	return img_%s;\n", lname);
	fprintf(opf, "}\n");
	fprintf(opf, "#define %s_img %s_img()\n\n", lname, lname);

	/* wxBitmap accessor */
	fprintf(opf, "static wxBitmap *%s_bmp()\n", lname);
	fprintf(opf, "{\n");
	fprintf(opf, "	static wxBitmap *bmp_%s;\n", lname);
	fprintf(opf, "	if (!bmp_%s || !bmp_%s->IsOk())\n", lname, lname);
	fprintf(opf, "		bmp_%s = new wxBitmap(*%s_img);\n", lname, lname);
	fprintf(opf, "	return bmp_%s;\n", lname);
	fprintf(opf, "}\n");
	fprintf(opf, "#define %s_bmp %s_bmp()\n\n", lname, lname);

	/* wxIcon accessor */
	fprintf(opf, "static wxIcon *%s_ico()\n", lname);
	fprintf(opf, "{\n");
	fprintf(opf, "	static wxIcon *ico_%s;\n", lname);
	fprintf(opf, "	if (!ico_%s || !ico_%s->IsOk())\n", lname, lname);
	fprintf(opf, "	{\n");
	fprintf(opf, "		ico_%s = new wxIcon();\n", lname);
	fprintf(opf, "		ico_%s->CopyFromBitmap(*%s_bmp);\n", lname, lname);
	fprintf(opf, "	}\n");
	fprintf(opf, "	return ico_%s;\n", lname);
	fprintf(opf, "}\n");
	fprintf(opf, "#define %s_ico %s_ico()\n\n", lname, lname);

	fprintf(opf, "#endif // %s_H\n", uname);
 
	fclose(ipf);
	fclose(opf);
	
	exit(0);
}