wa::storage::cloud_queue get_queue(bool create)
{
    wa::storage::cloud_queue_client client = get_queue_client();
    utility::string_t queue_name = get_queue_name();
    wa::storage::cloud_queue queue = client.get_queue_reference(queue_name);
    if (create)
    {
        queue.create_if_not_exists();
    }
    return queue;
}
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=0;/*JYWENG20031104*/
	if((check_par_usb_prn())== 1)
		fdPRNPARorUSB=open("/dev/usb/lp0",O_RDWR);
	else
		fdPRNPARorUSB=open("/dev/lp0",O_RDWR);

	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;
	}
Example #3
0
int Receive_job( int *sock, char *input )
{
	char line[SMALLBUFFER];		/* line buffer for input */
	char error[SMALLBUFFER];	/* line buffer for input */
	char buffer[SMALLBUFFER];	/* line buffer for input */
	int errlen = sizeof(error);
	char *tempfile;				/* name of temp file */
	double file_len;			/* length of file */
	double read_len;			/* amount to read from sock */
	double jobsize = 0;			/* size of job */
	int ack = 0;				/* ack to send */
	int status = 0;				/* status of the last command */
	double len;					/* length of last read */
	char *s, *filename;			/* name of control or data file */
	int temp_fd = -1;				/* used for file opening and locking */
	int filetype;				/* type of file - control or data */
	int fd;						/* for log file */
	int hold_fd = -1;				/* hold file */
	int db, dbf, rlen;
	int fifo_fd = -1;			/* fifo lock file */
	struct line_list files, info, l;
	struct job job;
	struct stat statb;

#ifdef REMOVE
#ifdef WINDOW_1//JYWeng
//aaaaaa=fopen("/tmp/pp", "a");
//fprintf(aaaaaa, "lpd_rcvjobs.c\n");
//fclose(aaaaaa);
#endif
#ifdef JYDEBUG//JYWeng
aaaaaa=fopen("/tmp/qqqqq", "a");
fprintf(aaaaaa, "Receive_job: check point 1\n");
fclose(aaaaaa);
#endif
#endif
	Init_line_list(&l);
	Init_line_list(&files);
	Init_line_list(&info);
	Init_job(&job);

	Name = "RECV";

	if( input && *input ) ++input;
	Clean_meta(input);
	Split(&info,input,Whitespace,0,0,0,0,0,0);

//printf("Receive_job!\n");//JY1107
/*JY1113: test QueueName*/
	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");
/**/

#ifdef ORIGINAL_DEBUG//JY@1020
	DEBUGFC(DRECV1)Dump_line_list("Receive_job: input", &info );
#endif
	if( info.count != 1 ){
		SNPRINTF( error, errlen) _("bad command line") );
		goto error;
	}