Exemplo n.º 1
0
/* Main entry point: locate home and dump structure */
home_data *home(char *path)
{
    home_data *data = find(path);
    int x = 0;

    if (data == NULL) {
        log_error("Cannot locate Java Home");
        return (NULL);
    }

    if (log_debug_flag == true) {
        log_debug("+-- DUMPING JAVA HOME STRUCTURE ------------------------");
        log_debug("| Java Home:       \"%s\"", PRINT_NULL(data->path));
        log_debug("| Java VM Config.: \"%s\"", PRINT_NULL(data->cfgf));
        log_debug("| Found JVMs:      %d", data->jnum);
        for (x = 0; x < data->jnum; x++) {
            home_jvm *jvm = data->jvms[x];
            log_debug("| JVM Name:        \"%s\"", PRINT_NULL(jvm->name));
            log_debug("|                  \"%s\"", PRINT_NULL(jvm->libr));
        }
        log_debug("+-------------------------------------------------------");
    }

    return (data);
}
Exemplo n.º 2
0
static void 
print_params (struct _mimeparam *param)
{
	struct _mimeparam *next;
	
	while (param) {
		next = param->next;
		debug_printf ("%s = ", PRINT_NULL (param->name));
		debug_printf ("%s\n", PRINT_NULL (param->value));
		param = next;
	}
}
Exemplo n.º 3
0
static void 
parse_content_disposition (unsigned char **in, unsigned char *inend, disposition_t *disposition, GError **err)
{
	unsigned char *inptr = *in;

	/* a) NIL 
	 * b) ("INLINE" NIL) 
	 * c) ("ATTACHMENT" ("FILENAME", "myfile.ext")) 
	 * d) "ALTERNATIVE" ("BOUNDARY", "---")  */

	while (inptr < inend && *inptr == ' ')
		inptr++;

	if (*inptr == '(') {
		inptr++; /* My '(' */

		/* cases c & b */
		disposition->type = decode_qstring (&inptr, inend, err);
		debug_printf ("disposition.type: %s\n", PRINT_NULL (disposition->type));
		disposition->params = decode_params (&inptr, inend, err);
		print_params (disposition->params);

		while (inptr < inend && *inptr == ' ')
			inptr++;

		if (*inptr != ')') {
			g_free (disposition->type);
			disposition->type = NULL;
			if (disposition->params)
				mimeparam_destroy (disposition->params);
			*in = inptr;
			set_error (err, in);
			return;
		}

		inptr++; /* My ')' */
	} else {
		if (strncmp ((const char *) inptr, "NIL", 3) != 0) {
			/* case d */
			disposition->type = decode_qstring (&inptr, inend, err);
			debug_printf ("disposition.type: %s\n", PRINT_NULL (disposition->type));
			disposition->params = decode_params (&inptr, inend, err);
			print_params (disposition->params);
		} else /* case a */
			inptr += 3;
	}

	*in = inptr;

	return;
}
Exemplo n.º 4
0
static void 
parse_lang (unsigned char **in, unsigned char *inend, struct _bodystruct *part, GError **err)
{
	unsigned char *inptr = *in;

	/* a) NIL 
	 * b) ("NL-BE") 
	 * c) "NL-BE" */

	while (inptr < inend && *inptr == ' ')
		inptr++;

	if (*inptr == '(') {

		inptr++; /* My '(' */

		/* case b */
		part->content.lang = decode_qstring (&inptr, inend, err);
		debug_printf ("lang: %s\n", PRINT_NULL (part->content.lang));

		while (inptr < inend && *inptr == ' ')
			inptr++;

		if (*inptr != ')') {
			g_free (part->content.lang);
			part->content.lang = NULL;
			*in = inptr;
			set_error (err, in);
			return;
		}

		inptr++; /* My ')' */

	} else {
		if (strncmp ((const char *) inptr, "NIL", 3) != 0) {
			/* case c */
			part->content.lang = decode_qstring (&inptr, inend, err);
			debug_printf ("lang: %s\n", PRINT_NULL (part->content.lang));
		} else /* case a */
			inptr += 3;
	}

	*in = inptr;

	return;
}
Exemplo n.º 5
0
/* Main entry point: parse command line arguments and dump them */
arg_data *arguments(int argc, char *argv[])
{
    arg_data *args = parse(argc,argv);
    int x = 0;

    if (args == NULL) {
        log_error("Cannot parse command line arguments");
        return NULL;
    }

    if (log_debug_flag == true) {
        log_debug("+-- DUMPING PARSED COMMAND LINE ARGUMENTS --------------");
        log_debug("| Detach:          %s", IsTrueFalse(args->dtch));
        log_debug("| Show Version:    %s", IsYesNo(args->vers));
        log_debug("| Show Help:       %s", IsYesNo(args->help));
        log_debug("| Check Only:      %s", IsEnabledDisabled(args->chck));
        log_debug("| Stop:            %s", IsTrueFalse(args->stop));
        log_debug("| Wait:            %d", args->wait);
        log_debug("| Run as service:  %s", IsYesNo(args->service));
        log_debug("| Install service: %s", IsYesNo(args->install));
        log_debug("| Remove service:  %s", IsYesNo(args->remove));
        log_debug("| JVM Name:        \"%s\"", PRINT_NULL(args->name));
        log_debug("| Java Home:       \"%s\"", PRINT_NULL(args->home));
        log_debug("| PID File:        \"%s\"", PRINT_NULL(args->pidf));
        log_debug("| User Name:       \"%s\"", PRINT_NULL(args->user));
        log_debug("| Extra Options:   %d", args->onum);
        for (x = 0; x < args->onum; x++) {
            log_debug("|   \"%s\"", args->opts[x]);
        }

        log_debug("| Class Invoked:   \"%s\"", PRINT_NULL(args->clas));
        log_debug("| Class Arguments: %d", args->anum);
        for (x = 0; x < args->anum; x++) {
            log_debug("|   \"%s\"",args->args[x]);
        }
        log_debug("+-------------------------------------------------------");
    }
    return args;
}
Exemplo n.º 6
0
static void 
read_unknown_qstring (unsigned char **in, unsigned char *inend, GError **err)
{
	unsigned char *inptr;
	char *str;

	inptr = *in;
	str = decode_qstring (&inptr, inend, err);
	debug_printf ("unknown: %s\n", PRINT_NULL (str));
	g_free (str);
	*in = inptr;

	return;
}
int main( int argc, char *argv[ ] ) {
	euca_opts euca_args;
	euca_opts *args = &euca_args;
	java_home_t *data = NULL;
	int status = 0;
	pid_t pid = 0;
	uid_t uid = 0;
	gid_t gid = 0;
	if( arguments( argc, argv, args ) != 0 ) exit( 1 );
	debug = args->verbose_flag || args->debug_flag;
	if( args->stop_flag == 1 ) return stop_child( args );
	if( checkuser( GETARG( args, user ), &uid, &gid ) == 0 ) return 1;
	char* java_home_user = GETARG(args,java_home);
	char* java_home_env = getenv( "JAVA_HOME" );
	if( java_home_user != NULL ) {
		__debug("Trying user supplied java home: %s", java_home_user);
		data = get_java_home(java_home_user);
	}
	if( data == NULL && java_home_env != NULL ) {
		__debug("Trying environment JAVA_HOME: %s", java_home_env);
		data = get_java_home(java_home_env);
	}
	__debug("TODO: loop through common locations for JVMs here.");
	if( data == NULL ) {
		__error( "Cannot locate Java Home" );
		return 1;
	}
	int x;
	if( debug == 1 ) {
		__debug( "+-- DUMPING JAVA HOME STRUCTURE ------------------------" );
		__debug( "| Java Home:       \"%s\"", PRINT_NULL( data->path ) );
		__debug( "| Found JVMs:      %d", data->jnum );
		for( x = 0; x < data->jnum; x++ ) {
			jvm_info_t *jvm = data->jvms[ x ];
			__debug( "| JVM Name:        \"%s\"", PRINT_NULL( jvm->name ) );
			__debug( "|                  \"%s\"", PRINT_NULL( jvm->libjvm_path ) );
		}
		__debug( "+-------------------------------------------------------" );
	}
	if( strcmp( argv[ 0 ], "eucalyptus-cloud" ) != 0 ) {
		char *oldpath = getenv( "LD_LIBRARY_PATH" ),*libf = java_library( args, data );
		char *old = argv[ 0 ],buf[ 32768 ],*tmp = NULL,*p1 = NULL,*p2 = NULL;
		p1 = strdup( libf );
		tmp = strrchr( p1, '/' );
		if( tmp != NULL ) tmp[ 0 ] = '\0';
		p2 = strdup( p1 );
		tmp = strrchr( p2, '/' );
		if( tmp != NULL ) tmp[ 0 ] = '\0';
		if( oldpath == NULL ) snprintf( buf, 32768, "%s:%s:%s/bin/linux-x64", p1, p2, GETARG(args,profiler_home) );
		else snprintf( buf, 32768, "%s:%s:%s:%s/bin/linux-x64", oldpath, p1, p2, GETARG(args,profiler_home) );
		tmp = strdup( buf );

		setenv( "LD_LIBRARY_PATH", tmp, 1 );
		__debug( "Invoking w/ LD_LIBRARY_PATH=%s", getenv( "LD_LIBRARY_PATH" ) );
		argv[ 0 ] = "eucalyptus-cloud";
		execve( old, argv, environ );
		__error( "Cannot execute process" );
		return 1;
	}
	__debug( "Running w/ LD_LIBRARY_PATH=%s", getenv( "LD_LIBRARY_PATH" ) );
	if(args->fork_flag) {
		pid = fork( );
		__die(( pid == -1 ),"Cannot detach from parent process" );
		if( pid != 0 ) return wait_child( args, pid );
		setsid( );
	}
	set_output(GETARG(args,out), GETARG(args,err));
	while( ( pid = fork( ) ) != -1 ) {
		if( pid == 0 ) exit( child( args, data, uid, gid ) );
		child_pid = pid;
		signal( SIGHUP, controller );
		signal( SIGTERM, controller );
		signal( SIGINT, controller );
		while( waitpid( pid, &status, 0 ) != pid );
		if( WIFEXITED( status ) ) {
			status = WEXITSTATUS( status );
			__debug( "Eucalyptus exited with status: %d", status );
			if( status != 122 ) unlink( GETARG( args, pidfile ) );
			if( status == 123 ) {
				__debug( "Reloading service" );
				continue;
			}
			if( status == 0 ) {
				__debug( "Service shut down" );
				return 0;
			}
			__error( "Service exit with a return value of %d", status );
			return 1;
		} else {
			__error( "Service did not exit cleanly exit value %d", status );
			return 1;
		}
	}
	__error( "Cannot decouple controller/child processes" );
	return 1;
}
Exemplo n.º 8
0
int main(int argc, char *argv[]) {
	euca_opts euca_args;
	euca_opts *args = &euca_args;
	java_home_t *data = NULL;
	int status = 0;
	pid_t pid = 0;
	uid_t uid = 0;
	gid_t gid = 0;
	int i;
	if (arguments(argc, argv, args) != 0)
		exit(1);
	debug = args->debug_flag;
	set_output(GETARG(args, out), GETARG(args, err));
	if (args->kill_flag == 1)
		return stop_child(args);
	if (checkuser(GETARG(args, user), &uid, &gid) == 0)
		return 1;
	for (i = 0; i < args->java_home_given; ++i) {
		__debug("Trying user supplied java home: %s", args->java_home_arg[i]);
		data = get_java_home(args->java_home_arg[i]);
		if (data != NULL) {
			break;
		}
	}
	char* java_home_env = getenv("JAVA_HOME");
	if (data == NULL && java_home_env != NULL) {
		__debug("Trying environment JAVA_HOME: %s", java_home_env);
		data = get_java_home(java_home_env);
	}
	if (data == NULL && !args->java_home_given && 
            args->java_home_arg[0] != NULL && CHECK_ISDIR(args->java_home_arg[0])) {
		__debug("Trying built-in java home: %s", args->java_home_arg[0]);
		data = get_java_home(args->java_home_arg[0]);
	}
	if (data == NULL && CHECK_ISREG("/usr/bin/java")) {
		char * javapath = (char *) calloc(PATH_MAX, sizeof(char));
		javapath = realpath("/usr/bin/java", javapath);
		if (javapath != NULL) {
			javapath[strlen(javapath)-strlen("jre/bin/java")] = '\0';
			__debug("Trying system java home: %s", javapath);
			data = get_java_home(javapath);
		}
	}
	if (data == NULL) {
		__error("Cannot locate Java Home");
		return 1;
	}
	int x;
	if (debug == 1) {
		__debug("+-- DUMPING JAVA HOME STRUCTURE ------------------------");
		__debug("| Java Home:       \"%s\"", PRINT_NULL(data->path));
		__debug("| Found JVMs:      %d", data->jnum);
		for (x = 0; x < data->jnum; x++) {
			jvm_info_t *jvm = data->jvms[x];
			__debug("| JVM Name:        \"%s\"", PRINT_NULL(jvm->name));
			__debug("|                  \"%s\"", PRINT_NULL(jvm->libjvm_path));
		}
		__debug("+-------------------------------------------------------");
	}
	if (strcmp(argv[0], "eucalyptus-cloud") != 0) {
		char *oldpath = getenv("LD_LIBRARY_PATH"), *libf = java_library(args,
				data);
		char *old = argv[0], buf[32768], *tmp = NULL, *p1 = NULL, *p2 = NULL;
		p1 = strdup(libf);
		tmp = strrchr(p1, '/');
		if (tmp != NULL)
			tmp[0] = '\0';
		p2 = strdup(p1);
		tmp = strrchr(p2, '/');
		if (tmp != NULL)
			tmp[0] = '\0';
		if (oldpath == NULL)
			snprintf(buf, 32768, "%s:%s:%s/bin/linux-x64", p1, p2, GETARG(args,
					profiler_home));
		else
			snprintf(buf, 32768, "%s:%s:%s:%s/bin/linux-x64", oldpath, p1, p2,
					GETARG(args, profiler_home));
		tmp = strdup(buf);

		setenv("LD_LIBRARY_PATH", tmp, 1);
		__debug("Invoking w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
		argv[0] = "eucalyptus-cloud";
		execve(old, argv, environ);
		__error("Cannot execute process");
		return 1;
	}
	__debug("Running w/ LD_LIBRARY_PATH=%s", getenv("LD_LIBRARY_PATH"));
	if (args->fork_flag) {
		pid = fork();
		__die((pid == -1), "Cannot detach from parent process");
		if (pid != 0)
			return wait_child(args, pid);
		setsid();
	}
	while ((pid = fork()) != -1) {
		if (pid == 0)
			exit(child(args, data, uid, gid));
		child_pid = pid;
		signal(SIGHUP, controller);
		signal(SIGTERM, controller);
		signal(SIGINT, controller);

		while (waitpid(-1, &status, 0) != pid)
			;
		if (WIFEXITED(status)) {
			status = WEXITSTATUS(status);
			__debug("Eucalyptus exited with status: %d", status);
			unlink(GETARG(args, pidfile));
			if (status == EUCA_RET_RELOAD) {
				__debug("Reloading service.");
				continue;
			} else if (status == 0) {
				__debug("Service shut down cleanly.");
				return 0;
			}
			__error("Service exit with a return value of %d.", status);
			return 1;
		} else {
			perror("Service did not exit cleanly.");
			__error("Service did not exit cleanly: exit value=%d.", status);
			return 1;
		}
	}
	__error("Cannot decouple controller/child processes");
	return 1;
}
Exemplo n.º 9
0
void help(home_data *data)
{
    int x;

    printf("Usage: %s [-options] class [args...]\n", log_prog);
    printf("\n");
    printf("Where options include:\n");
    printf("\n");
    printf("    -help | --help | -?\n");
    printf("        show this help page (implies -nodetach)\n");
    printf("    -jvm <JVM name>\n");
    printf("        use a specific Java Virtual Machine. Available JVMs:\n");
    printf("           ");
    for (x = 0; x < data->jnum; x++) {
        printf(" '%s'", PRINT_NULL(data->jvms[x]->name));
    }
    printf("\n");

    printf("    -cp | -classpath <directories and zip/jar files>\n");
    printf("        set search path for service classes and resouces\n");
    printf("    -java-home | -home <directory>\n");
    printf("        set the path of your JDK or JRE installation (or set\n");
    printf("        the JAVA_HOME environment variable)\n");

    printf("    -version\n");
    printf("        show the current Java environment version (to check\n");
    printf("        correctness of -home and -jvm. Implies -nodetach)\n");
    printf("    -showversion\n");
    printf("        show the current Java environment version (to check\n");
    printf("        correctness of -home and -jvm) and continue execution.\n");
    printf("    -nodetach\n");
    printf("        don't detach from parent process and become a daemon\n");
    printf("    -debug\n");
    printf("        verbosely print debugging information\n");
    printf("    -check\n");
    printf("        only check service (implies -nodetach)\n");
    printf("    -user <user>\n");
    printf("        user used to run the daemon (defaults to current user)\n");
    printf("    -verbose[:class|gc|jni]\n");
    printf("        enable verbose output\n");
    printf("    -outfile </full/path/to/file>\n");
    printf("        Location for output from stdout (defaults to /dev/null)\n");
    printf("        Use the value '&2' to simulate '1>&2'\n");
    printf("    -errfile </full/path/to/file>\n");
    printf("        Location for output from stderr (defaults to /dev/null)\n");
    printf("        Use the value '&1' to simulate '2>&1'\n");
    printf("    -pidfile </full/path/to/file>\n");
    printf("        Location for output from the file containing the pid of jsvc\n");
    printf("        (defaults to /var/run/jsvc.pid)\n");
    printf("    -D<name>=<value>\n");
    printf("        set a Java system property\n");
    printf("    -X<option>\n");
    printf("        set Virtual Machine specific option\n");
    printf("    -ea[:<packagename>...|:<classname>]\n");
    printf("    -enableassertions[:<packagename>...|:<classname>]\n");
    printf("        enable assertions\n");
    printf("    -da[:<packagename>...|:<classname>]\n");
    printf("    -disableassertions[:<packagename>...|:<classname>]\n");
    printf("        disable assertions\n");
    printf("    -esa | -enablesystemassertions\n");
    printf("        enable system assertions\n");
    printf("    -dsa | -disablesystemassertions\n");
    printf("        disable system assertions\n");
    printf("    -agentlib:<libname>[=<options>]\n");
    printf("        load native agent library <libname>, e.g. -agentlib:hprof\n");
    printf("    -agentpath:<pathname>[=<options>]\n");
    printf("        load native agent library by full pathname\n");
    printf("    -javaagent:<jarpath>[=<options>]\n");
    printf("        load Java programming language agent, see java.lang.instrument\n");
    printf("    -procname <procname>\n");
    printf("        use the specified process name (works only for Linux)\n");
    printf("    -wait <waittime>\n");
    printf("        wait waittime seconds for the service to start\n");
    printf("        waittime should multiple of 10 (min=10)\n");
    printf("    -stop\n");
    printf("        stop the service using the file given in the -pidfile option\n");
    printf("    -keepstdin\n");
    printf("        does not redirect stdin to /dev/null\n");
    printf("\njsvc (Apache Commons Daemon) " JSVC_VERSION_STRING "\n");
    printf("Copyright (c) 1999-2011 Apache Software Foundation.\n");

    printf("\n");
}
Exemplo n.º 10
0
static void
bodystruct_dump_r (bodystruct_t *part, gint depth)
{
	struct _mimeparam *param;
	int i;

	for (i = 0; i < depth; i++)
		printf ("  ");

	printf ("IMAP part specification: %s\n", PRINT_NULL (part->part_spec));

	for (i = 0; i < depth; i++)
		printf ("  ");

	printf ("Content-Type: %s/%s", PRINT_NULL (part->content.type),
		 part->content.subtype);

	if (part->content.params) {
		param = part->content.params;
		while (param) {
			printf ("; %s=%s", PRINT_NULL (param->name), 
				PRINT_NULL (param->value));
			param = param->next;
		}
	}

	printf ("\n");

	if (part->content.type && !strcasecmp (part->content.type, "multipart")) {
		part = part->subparts;
		while (part != NULL) {
			bodystruct_dump_r (part, depth + 1);
			part = part->next;
		}
	} else if (part->content.type && !strcasecmp (part->content.type, "message") && part->content.subtype && !strcasecmp (part->content.subtype, "rfc822")) {
		depth++;
		
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ( "Date: %s\n", PRINT_NULL (part->envelope->date));
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("Subject: %s\n", PRINT_NULL (part->envelope->subject));
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("From: %s\n", PRINT_NULL (part->envelope->from));
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("Sender: %s\n", PRINT_NULL (part->envelope->sender));
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("Reply-To: %s\n", PRINT_NULL (part->envelope->reply_to));
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("To: %s\n", PRINT_NULL (part->envelope->to));
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("Cc: %s\n", PRINT_NULL (part->envelope->cc));
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("Bcc: %s\n", PRINT_NULL (part->envelope->bcc));
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("In-Reply-To: %s\n", PRINT_NULL (part->envelope->in_reply_to));
		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("Message-Id: %s\n", PRINT_NULL (part->envelope->message_id));
		bodystruct_dump_r (part->subparts, depth);
		depth--;
	} else {
		if (part->disposition.type) {
			for (i = 0; i < depth; i++)
				printf ("  ");
			printf ("Content-Disposition: %s", PRINT_NULL (part->disposition.type));
			if (part->disposition.params) {
				param = part->disposition.params;
				while (param) {
					printf ("; %s=%s", PRINT_NULL (param->name), 
						PRINT_NULL (param->value));
					param = param->next;
				}
			}
			
			printf ("\n");
		}
		
		if (part->encoding) {
			for (i = 0; i < depth; i++)
				printf ("  ");
			printf ("Content-Transfer-Encoding: %s\n", PRINT_NULL (part->encoding));
		}

		if (part->description) {
			for (i = 0; i < depth; i++)
				printf ("  ");
			printf ("Description: %s\n", PRINT_NULL (part->description));
		}

		for (i = 0; i < depth; i++)
			printf ("  ");
		printf ("Octets: %d, Lines: %d\n", part->octets, part->lines);

		if (part->content.lang) {
			for (i = 0; i < depth; i++)
				printf ("  ");
			printf ("Language: %s\n", PRINT_NULL (part->content.lang));
		}

		if (part->content.loc) {
			for (i = 0; i < depth; i++)
				printf ("  ");
			printf ("Location: %s\n", PRINT_NULL (part->content.loc));
		}

		if (part->content.cid) {
			for (i = 0; i < depth; i++)
				printf ("  ");
			printf ("Cid: %s\n", PRINT_NULL (part->content.cid));
		}

		if (part->content.md5) {
			for (i = 0; i < depth; i++)
				printf ("  ");
			printf ("MD5: %s\n", PRINT_NULL (part->content.md5));
		}
	}


	printf ("\n");
}
Exemplo n.º 11
0
static struct _bodystruct *
bodystruct_part_decode (unsigned char **in, unsigned char *inend, bodystruct_t *parent, gint num, GError **err)
{
	struct _bodystruct *part, *list, *tail, *n;
	unsigned char *inptr;

	inptr = *in;

	while (inptr < inend && *inptr == ' ')
		inptr++;


	if (inptr == inend || *inptr != '(') {
		*in = inptr;
		return NULL;
	}

	inptr++; /* My '(' */

	part = bodystruct_new ();

	part->part_spec = NULL;
	part->parent = parent;

	if (parent) {
		if (parent->part_spec && *parent->part_spec) {
			if (!strcasecmp (parent->content.type, "message") && !strcasecmp (parent->content.subtype, "rfc822")) {
				part->part_spec = g_strdup (parent->part_spec);
			} else {
				part->part_spec = g_strdup_printf ("%s.%d", parent->part_spec, num);
			}
		} else {
			part->part_spec = g_strdup_printf ("%d", num);
		}
	} else {
		part->part_spec = g_strdup ("");
	}

	if (*inptr == '(') {
		gint cnt = 1;

		part->content.type = g_strdup ("MULTIPART");

		list = NULL;
		tail = (struct _bodystruct *) &list;

		while ((n = bodystruct_part_decode (&inptr, inend, part, cnt, err)) != NULL) 
		{
			tail->next = n;
			tail = n;
			cnt++;

			while (inptr < inend && *inptr == ' ')
				inptr++;

			if (*inptr == ')')
				break;
		}

		part->subparts = list;

		if (*inptr != ')') {
			part->content.subtype = decode_qstring (&inptr, inend, err);
			debug_printf ("contensubtype: %s\n", PRINT_NULL (part->content.subtype));
		}

		if (*inptr != ')') {
			part->content.params = decode_params (&inptr, inend, err);
			print_params (part->content.params);
		}

		/* if (*inptr != ')') {
		 *	parse_something_unknown (&inptr, inend, err);
		 * } */

		if (*inptr != ')') {
			parse_content_disposition (&inptr, inend, &part->disposition, err);
		}

		if (*inptr != ')') {
			parse_lang (&inptr, inend, part, err);
		}

		if (*inptr != ')') {
			end_this_piece (&inptr, inend, err);
		}

	} else {
		part->next = NULL;
		part->content.type = decode_qstring (&inptr, inend, err);
		if (!part->content.type)
			part->content.type = g_strdup ("TEXT");
		debug_printf ("contentype: %s\n", PRINT_NULL (part->content.type));

		part->content.subtype = decode_qstring (&inptr, inend, err);
		if (!part->content.subtype)
			part->content.subtype = g_strdup ("PLAIN");
		debug_printf ("contensubtype: %s\n", PRINT_NULL (part->content.subtype));

		part->disposition.type = NULL;
		part->disposition.params = NULL;
		part->encoding = NULL;
		part->envelope = NULL;
		part->subparts = NULL;


		if (!strcasecmp (part->content.type, "message") && !strcasecmp (part->content.subtype, "rfc822")) {

			if (*inptr != ')') {
				part->content.params = decode_params (&inptr, inend, err);
				print_params (part->content.params);
			}

			if (*inptr != ')') {
				part->content.cid = decode_qstring (&inptr, inend, err);
				debug_printf ("content.cid: %s\n", PRINT_NULL (part->content.cid));
			}

			if (*inptr != ')') {
				part->description = decode_qstring (&inptr, inend, err);
				debug_printf ("description: %s\n", PRINT_NULL (part->description));
			}

			if (*inptr != ')') {
				part->encoding = decode_qstring (&inptr, inend, err);
				if (!part->encoding)
					part->encoding = g_strdup ("7BIT");
				debug_printf ("encoding: %s\n", PRINT_NULL (part->encoding));
			}

			if (*inptr != ')') {
				part->octets = decode_num (&inptr, inend, err);
				debug_printf ("octets: %d\n", part->octets);
			}

			if (*inptr != ')') {
				part->envelope = decode_envelope (&inptr, inend, err);
			}

			if (*inptr != ')') {
				part->subparts = bodystruct_part_decode (&inptr, inend, part, 1, err);
			}

			if (*inptr != ')') {
				part->lines = decode_num (&inptr, inend, err);
				debug_printf ("lines: %d\n", part->lines);
			}

			if (*inptr != ')') {
				read_unknown_qstring (&inptr, inend, err);
			}

			if (*inptr != ')') {
				parse_content_disposition (&inptr, inend, &part->disposition, err);
			}

			if (*inptr != ')') {
				parse_lang (&inptr, inend, part, err);
			}

			if (*inptr != ')') {
				end_this_piece (&inptr, inend, err);
			}

		} else if (!strcasecmp (part->content.type, "text")) {

			if (*inptr != ')') {
				part->content.params = decode_params (&inptr, inend, err);
				print_params (part->content.params);
			}

			if (*inptr != ')') {
				part->content.cid = decode_qstring (&inptr, inend, err);
				debug_printf ("content.cid: %s\n", PRINT_NULL (part->content.cid));
			}

			if (*inptr != ')') {
				part->description = decode_qstring (&inptr, inend, err);
				debug_printf ("description: %s\n", PRINT_NULL (part->description));
			}

			if (*inptr != ')') {
				part->encoding = decode_qstring (&inptr, inend, err);
				debug_printf ("encoding: %s\n", PRINT_NULL (part->encoding));
			}

			if (*inptr != ')') {
				part->octets = decode_num (&inptr, inend, err);
				debug_printf ("octets: %d\n", part->octets);
			}

			if (*inptr != ')') {
				part->lines = decode_num (&inptr, inend, err);
				debug_printf ("lines: %d\n", part->lines);
			}

			if (*inptr != ')') {
				read_unknown_qstring (&inptr, inend, err);
			}

			if (*inptr != ')') {
				parse_content_disposition (&inptr, inend, &part->disposition, err);
			}

			if (*inptr != ')') {
				parse_lang (&inptr, inend, part, err);
			}

			if (*inptr != ')') {
				end_this_piece (&inptr, inend, err);
			}

		} else if (!strcasecmp (part->content.type, "APPLICATION")||
				!strcasecmp (part->content.type, "IMAGE") ||
				!strcasecmp (part->content.type, "VIDEO") ||
				!strcasecmp (part->content.type, "AUDIO"))
		{

			if (*inptr != ')') {
				part->content.params = decode_params (&inptr, inend, err);
				print_params (part->content.params);
			}

			if (*inptr != ')') {
				part->content.cid = decode_qstring (&inptr, inend, err);
				debug_printf ("content.cid: %s\n", PRINT_NULL (part->content.cid));
			}

			if (*inptr != ')') {
				part->description = decode_qstring (&inptr, inend, err);
				debug_printf ("description: %s\n", PRINT_NULL (part->description));
			}

			if (*inptr != ')') {
				part->encoding = decode_qstring (&inptr, inend, err);
				debug_printf ("encoding: %s\n", PRINT_NULL (part->encoding));
			}

			if (*inptr != ')') {
				part->octets = decode_num (&inptr, inend, err);
				debug_printf ("octets: %d\n", part->octets);
			}

			if (*inptr != ')') {
				read_unknown_qstring (&inptr, inend, err);
			}

			if (*inptr != ')') {
				parse_content_disposition (&inptr, inend, &part->disposition, err);
			}

			if (*inptr != ')') {
				parse_lang (&inptr, inend, part, err);
			}

			if (*inptr != ')') {
				end_this_piece (&inptr, inend, err);
			}

		} else {
			/* I don't know how it looks, so I just read it away */
			end_this_piece (&inptr, inend, err);
		}


	}

	if (*inptr != ')') {
		*in = inptr;
		set_error (err, in);
		bodystruct_free (part);
		return NULL;
	}

	inptr++; /* My ')' */

	*in = inptr;

	return part;
}
Exemplo n.º 12
0
static struct _envelope *
decode_envelope (unsigned char **in, unsigned char *inend, GError **err)
{
	struct _envelope *node;
	unsigned char *inptr;
	
	inptr = *in;

	while (inptr < inend && *inptr == ' ')
		inptr++;

	if (inptr == inend || *inptr != '(') {
		*in = inptr;
		set_error (err, in);
		return NULL;
	}

	inptr++;

	node = envelope_new ();

	node->date = decode_qstring (&inptr, inend, err);
	debug_printf ("env date: %s\n", PRINT_NULL (node->date));
	node->subject = decode_qstring (&inptr, inend, err);
	debug_printf ("env subject: %s\n", PRINT_NULL (node->subject));

	node->from = decode_estring (&inptr, inend, err);
	debug_printf ("env from: %s\n", PRINT_NULL (node->from));

	node->sender = decode_estring (&inptr, inend, err);
	debug_printf ("env sender: %s\n", PRINT_NULL (node->sender));

	node->reply_to = decode_estring (&inptr, inend, err);
	debug_printf ("env reply_to: %s\n", PRINT_NULL (node->reply_to));

	node->to = decode_estring (&inptr, inend, err);
	debug_printf ("env to: %s\n", PRINT_NULL (node->to));

	node->cc = decode_estring (&inptr, inend, err);
	debug_printf ("env cc: %s\n", PRINT_NULL (node->cc));

	node->bcc = decode_estring (&inptr, inend, err);
	debug_printf ("env bcc: %s\n", PRINT_NULL (node->bcc));

	node->in_reply_to = decode_estring (&inptr, inend, err);
	debug_printf ("env in_reply_to: %s\n", PRINT_NULL (node->in_reply_to));

	node->message_id = decode_qstring (&inptr, inend, err);
	debug_printf ("env message_id: %s\n", PRINT_NULL (node->message_id));

	while (inptr < inend && *inptr == ' ')
		inptr++;


	if (*inptr != ')') {
		envelope_free (node);
		*in = inptr;
		set_error (err, in);
		return NULL;
	}


	inptr++;

	*in = inptr;

	return node;
}