Exemple #1
0
static ParrotIO *
PIO_unix_pipe(theINTERP, ParrotIOLayer *l, STRING *cmd, int flags)
{
#if defined (linux) || defined (solaris)
    ParrotIO *io;
    int pid, err, fds[2];
    char *ccmd = string_to_cstring(interpreter, cmd);
    /* FIXME mem leak here */

    if((err = pipe(fds)) < 0) {
        perror("pipe:");
        return NULL;
    }

    /* Parent - return IO stream */
    if((pid = fork()) > 0) {
        io = PIO_new(interpreter, PIO_F_PIPE, 0, PIO_F_READ|PIO_F_WRITE);
        io->fd = fds[0];
        io->fd2 = fds[1];
        return io;
    }

    /* Child - exec process */
    if(pid == 0) {
        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);
        if( dup(fds[0]) != STDIN_FILENO || dup(fds[1]) != STDOUT_FILENO
               || dup(fds[1]) != STDERR_FILENO )
        {
            exit(0);
        }

        execl(ccmd, ccmd, (char*)0);
        /* Will never reach this unless exec fails. */
        perror("execvp:");
        return NULL;
    }

    perror("fork:");
#endif
    return NULL;
}
/*!
 * \brief The patcher's identifier
 *
 * \note The returned string is dynamically allocated. It should be free()'d
 *       when it is no longer needed.
 *
 * \param patcher CPatcher object
 * \return Patcher ID
 *
 * \sa Patcher::id()
 */
char * mbp_patcher_id(const CPatcher *patcher)
{
    CCASTP(patcher);
    return string_to_cstring(p->id());
}
/*!
 * \brief File to be patched
 *
 * \param info CFileInfo object
 *
 * \note The returned string is dynamically allocated. It should be free()'d
 *       when it is no longer needed.
 *
 * \return File path
 *
 * \sa FileInfo::inputPath()
 */
char * mbp_fileinfo_input_path(const CFileInfo *info)
{
    CCAST(info);
    return string_to_cstring(fi->inputPath());
}
char * mbp_fileinfo_rom_id(const CFileInfo *info)
{
    CCAST(info);
    return string_to_cstring(fi->romId());
}
/*!
 * \brief Get version number of the patcher
 *
 * \note The returned string is dynamically allocated. It should be free()'d
 *       when it is no longer needed.
 *
 * \param pc CPatcherConfig object
 * \return Version number
 *
 * \sa PatcherConfig::version()
 */
char * mbp_config_version(const CPatcherConfig *pc)
{
    CCAST(pc);
    return string_to_cstring(config->version());
}
/*!
 * \brief Get the temporary directory
 *
 * \note The returned string is dynamically allocated. It should be free()'d
 *       when it is no longer needed.
 *
 * \param pc CPatcherConfig object
 * \return Temporary directory
 *
 * \sa PatcherConfig::tempDirectory()
 */
char * mbp_config_temp_directory(const CPatcherConfig *pc)
{
    CCAST(pc);
    return string_to_cstring(config->tempDirectory());
}
Exemple #7
0
char * mbp_device_id(const CDevice *device)
{
    CCAST(device);
    return string_to_cstring(d->id());
}
/*!
 * \brief Which ramdisk patcher to use
 *
 * \note The output data is dynamically allocated. It should be `free()`'d
 *       when it is no longer needed.
 *
 * \param info CPatchInfo object
 *
 * \return Which ramdisk patcher to use
 *
 * \sa PatchInfo::ramdisk()
 */
char * mbp_patchinfo_ramdisk(const CPatchInfo *info)
{
    CCAST(info);
    return string_to_cstring(pi->ramdisk());
}
Exemple #9
0
/*!
 * \brief Device's full name
 *
 * \note The output data is dynamically allocated. It should be `free()`'d
 *       when it is no longer needed.
 *
 * \param device CDevice object
 *
 * \return Device name
 *
 * \sa Device::name()
 */
char *mbp_device_name(const CDevice *device)
{
    CCAST(device);
    return string_to_cstring(d->name());
}
Exemple #10
0
/*!
 * \brief Device's CPU architecture
 *
 * \note The output data is dynamically allocated. It should be `free()`'d
 *       when it is no longer needed.
 *
 * \param device CDevice object
 *
 * \return Architecture
 *
 * \sa Device::architecture()
 */
char *mbp_device_architecture(const CDevice *device)
{
    CCAST(device);
    return string_to_cstring(d->architecture());
}
Exemple #11
0
/*!
 * \brief Kernel cmdline in the boot image header
 *
 * \note The returned string is dynamically allocated. It should be free()'d
 *       when it is no longer needed.
 *
 * \param bootImage CBootImage object
 *
 * \return Kernel cmdline
 *
 * \sa BootImage::kernelCmdline()
 */
char * mbp_bootimage_kernel_cmdline(const CBootImage *bootImage)
{
    CCAST(bootImage);
    return string_to_cstring(bi->kernelCmdline());
}
Exemple #12
0
/*!
 * \brief Board name field in the boot image header
 *
 * \note The returned string is dynamically allocated. It should be free()'d
 *       when it is no longer needed.
 *
 * \param bootImage CBootImage object
 *
 * \return Board name
 *
 * \sa BootImage::boardName()
 */
char * mbp_bootimage_boardname(const CBootImage *bootImage)
{
    CCAST(bootImage);
    return string_to_cstring(bi->boardName());
}
/*!
 * \brief File to be patched
 *
 * \param info CFileInfo object
 *
 * \note The returned string is dynamically allocated. It should be free()'d
 *       when it is no longer needed.
 *
 * \return File path
 *
 * \sa FileInfo::filename()
 */
char * mbp_fileinfo_filename(const CFileInfo *info)
{
    CCAST(info);
    return string_to_cstring(fi->filename());
}
/*!
 * \brief The autopatcher's identifier
 *
 * \note The returned string is dynamically allocated. It should be free()'d
 *       when it is no longer needed.
 *
 * \param patcher CAutoPatcher object
 * \return AutoPatcher ID
 *
 * \sa AutoPatcher::id()
 */
char * mbp_autopatcher_id(const CAutoPatcher *patcher)
{
    CCASTAP(patcher);
    return string_to_cstring(ap->id());
}
Exemple #15
0
int
litsig_text_tool(struct pine *ps, int cmd, CONF_S **cl, unsigned int flags)
{
    char           **apval;
    int		     rv = 0;

    if(cmd != MC_EXIT && fixed_var((*cl)->var, NULL, NULL))
      return(rv);

    apval = APVAL((*cl)->var, ew);

    switch(cmd){
      case MC_ADD:
      case MC_EDIT :
	if(apval){
	    char *input = NULL, *result = NULL, *err = NULL, *cstring_version;
	    char *olddefval = NULL, *start_with;
	    size_t len;

	    if(!*apval && (*cl)->var->current_val.p &&
	       (*cl)->var->current_val.p[0]){
		if(!strncmp((*cl)->var->current_val.p,
			    DSTRING,
			    (len=strlen(DSTRING)))){
		    /* strip DSTRING and trailing paren */
		    olddefval = (char *)fs_get(strlen((*cl)->var->current_val.p)+1);
		    strncpy(olddefval, (*cl)->var->current_val.p+len,
			    strlen((*cl)->var->current_val.p)-len-1);
		    olddefval[strlen((*cl)->var->current_val.p)-len-1] = '\0';
		    start_with = olddefval;
		}
		else{
		    olddefval = cpystr((*cl)->var->current_val.p);
		    start_with = olddefval;
		}
	    }
	    else
	      start_with = (*apval) ? *apval : "";

	    input = (char *)fs_get((strlen(start_with)+1) * sizeof(char));
	    input[0] = '\0';
	    cstring_to_string(start_with, input);
	    err = signature_edit_lit(input, &result,
				     ((*cl)->var == role_comment_ptr)
					 ? "COMMENT EDITOR"
					 : "SIGNATURE EDITOR",
				     ((*cl)->var == role_comment_ptr)
					 ? h_composer_commentedit
					 : h_composer_sigedit);

	    if(!err){
		if(olddefval && !strcmp(input, result) &&
		   want_to(_("Leave unset and use default "), 'y',
			   'y', NO_HELP, WT_FLUSH_IN) == 'y'){
		    rv = 0;
		}
		else{
		    cstring_version = string_to_cstring(result);

		    if(apval && *apval)
		      fs_give((void **)apval);
		    
		    if(apval){
			*apval = cstring_version;
			cstring_version = NULL;
		    }

		    if(cstring_version)
		      fs_give((void **)&cstring_version);

		    rv = 1;
		}
	    }
	    else
	      rv = 0;

	    if(err){
		q_status_message1(SM_ORDER, 3, 5, "%s", err);
		fs_give((void **)&err);
	    }

	    if(result)
	      fs_give((void **)&result);
	    if(olddefval)
	      fs_give((void **)&olddefval);
	    if(input)
	      fs_give((void **)&input);
	}

	ps->mangled_screen = 1;
	break;
	
      default:
	rv = text_tool(ps, cmd, cl, flags);
	break;
    }

    /*
     * At this point, if changes occurred, var->user_val.X is set.
     * So, fix the current_val, and handle special cases...
     *
     * NOTE: we don't worry about the "fixed variable" case here, because
     *       editing such vars should have been prevented above...
     */
    if(rv == 1){
	/*
	 * Now go and set the current_val based on user_val changes
	 * above.  Turn off command line settings...
	 */
	set_current_val((*cl)->var, TRUE, FALSE);

	if((*cl)->value)
	  fs_give((void **)&(*cl)->value);

	(*cl)->value = pretty_value(ps, *cl);

	exception_override_warning((*cl)->var);

	/*
	 * The value of literal sig can affect whether signature file is
	 * used or not. So it affects what we display for sig file variable.
	 */
	if((*cl)->next && (*cl)->next->var == &ps->vars[V_SIGNATURE_FILE]){
	    if((*cl)->next->value)
	      fs_give((void **)&(*cl)->next->value);
	    
	    (*cl)->next->value = pretty_value(ps, (*cl)->next);
	}
    }

    return(rv);
}
/*!
 * \brief The ramdisk patchers's identifier
 *
 * \note The returned string is dynamically allocated. It should be free()'d
 *       when it is no longer needed.
 *
 * \param patcher CRamdiskPatcher object
 * \return RamdiskPatcher ID
 *
 * \sa RamdiskPatcher::id()
 */
char * mbp_ramdiskpatcher_id(const CRamdiskPatcher *patcher)
{
    CCASTRP(patcher);
    return string_to_cstring(rp->id());
}
/*!
 * \brief The path of the newly patched file
 *
 * \param patcher CPatcher object
 * \return Path to new file
 *
 * \sa Patcher::newFilePath()
 */
char * mbp_patcher_new_file_path(CPatcher *patcher)
{
    CASTP(patcher);
    return string_to_cstring(p->newFilePath());
}
/*!
 * \brief PatchInfo identifier
 *
 * \note The output data is dynamically allocated. It should be `free()`'d
 *       when it is no longer needed.
 *
 * \param info CPatchInfo object
 *
 * \return PatchInfo ID
 *
 * \sa PatchInfo::id()
 */
char * mbp_patchinfo_id(const CPatchInfo *info)
{
    CCAST(info);
    return string_to_cstring(pi->id());
}
Exemple #19
0
STRING *
PIO_sockaddr_in(theINTERP, unsigned short port, STRING * addr)
{
    struct sockaddr_in sa;
    /* Hard coded to IPv4 for now */
    int family = AF_INET;

    char * s = string_to_cstring(interpreter, addr);
#ifdef PARROT_DEF_INET_ATON
    if(inet_aton(s, &sa.sin_addr) != 0) {
#else
    if(inet_pton(family, s, &sa.sin_addr) != 0) {
#endif
        /* Success converting numeric IP */
    }
    else {
        /* Maybe it is a hostname, try to lookup */
        /* XXX Check PIO option before doing a name lookup,
         * it may have been toggled off.
         */
        struct hostent *he = gethostbyname(s);
        /* XXX FIXME - Handle error condition better */
        if(!he) {
            string_cstring_free(s);
            fprintf(stderr, "gethostbyname failure [%s]\n", s);
            return NULL;
        }
        memcpy((char*)&sa.sin_addr, he->h_addr, sizeof(sa.sin_addr));
    }
    string_cstring_free(s);

    sa.sin_port = htons(port);

    fprintf(stderr, "sockaddr_in: port %d\n", port);
    return string_make(interpreter, &sa, sizeof(struct sockaddr), NULL, 0,
            NULL);
}


#if PARROT_NET_DEVEL

/*

=item C<static ParrotIO *
PIO_unix_socket(theINTERP, ParrotIOLayer *layer, int fam, int type, int proto)>

Uses C<socket()> to create a socket with the specified address family,
socket type and protocol number.

=cut

*/

static ParrotIO *
PIO_unix_socket(theINTERP, ParrotIOLayer *layer, int fam, int type, int proto)
{
    int sock;
    ParrotIO * io;
    if((sock = socket(fam, type, proto)) >= 0) {
        io = PIO_new(interpreter, PIO_F_SOCKET, 0, PIO_F_READ|PIO_F_WRITE);
        io->fd = sock;
        io->remote.sin_family = fam;
        fprintf(stderr, "socket: fd = %d\n", sock);
        return io;
    }
    perror("socket:");
    return 0;
}