Example #1
0
int
nuov_processor(int cmd, MSGNO_S *msgmap, SCROLL_S *sparms)
{
    int rv = 0;

    switch(cmd){
	/*----------- Print all the help ------------*/
      case MC_PRINTMSG :
	if(open_printer(sparms->text.desc) == 0){
	    print_help(sparms->proc.data.p);
	    close_printer();
	}

	break;

      case MC_RELNOTES :
	helper(h_news, "ALPINE RELEASE NOTES", 0);
	ps_global->mangled_screen = 1;
	break;

      case MC_EXIT :
	rv = 1;
	break;

      default :
	panic("Unhandled case");
    }

    return(rv);
}
Example #2
0
void
int17(regcontext_t *REGS)
{
    int	fd;
    u_char c;

    switch (R_AH) {

    case 0x00:
	reset_poll();
	
	fd = lpt_fd[R_DX];
	if (fd == -1) {
	    open_printer(R_DX);
	    fd = lpt_fd[R_DX];
	}
	if (fd >= 0) {
	    c = R_AL;
	    write(fd, &c, 1);
	}
	R_AH = 0x90;		/* printed selected */
	current_count[R_DX]++;
	break;

    case 0x01:
    case 0x02:
	R_AH = 0x90;
	break;

    default:
	unknown_int2(0x17, R_AH, REGS);
	break;
    }
}
Example #3
0
void  print_people( int ref )
{
	int reference ;					/* person selected for printing		*/
	char *alert_ptr, alert_str[200] ;
	short i, count = 0 ;
	Str_prt_params params ;
	
	while( !count )
	{
		if( !ref )
		{
			reference =  get_person_reference( NULL, TRUE ) ;
			if( !reference )  return ;		/* exit if nobody selected	*/

			count = entries ;	/* entries is number of people selected	*/
			if( count > 1 )
			{
				rsrc_gaddr( R_STRING, PRINT_MANY, &alert_ptr ) ;
				sprintf( alert_str, alert_ptr, count ) ;
				if( form_alert( 0, alert_str ) == 2 )  count = 0 ;
			}
		}
		else
		{
			matches[0] = ref ;	/* force selector list					*/
			count = 1 ;
		}	

		if( count )
		{
			if( open_printer( &params ) )
			{
				params.ref2 = 0 ;		/* Do not print second reference.	*/
				
				if( params.use_gdos )
					setup_font( &params, fontinfo ) ;

				if( params.chs_across < 40 )
				{
					rsrc_gaddr( R_STRING, GROSS_FONT, &alert_ptr ) ;
					rsrc_form_alert( 1, GROSS_FONT ) ;
				}
				else
				{
					busy( BUSY_MORE ) ;
			
					start_print_checking( &params ) ;

					i = 0 ;
					while(  printing_ok( &params ) && ( reference = matches[i++] ) )
						print_person( reference, &params ) ;

					close_printer( &params ) ;
					busy( BUSY_LESS ) ;
				}
			}
		}
	}
}
Example #4
0
void processReq_Raw(int fd)
{
	int f1;

	if (busy == FALSE)
	{
		if ((f1 = open_printer()) >= 0)   //modify by Lisa
		{
			if (copy_stream(fd, f1) < 0)
			{
				//syslog(0, "copy stream err\n");
			}
			close(f1);
		}		
	}
	close(fd);
}
Example #5
0
void one_job(int lpnumber)
{
	int lp, open_sleep = 10;
	struct sockaddr_storage client;
	socklen_t clientlen = sizeof(client);

	if (getpeername(0, (struct sockaddr *)&client, &clientlen) >= 0) {
		char host[INET6_ADDRSTRLEN];
		dolog(LOG_NOTICE, "Connection from %s port %hu\n", get_ip_str((struct sockaddr *)&client, host, sizeof(host)), get_port((struct sockaddr *)&client));
	}
	if (get_lock(lpnumber) == 0)
		return;
	/* Make sure lp device is open... */
	while ((lp = open_printer(lpnumber)) == -1) {
		sleep(open_sleep);
		if (open_sleep < 320) /* ~5 min interval to avoid spam in syslog */
			open_sleep *= 2;
	}
	if (copy_stream(0, lp) < 0)
		dolog(LOGOPTS, "copy_stream: %m\n");
	close(lp);
	free_lock();
}
Example #6
0
void processReq_Raw(int fd)
{
    int f1;
    //PRINT("fd=%d \n",fd);
    //strcpy(clientaddr , inet_ntoa(client.sin_addr));

    //PRINT("Connection from %s prot %d accepted \n",inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port));
    //syslog(LOGOPTS, "Connection from %s port %hd accepted\n", inet_ntoa(client.sin_addr), ntohs(client.sin_port));
    /*write(fd, "Printing", 8);*/
    if (lptstatus.busy == FALSE)
    {
        if ((f1 = open_printer()) >= 0)   //modify by Lisa
        {
            if (copy_stream(fd, f1) < 0)
                syslog(LOGOPTS, "read: %m\n");
            close(f1);
        }
        (void)close(fd);
    }
    else
        return 0;

}
Example #7
0
/*-------------------------------------------------------------------*/
static void printer_execute_ccw (DEVBLK *dev, BYTE code, BYTE flags,
        BYTE chained, U16 count, BYTE prevcode, int ccwseq,
        BYTE *iobuf, BYTE *more, BYTE *unitstat, U16 *residual)
{
int             rc = 0;                 /* Return code               */
int             i;                      /* Loop counter              */
int             num;                    /* Number of bytes to move   */
char           *eor;                    /* -> end of record string   */
char           *nls = "\n\n\n";         /* -> new lines              */
BYTE            c;                      /* Print character           */
char            hex[3];                 /* for hex conversion        */
char            wbuf[150];

    /* Reset flags at start of CCW chain */
    if (chained == 0)
    {
        dev->diaggate = 0;
    }

    /* Open the device file if necessary */
    if (dev->fd < 0 && !IS_CCW_SENSE(code))
        rc = open_printer (dev);
    else
    {
        /* If printer stopped, return intervention required */
        if (dev->stopdev && !IS_CCW_SENSE(code))
            rc = -1;
        else
            rc = 0;
    }

    if (rc < 0)
    {
        /* Set unit check with intervention required */
        dev->sense[0] = SENSE_IR;
        *unitstat = CSW_UC;
        return;
    }

    /* Process depending on CCW opcode */

    switch (code) {

    case 0x01: /* Write     No Space             */
    case 0x09: /* Write and Space 1 Line         */
    case 0x11: /* Write and Space 2 Lines        */
    case 0x19: /* Write and Space 3 Lines        */

    case 0x89: /* Write and Skip to Channel 1    */
    case 0x91: /* Write and Skip to Channel 2    */
    case 0x99: /* Write and Skip to Channel 3    */
    case 0xA1: /* Write and Skip to Channel 4    */
    case 0xA9: /* Write and Skip to Channel 5    */
    case 0xB1: /* Write and Skip to Channel 6    */
    case 0xB9: /* Write and Skip to Channel 7    */
    case 0xC1: /* Write and Skip to Channel 8    */
    case 0xC9: /* Write and Skip to Channel 9    */
    case 0xD1: /* Write and Skip to Channel 10   */
    case 0xD9: /* Write and Skip to Channel 11   */
    case 0xE1: /* Write and Skip to Channel 12   */
        if (dev->rawcc)
        {
            sprintf(hex,"%02x",code);
            write_buffer(dev, hex, 2, unitstat);
            if (*unitstat != 0) return;
            WRITE_LINE();
            write_buffer(dev, "\n", 1, unitstat);
            if (*unitstat == 0)
                *unitstat = CSW_CE | CSW_DE;
            return;
        }

        if ( dev->browse && dev->ccpend && ((chained & CCW_FLAGS_CD) == 0) )
        {
            dev->ccpend = 0;
            /* dev->currline++; */
            write_buffer(dev, "\n", 1, unitstat);
            if (*unitstat != 0) return;
        }
        WRITE_LINE();
        if ((flags & CCW_FLAGS_CD) == 0)
        {
            if    ( code <= 0x80 ) /* line control */
            {
                coun = code / 8;
                if ( coun == 0 )
                {
                    dev->chskip = 1;
                    if ( dev->browse )
                    {
                        dev->ccpend = 1;
                        *unitstat = 0;
                    }
                    else
                        write_buffer(dev, "\r", 1, unitstat);
                    if (*unitstat == 0)
                        *unitstat = CSW_CE | CSW_DE;
                    return;
                }

                dev->ccpend = 0;
                dev->currline += coun;
                write_buffer(dev, nls, coun, unitstat);
                if (*unitstat == 0)
                    *unitstat = CSW_CE | CSW_DE;
                return;
            }
            else  /*code >  0x80*/ /* chan control */
            {
                /*
                if ( dev->browse )
                {
                    dev->currline++;
                    write_buffer(dev, "\n", 1, unitstat);
                    if (*unitstat != 0) return;
                }
                */
                chan = ( code - 128 ) / 8;
                if ( chan == 1 )
                {
                    write_buffer(dev, "\r", 1, unitstat);
                    if (*unitstat != 0)
                        return;
                }
                SKIP_TO_CHAN();
                if (*unitstat == 0)
                    *unitstat = CSW_CE | CSW_DE;
                return;
            }

        }
        *unitstat = CSW_CE | CSW_DE;
        return;

    case 0x03: /* No Operation                   */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x0B: /*           Space 1 Line         */
    case 0x13: /*           Space 2 Lines        */
    case 0x1B: /*           Space 3 Lines        */

    case 0x8B: /*           Skip to Channel 1    */
    case 0x93: /*           Skip to Channel 2    */
    case 0x9B: /*           Skip to Channel 3    */
    case 0xA3: /*           Skip to Channel 4    */
    case 0xAB: /*           Skip to Channel 5    */
    case 0xB3: /*           Skip to Channel 6    */
    case 0xBB: /*           Skip to Channel 7    */
    case 0xC3: /*           Skip to Channel 8    */
    case 0xCB: /*           Skip to Channel 9    */
    case 0xD3: /*           Skip to Channel 10   */
    case 0xDB: /*           Skip to Channel 11   */
    case 0xE3: /*           Skip to Channel 12   */
        if (dev->rawcc)
        {
            sprintf(hex,"%02x",code);
            write_buffer(dev, hex, 2, unitstat);
            if (*unitstat != 0) return;
            eor = (dev->crlf) ? "\r\n" : "\n";
            write_buffer(dev, eor, (int)strlen(eor), unitstat);
            if (*unitstat == 0)
                *unitstat = CSW_CE | CSW_DE;
            return;
        }

        if    ( code <= 0x80 ) /* line control */
        {
            coun = code / 8;
            dev->ccpend = 0;
            dev->currline += coun;
            write_buffer(dev, nls, coun, unitstat);
            if (*unitstat == 0)
                *unitstat = CSW_CE | CSW_DE;
            return;
        }
        else  /*code >  0x80*/ /* chan control */
        {
            /*
            if ( dev->browse && dev->ccpend)
            {
                coun = 1;
                dev->ccpend = 0;
                dev->currline += coun;
                write_buffer(dev, nls, coun, unitstat);
                if (*unitstat != 0) return;
            }
            */
            chan = ( code - 128 ) / 8;
            SKIP_TO_CHAN();
            if (*unitstat == 0)
                *unitstat = CSW_CE | CSW_DE;
            return;
        }
        break;

    case 0x63:
    /*---------------------------------------------------------------*/
    /* LOAD FORMS CONTROL BUFFER                                     */
    /*---------------------------------------------------------------*/
        if (dev->rawcc)
        {
            sprintf(hex,"%02x",code);
            write_buffer(dev, hex, 2, unitstat);
            if (*unitstat != 0) return;
            for (i = 0; i < count; i++)
            {
                sprintf(hex,"%02x",iobuf[i]);
                dev->buf[i*2] = hex[0];
                dev->buf[i*2+1] = hex[1];
            } /* end for(i) */
            write_buffer(dev, (char *)dev->buf, i*2, unitstat);
            if (*unitstat != 0) return;
            eor = (dev->crlf) ? "\r\n" : "\n";
            write_buffer(dev, eor, (int)strlen(eor), unitstat);
            if (*unitstat != 0) return;
        }
        else
        {
            int i = 0;
            int j = 1;
            int more = 1;
            for (i = 0; i <= FCBSIZE; i++) dev->fcb[i] = 0;

            dev->lpi = 6;
            dev->index = 0;
            if (iobuf[0] & 0xc0)
            {
                /* First byte is a print position index */
                if ((iobuf[0] & 0xc0) == 0x80)
                    /* Indexing right */
                    dev->index = iobuf[0] & 0x1f;
                else
                    /* Indexing left */
                    dev->index = - (iobuf[0] & 0x1f);
                i = 1;
            }

            for (; i < count && j <= FCBSIZE && more; i++, j++)
            {
                dev->fcb[i] = iobuf[i] & 0x0f;
                if (dev->fcb[j] > 12)
                {
                    *residual = count - i;
                    *unitstat = CSW_CE | CSW_DE | CSW_UC;
                    dev->sense[0] = SENSE_CC;
                    return;
                }

                if (iobuf[i] & 0x10)
                {
                    /* Flag bit is on */
                    if (j == 1)
                        /* Flag bit in first byte means eight lines per inch */
                        dev->lpi = 8;
                    else
                        more = 0;
                }
            }
            if (more)
            {
                /* No flag in last byte or too many bytes */
                *residual = count - i;
                *unitstat = CSW_CE | CSW_DE | CSW_UC;
                dev->sense[0] = SENSE_CC;
                return;
            }
            *residual = count - i;
            dev->lpp = j - 1;

            fcb_dump(dev, wbuf, 150);
            WRMSG(HHC02210, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, wbuf );
        }
        /* Return normal status */
        *residual = 0;
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x06:
    /*---------------------------------------------------------------*/
    /* DIAGNOSTIC CHECK READ                                         */
    /*---------------------------------------------------------------*/
        /* If not 1403, reject if not preceded by DIAGNOSTIC GATE */
        if (dev->devtype != 0x1403 && dev->diaggate == 0)
        {
            dev->sense[0] = SENSE_CR;
            *unitstat = CSW_CE | CSW_DE | CSW_UC;
            break;
        }

        /* Return normal status */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x07:
    /*---------------------------------------------------------------*/
    /* DIAGNOSTIC GATE                                               */
    /*---------------------------------------------------------------*/
        /* Command reject if 1403, or if chained to another CCW
           except a no-operation at the start of the CCW chain */
        if (dev->devtype == 0x1403 || ccwseq > 1
            || (chained && prevcode != 0x03))
        {
            dev->sense[0] = SENSE_CR;
            *unitstat = CSW_CE | CSW_DE | CSW_UC;
            break;
        }

        /* Set diagnostic gate flag */
        dev->diaggate = 1;

        /* Return normal status */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x0A:
    /*---------------------------------------------------------------*/
    /* DIAGNOSTIC READ UCS BUFFER                                    */
    /*---------------------------------------------------------------*/
        /* Reject if 1403 or not preceded by DIAGNOSTIC GATE */
        if (dev->devtype == 0x1403 || dev->diaggate == 0)
        {
            dev->sense[0] = SENSE_CR;
            *unitstat = CSW_CE | CSW_DE | CSW_UC;
            break;
        }

        /* Return normal status */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x12:
    /*---------------------------------------------------------------*/
    /* DIAGNOSTIC READ fcb                                           */
    /*---------------------------------------------------------------*/
        /* Reject if 1403 or not preceded by DIAGNOSTIC GATE */
        if (dev->devtype == 0x1403 || dev->diaggate == 0)
        {
            dev->sense[0] = SENSE_CR;
            *unitstat = CSW_CE | CSW_DE | CSW_UC;
            break;
        }

        /* Return normal status */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x23:
    /*---------------------------------------------------------------*/
    /* UNFOLD                                                        */
    /*---------------------------------------------------------------*/
        dev->fold = 0;
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x43:
    /*---------------------------------------------------------------*/
    /* FOLD                                                          */
    /*---------------------------------------------------------------*/
        dev->fold = 1;
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x73:
    /*---------------------------------------------------------------*/
    /* BLOCK DATA CHECK                                              */
    /*---------------------------------------------------------------*/
    /*
        *residual = 0;
    */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x7B:
    /*---------------------------------------------------------------*/
    /* ALLOW DATA CHECK                                              */
    /*---------------------------------------------------------------*/
    /*
        *residual = 0;
    */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0xEB:
    /*---------------------------------------------------------------*/
    /* UCS GATE LOAD                                                 */
    /*---------------------------------------------------------------*/
        /* Command reject if not first command in chain */
        if (chained != 0)
        {
            dev->sense[0] = SENSE_CR;
            *unitstat = CSW_CE | CSW_DE | CSW_UC;
            break;
        }

        /* Return normal status */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0xF3:
    /*---------------------------------------------------------------*/
    /* LOAD UCS BUFFER AND FOLD                                      */
    /*---------------------------------------------------------------*/
        /* For 1403, command reject if not chained to UCS GATE */
        /* Also allow ALLOW DATA CHECK to get TSS/370 working  */
        /* -- JRM 11/28/2007 */
        if (dev->devtype == 0x1403 &&
            ((prevcode != 0xEB) && (prevcode != 0x7B)))
        {
            dev->sense[0] = SENSE_CR;
            *unitstat = CSW_CE | CSW_DE | CSW_UC;
            break;
        }

        /* Set fold indicator and return normal status */
        dev->fold = 1;
        dev->chskip = 1;
    /*
        *residual = 0;
    */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0xFB:
    /*---------------------------------------------------------------*/
    /* LOAD UCS BUFFER (NO FOLD)                                     */
    /*---------------------------------------------------------------*/
        /* For 1403, command reject if not chained to UCS GATE */
        if (dev->devtype == 0x1403 && prevcode != 0xEB)
        {
            dev->sense[0] = SENSE_CR;
            *unitstat = CSW_CE | CSW_DE | CSW_UC;
            break;
        }

        /* Reset fold indicator and return normal status */
        dev->fold = 0;
        dev->chskip = 1;

    /*
        *residual = 0;
    */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0x04:
    /*---------------------------------------------------------------*/
    /* SENSE                                                         */
    /*---------------------------------------------------------------*/
        /* Calculate residual byte count */
        num = (count < dev->numsense) ? count : dev->numsense;
        *residual = count - num;
        if (count < dev->numsense) *more = 1;

        /* Copy device sense bytes to channel I/O buffer */
        memcpy (iobuf, dev->sense, num);

        /* Clear the device sense bytes */
        memset (dev->sense, 0, sizeof(dev->sense));

        /* Return unit status */
        *unitstat = CSW_CE | CSW_DE;
        break;

    case 0xE4:
    /*---------------------------------------------------------------*/
    /* SENSE ID                                                      */
    /*---------------------------------------------------------------*/

        /* SENSE ID is only supported if LEGACYSENSEID is ON;
         * otherwise, fall through to invalid operation.
         */
        if (sysblk.legacysenseid)
        {
            /* Calculate residual byte count */
            num = (count < dev->numdevid) ? count : dev->numdevid;
            *residual = count - num;
            if (count < dev->numdevid) *more = 1;

            /* Copy device identifier bytes to channel I/O buffer */
            memcpy (iobuf, dev->devid, num);

            /* Return unit status */
            *unitstat = CSW_CE | CSW_DE;
            break;
        }

    default:
    /*---------------------------------------------------------------*/
    /* INVALID OPERATION                                             */
    /*---------------------------------------------------------------*/
        /* Set command reject sense byte, and unit check status */
        dev->sense[0] = SENSE_CR;
        *unitstat = CSW_UC;

    } /* end switch(code) */

} /* end function printer_execute_ccw */
Example #8
0
void server(int lpnumber)
{
	struct rlimit resourcelimit;
#ifdef	USE_GETPROTOBYNAME
	struct protoent *proto;
#endif
	int netfd = -1, fd, lp, one = 1;
	int open_sleep = 10;
	socklen_t clientlen;
	struct sockaddr_storage client;
	struct addrinfo hints, *res, *ressave;
	char pidfilename[sizeof(PIDFILE)];
	char service[10];	// 9100 (65535 max)
	FILE *f;
	const int bufsiz = 65536;

#ifndef	TESTING
	if (!log_to_stdout)
	{
		switch (fork()) {
		case -1:
			dolog(LOGOPTS, "fork: %m\n");
			exit(1);
		case 0:		/* child */
			break;
		default:		/* parent */
			exit(0);
		}
		/* Now in child process */
		resourcelimit.rlim_max = 0;
		if (getrlimit(RLIMIT_NOFILE, &resourcelimit) < 0) {
			dolog(LOGOPTS, "getrlimit: %m\n");
			exit(1);
		}
		for (fd = 0; fd < resourcelimit.rlim_max; ++fd)
			(void)close(fd);
		if (setsid() < 0) {
			dolog(LOGOPTS, "setsid: %m\n");
			exit(1);
		}
		(void)chdir("/");
		(void)umask(022);
		fd = open("/dev/null", O_RDWR);	/* stdin */
		(void)dup(fd);		/* stdout */
		(void)dup(fd);		/* stderr */
		(void)snprintf(pidfilename, sizeof(pidfilename), PIDFILE, lpnumber);
		if ((f = fopen(pidfilename, "w")) == NULL) {
			dolog(LOGOPTS, "%s: %m\n", pidfilename);
			exit(1);
		}
		(void)fprintf(f, "%d\n", getpid());
		(void)fclose(f);
	}
	if (get_lock(lpnumber) == 0)
		exit(1);
#endif
	memset(&hints, 0, sizeof(hints));
	hints.ai_family = PF_UNSPEC;
	hints.ai_flags = AI_PASSIVE;
	hints.ai_socktype = SOCK_STREAM;
	(void)snprintf(service, sizeof(service), "%hu", (BASEPORT + lpnumber - '0'));
	if (getaddrinfo(bindaddr, service, &hints, &res) != 0) {
		dolog(LOGOPTS, "getaddr: %m\n");
		exit(1);
	}
	ressave = res;
	while (res) {
#ifdef	USE_GETPROTOBYNAME
		if ((proto = getprotobyname("tcp6")) == NULL) {
			if ((proto = getprotobyname("tcp")) == NULL) {
				dolog(LOGOPTS, "Cannot find protocol for TCP!\n");
				exit(1);
			}
		}
		if ((netfd = socket(res->ai_family, res->ai_socktype, proto->p_proto)) < 0)
#else
		if ((netfd = socket(res->ai_family, res->ai_socktype, IPPROTO_IP)) < 0)
#endif
		{
			dolog(LOGOPTS, "socket: %m\n");
			close(netfd);
			res = res->ai_next;
			continue;
		}
		if (setsockopt(netfd, SOL_SOCKET, SO_RCVBUF, &bufsiz, sizeof(bufsiz)) < 0) {
			dolog(LOGOPTS, "setsocketopt: SO_RCVBUF: %m\n");
			/* not fatal if it fails */
		}
		if (setsockopt(netfd, SOL_SOCKET, SO_SNDBUF, &bufsiz, sizeof(bufsiz)) < 0) {
			dolog(LOGOPTS, "setsocketopt: SO_SNDBUF: %m\n");
			/* not fatal if it fails */
		}
		if (setsockopt(netfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) {
			dolog(LOGOPTS, "setsocketopt: SO_REUSEADDR: %m\n");
			close(netfd);
			res = res->ai_next;
			continue;
		}
		if (bind(netfd, res->ai_addr, res->ai_addrlen) < 0) {
			dolog(LOGOPTS, "bind: %m\n");
			close(netfd);
			res = res->ai_next;
			continue;
		}
		if (listen(netfd, 5) < 0) {
			dolog(LOGOPTS, "listen: %m\n");
			close(netfd);
			res = res->ai_next;
			continue;
		}
		break;
	}
	freeaddrinfo(ressave);
	clientlen = sizeof(client);
	memset(&client, 0, sizeof(client));
	while ((fd = accept(netfd, (struct sockaddr *)&client, &clientlen)) >= 0) {
		char host[INET6_ADDRSTRLEN];
#ifdef	USE_LIBWRAP
		if (hosts_ctl("p910nd", STRING_UNKNOWN, get_ip_str((struct sockaddr *)&client, host, sizeof(host)), STRING_UNKNOWN) == 0) {
			dolog(LOGOPTS,
			       "Connection from %s port %hu rejected\n", get_ip_str((struct sockaddr *)&client, host, sizeof(host)), get_port((struct sockaddr *)&client));
			close(fd);
			continue;
		}
#endif
		dolog(LOG_NOTICE, "Connection from %s port %hu accepted\n", get_ip_str((struct sockaddr *)&client, host, sizeof(host)), get_port((struct sockaddr *)&client));
		/*write(fd, "Printing", 8); */

		/* Make sure lp device is open... */
		while ((lp = open_printer(lpnumber)) == -1) {
			sleep(open_sleep);
			if (open_sleep < 320) /* ~5 min interval to avoid spam in syslog */
				open_sleep *= 2;
		}
		open_sleep = 10;

		if (copy_stream(fd, lp) < 0)
			dolog(LOGOPTS, "copy_stream: %m\n");
		(void)close(fd);
		(void)close(lp);
	}
	dolog(LOGOPTS, "accept: %m\n");
	free_lock();
	exit(1);
}
Example #9
0
void  print_index( void )
{
	int ref ;
	short print_all = FALSE ;
	short print_list = FALSE ;
	Str_prt_params params ;
	short i ;
	char *start_str, *end_str ;
	int start_index, end_index ;
	short button ;

	if( rsrc_form_alert( 0, PRINT_ALL ) == 1 )
		print_all = TRUE ;
	else if( ref = get_person_reference( NULL, TRUE ) )
		print_list = TRUE ;
	if( !print_all && !print_list )  return ;
	
	if( open_printer( &params ) )
	{	
		params.ref1 = 0 ;			/* Do not print references.	*/
		params.ref2 = 0 ;


		params.align = LEFT ;		/* printout alignment				*/
		params.max_len = 0 ;		/* maximum length in character widths	*/
		params.last_x_end = 0 ;
		params.y_pos = 0 ;
		params.tabpos = 0 ;		/* relative position of second string	*/
		
		if( print_all )
		{	
			start_str = FORM_TEXT( range_ptr, START_INDEX ) ;
			end_str = FORM_TEXT( range_ptr, END_INDEX ) ;
			sprintf( start_str, "%d", 1 ) ;
			sprintf( end_str, "%d", next_person - 1 ) ;

			app_modal_init( range_ptr, "", TITLED ) ;
			button = app_modal_do() ;
			if( button != APP_MODAL_TERM )
			{
				range_ptr[INDEX_RANGE_OK].ob_state &= ~SELECTED ;

				start_index = atoi( start_str ) ;
				end_index = atoi( end_str ) ;
			}
			app_modal_end() ;
			
			if( button != APP_MODAL_TERM )
			{
				if( start_index < 1 || end_index > next_person - 1
											|| end_index < start_index )
					rsrc_form_alert( 1, INVALID_RANGE ) ;
				else
				{
					busy( BUSY_MORE ) ;

					start_print_checking( &params ) ;
	
					for( i=start_index;  printing_ok( &params ) && i<=end_index; i++ )
						if( people[i].birth_date != DELETED_DATE )
						print_idx_person( i, &params ) ;
					busy( BUSY_LESS ) ;
				}
			}
		}
		else if( print_list )
		{	
			busy( BUSY_MORE ) ;

			start_print_checking( &params ) ;
	
			i = 0 ;
			while(  printing_ok( &params ) && ( ref = matches[i++] ) )
				print_idx_person( ref, &params ) ;
			busy( BUSY_LESS ) ;
		}
	
		end_page( &params, FALSE ) ;
		close_printer( &params ) ;
	}
}
Example #10
0
void  tree_print( int trunk )
{
	Tree_params tree_params ;
	Str_prt_params params ;
	short max_gens ;
	short x_offset ;
	char underlines[80] ;
	short sidestep ;
	short verts[MAX_GENS+1] ;
	short val, offset ;						/* temporary values used in	*/
											/* optimisation of x_offset	*/
	short generation ;
	short i ;
	int x ;					/* int needed as max lines returned for	*/
							/* file is 7FFF, and extra 2 would go	*/
							/* negative								*/

	if( !trunk )  trunk = get_person_reference( NULL, FALSE ) ;
	if( !trunk )  return ;		/* exit if nobody selected			*/

	if( open_printer( &params ) )
	{
		start_print_checking( &params ) ;

		params.ref1 = trunk ;
		params.ref2 = 0 ;			/* Do not print second reference.	*/
		busy( BUSY_MORE ) ;

		x = (int) params.chs_up + 2 ;	/* calculate max generations vertically	*/
		max_gens = 0 ;
		while( x > 3 && max_gens < MAX_GENS )
		{	x >>= 1 ;
			max_gens++ ;
		}
		tree_params.ref = trunk ;
		tree_params.generation = 1 ;
		tree_params.max_generations = max_gens ;		/* temporary values	*/
		tree_params.position = 1 ;
		tree_params.right_limit = params.chs_across * params.cell_width ;
		for( i=0; i<MAX_TREE_SIZE; i++ )
		{
			tree_names[i][0] = '\0' ;
			tree_dates[i][0] = '\0' ;
		}

		load_tree_strings( tree_params ) ;

						/* For each generation find value of offset which	*/
						/* would just allow name to fit. The offset is set	*/
						/* to the minimum of these to ensure that all		*/
						/* generations fit. Normally but not always it will	*/
						/* be the last generation that is critical.			*/
						/* Space allowed is width minus 2 to allow for		*/
						/* spaces at start and end of print.				*/
		offset = params.chs_across ;	/* initialise to excessive value	*/
		for( generation = 2; generation <= max_gens; generation++ )
		{
			val = ( params.chs_across - 2 - name_max_found[generation] )
														/ ( generation - 1 ) ;
			if( val < offset )  offset = val ;
		}
		if( offset <= 0 )  offset = 1 ;
		x_offset = params.cell_width * offset ;
		tree_params.x_offsets = x_offset ;

		if(  printing_ok( &params ) && params.prn_handle )
		{
			tree_params.ch_width = params.cell_width ;
			tree_params.x_position = params.cell_width + params.x_offset ;
			tree_params.ch_height = params.cell_height ;
			tree_params.y_min = 2 + params.y_offset ;
			tree_params.y_max = params.chs_up * params.cell_height - 2 + params.y_offset ;
			tree_params.line_start_x = 0 ;
			tree_params.line_start_y = 0 ;

			draw_person( params.prn_handle, tree_params ) ;
		}
		else if(  printing_ok( &params ) && params.fp )
		{
			if( x_offset > 16 )  sidestep = 8 ;
			else  sidestep = x_offset / 2 ;
			for( i=0; i < x_offset - sidestep - 1; i++ )
				underlines[i] = '_' ;
			underlines[i] = '\0' ;
			for( i=0; i<MAX_GENS + 1; i++ )  verts[i] = 0 ;
			params.y_pos = 0 ;
			params.downlines = 1 ;
			params.tabpos = x_offset - sidestep - 1 ;
			params.align = LEFT ;
			params.x_pos = 0 ;
			params.last_x_end = 0 ;

			std_print_tree_person( tree_params, &params, verts, underlines,
															sidestep ) ;
		}

		end_page( &params, FALSE ) ;
		close_printer( &params ) ;
		busy( BUSY_LESS ) ;
	}
Example #11
0
int Job_status( int *sock, char *input )
{
	char *s, *t, *name, *hash_key;
	int displayformat, status_lines = 0, i, n;
	struct line_list l, listv;
	struct line_list done_list;
	char error[SMALLBUFFER], buffer[16];
	int db, dbflag;
	
	FILE *READSTATUSFILE;//JY1120
	char readbuffer[SMALLBUFFER];//JY1120
	char *str_index;//JY1120

#if !defined(JYWENG20031104status)
	if( input && *input ) ++input;//JY1114
	if(get_queue_name(input))
	{
		printf("QueueName is not LPRServer\n");
		send_ack_packet(sock, ACK_FAIL);//JY1120
		return(0);
	}
	else
	{
		printf("QueueName is LPRServer\n");
	}

	int prnstatus=1;
	char buffertosend[LARGEBUFFER];
	int fdPRNPARorUSB = open_printer(); /*JYWENG20031104*/

	if(fdPRNPARorUSB == 0)
	{
		printf("file descriptor not created\n");
		send_ack_packet(sock, ACK_FAIL);//JY1120
		return(0);	
	}
//	ioctl(fdPRNPARorUSB, 0x060b, &prnstatus);
//	if(prnstatus == 0)
//JY1120
	if((READSTATUSFILE=fopen("/var/state/printstatus.txt", "r")) == NULL)
	{
		printf("open /var/state/printstatus.txt failed!\n");
		send_ack_packet(sock, ACK_FAIL);//JY1120
		return(0);		
	}
	while( fgets(readbuffer, SMALLBUFFER, READSTATUSFILE) != NULL)
	{
		if((str_index = strstr(readbuffer, "PRINTER_STATUS=\"")))
		{
			str_index += 16;//moving to status
			strncpy(printerstatus, str_index, strlen(str_index) - 2 );	
		}
	}
//JY1120	

	SNPRINTF(buffertosend, sizeof(buffertosend))"Status: %s\n", printerstatus);
//	else
//		SNPRINTF(buffertosend, sizeof(buffertosend))"Status: Off line\n");
//	if( Write_fd_str( *sock, buffertosend ) < 0 ) cleanup(0);
	if( write( *sock, buffertosend, strlen(buffertosend) ) < 0 ) cleanup(0);
	exit(0);//JY1120
	
#endif


#ifdef REMOVE
	Init_line_list(&l);
	Init_line_list(&listv);
	Init_line_list(&done_list);
	db = Debug;
	dbflag = DbgFlag;

	Name = "Job_status";

	/* get the format */
	if( (s = safestrchr(input, '\n' )) ) *s = 0;
	displayformat = *input++;

	/*
	 * if we get a short/long request from these hosts,
	 * reverse the sense of question
	 */
	if( Reverse_lpq_status_DYN
		&& (displayformat == REQ_DSHORT || displayformat==REQ_DLONG)  ){
		Free_line_list(&l);
		Split(&l,Reverse_lpq_status_DYN,File_sep,0,0,0,0,0,0);
		if( Match_ipaddr_value( &l, &RemoteHost_IP ) == 0 ){
			DEBUGF(DLPQ1)("Job_status: reversing status sense");
			if( displayformat == REQ_DSHORT ){
				displayformat = REQ_DLONG;
			} else {
				displayformat = REQ_DSHORT;
			}
		}
		Free_line_list(&l);
	}
	/*
	 * we have a list of hosts with format of the form:
	 *  Key=list; Key=list;...
	 *  key is s for short, l for long
	 */
	DEBUGF(DLPQ1)("Job_status: Force_lpq_status_DYN '%s'", Force_lpq_status_DYN);
	if( Force_lpq_status_DYN ){
		Free_line_list(&listv);
		Split(&listv,Force_lpq_status_DYN,";",0,0,0,0,0,0);
		for(i = 0; i < listv.count; ++i ){
			s = listv.list[i];
			if( (t = safestrpbrk(s,File_sep)) ) *t++ = 0;
			Free_line_list(&l);
			Split(&l,t,Value_sep,0,0,0,0,0,0);
			DEBUGF(DLPQ1)("Job_status: Force_lpq_status '%s'='%s'", s,t);
			if( Match_ipaddr_value( &l, &RemoteHost_IP ) == 0 ){
				DEBUGF(DLPQ1)("Job_status: forcing status '%s'", s);
				if( safestrcasecmp(s,"s") == 0 ){
					displayformat = REQ_DSHORT;
				} else if( safestrcasecmp(s,"l") == 0 ){
					displayformat = REQ_DLONG;
				}
				status_lines = Short_status_length_DYN;
				break;
			}
		}
		Free_line_list(&l);
		Free_line_list(&listv);
	}

	/*
	 * check for short status to be returned
	 */

	if( Return_short_status_DYN && displayformat == REQ_DLONG ){
		Free_line_list(&l);
		Split(&l,Return_short_status_DYN,File_sep,0,0,0,0,0,0);
		if( Match_ipaddr_value( &l, &RemoteHost_IP ) == 0 ){
			status_lines = Short_status_length_DYN;
			DEBUGF(DLPQ1)("Job_status: truncating status to %d",
				status_lines);
		}
		Free_line_list(&l);
	}

	DEBUGF(DLPQ1)("Job_status: doing '%s'", input );
	Free_line_list(&l);
	Split(&l,input,Whitespace,0,0,0,0,0,0);
	if( l.count == 0 ){
		SNPRINTF( error, sizeof(error)) "zero length command line");
		goto error;
	}