#1
  1. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95

    piping html to mozilla


    i have a process that is going to be processing large amounts of html. what i want to do is take this html as it comes from the socket and pipe it into mozilla. can i open a named pipe in the socket process, and then have a different process that dups stdin to the read end of the above named pipe and then execve() Mozilla? maybe that wont work but something along those lines im guessing? is this possible without touching the Mozilla source? if its not my other idea, which i DONT want to do, would be to write the html to a tmp file, and then pass mozilla a command to open it; but if there is a better way what might it be?
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    well im pretty sure that won't work. does anyone have any ideas how to go about doing this? im thinking if i can get mozilla to connect to a socket i create, and then dup the output of the socket that is streaming the html into the input of the socket mozilla connects to maybe?? and just keep feeding it html? but it wont be requesting it so will it just read it like that??
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    13
    If mozilla won't read it's input from stdin, you're going to have to find another way to see the output.

    What's the application, and what kind of processing will you be doing?
  6. #4
  7. ASP.Net MVP
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Aug 2003
    Location
    WI
    Posts
    4,378
    Rep Power
    1511
    perhaps write it to file, and tell mozilla to use that file? it means you have to wait for everything to be downloaded, but it will render pretty much instantly when you load if from the local disk anyway.
    Primary Forum: .Net Development
    Holy cow, I'm now an ASP.Net MVP!

    [Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

    http://twitter.com/jcoehoorn
  8. #5
  9. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    the application is a packet sniffer. it list's established connections, then when you choose which one to snoop on it should launch mozilla and feed it html. i haven't actually tried using stdin in yet, i didnt think it would be that easy but i'll try that and see how it works. else i'll just have to use temp files i guess.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    13
    I'd be inclined to build the app so that it optionally snarfs HTML data to a file, or more likely a series of files, one to a page. Take an optional parameter as the directory to snarf the files into. This provides a nice way to archive the porn that the CEO is downloading, too. Very useful when it comes time to negotiate a raise or promotion.
  12. #7
  13. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    hehe this is pretty cool it kinda sorta works. here's the deal: i tried first to just fork, dup2 the socket to stdin, and exec mozilla but that wasnt working. it just sat there, so im guessing it cant read raw html from stdin. . it turns out mozilla has an option like so, 'mozilla -remote "openfile(/path/to/file/)"', which lets you tell an already running mozilla to open a file. so i implemented the tmp file idea, but here is the slight problem. my socket gets passed single packets, so one read does not give me an entire page, the pages usually will be split up over multiple packets. so the pages aren't rendering correctly. im thinking my only option is to sift thru the data and look for a closing '</html>', even tho that wont be 100% reliable since someone could just type that onto a page anyways. here's how im doing it now, but i would really rather find a way to "stream" the html rather than creating files. any bright ideas?
    reading html
    Code:
    if(mozilla)
            {
                    //create the pipe; child reads parent writes
                    if( (pipe(bong)) != 0)
                            perror("pipe"), exit(1);
    
                    printf("forking\n");
                    if( (cpid = fork()) == 0)
                    {
                            close(bong[1]); //close write end
    
                            char    buf[FLEN],      command[CMDLEN];
    
                            strcpy(command, "/usr/bin/mozilla ");
                            len = strlen(command);
    
                            //start mozilla 
                            system("/usr/bin/mozilla &");
    
                            //read filename from pipe and build mozilla command
                            while( (nread = read(bong[0], buf, FLEN - 1)) > 0)
                            {
                                    printf("read %d bytes from pipe\n", nread);
                                    strcpy(command + len, "-remote \"openfile(");
                                    strncat(command, buf, nread);
                                    strcat(command, ")\"");
                                    printf("executing %s\n", command);
                                    system(command);
                                    bzero(buf, FLEN);
                                    strcpy(command, "/usr/bin/mozilla ");
                            }
                            close(bong[0]);
                            exit(0);
                    }
            }
    writing html
    Code:
                    if( (nread = recvfrom(sock, recvbuf, HTMLBUF, MSG_TRUNC, (struct sockaddr *) &sa, &salen)) < 1)
                    {
                            if(errno == EAGAIN)     //indicates timeout
                                    return 1;
                            else                    //other error
                                    perror("recv"),         exit(0);
                    }
    
                    ip = (struct ip *) (recvbuf + ETH_HDRLEN);      
                    tcp = (struct tcphdr *) (recvbuf + ETH_HDRLEN + (ip->ip_hl << 2));
    
                    //if we have data then print it out             
                    if( (datalen = (ntohs(ip->ip_len) - (ip->ip_hl << 2) - (tcp->doff << 2))) > 0)
                    {       //this has to be cast before it is incremented or else we would increment it by the
                            //size of a tcphdr * 4 ! 
                            bcopy( (  ( (char *)tcp) + (tcp->doff << 2)), data, datalen);
    
                            //random bytes that are appended to filename
                            for(x = 0; x < 3; x++)
                            {
                                    count[x]++;
                                    if( count[x] == 'z' )
                                            count[x] = 'a';
                            }
    
                            if(mozilla)
                            {
                                    //make a new tmp file
                                    strcpy(filename, TMPFILE);      //sniftmp
                                    strncat(filename, count, 3);    //random 3 chars
                                    strcat(filename, ".html");      // sniftmpXXX.html
                                    len = strlen(filename);
    
                                    //open and write the html to tmp file
                                    if( (tmpfd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, _PERM)) < 0)
                                            perror("open"), exit(1);
    
                                    if( write(tmpfd, recvbuf, datalen) < 0)
                                            perror("write"),        exit(1);
    
                                    close(tmpfd);
    
                                    //send the name of the file down the pipe
                                    if( (nread = write(bong[1], filename, len)) < 0)
                                            perror("write"),        exit(1);
                                    else
                                            printf("sent %s down pipe %d bytes\n", filename, nread);
                            }

IMN logo majestic logo threadwatch logo seochat tools logo