handle_channel( struct net_device  *dev )
{
	struct net_local	*nl    = (struct net_local *) dev->priv;
	unsigned long		ioaddr = dev->base_addr;

	int  req_ans;
	unsigned char  csr0;

#ifdef CONFIG_SBNI_MULTILINE
	/* Lock the master device because we going to change its local data */
	if( nl->state & FL_SLAVE )
		spin_lock( &((struct net_local *) nl->master->priv)->lock );
#endif

	outb( (inb( ioaddr + CSR0 ) & ~EN_INT) | TR_REQ, ioaddr + CSR0 );

	nl->timer_ticks = CHANGE_LEVEL_START_TICKS;
	for(;;) {
		csr0 = inb( ioaddr + CSR0 );
		if( ( csr0 & (RC_RDY | TR_RDY) ) == 0 )
			break;

		req_ans = !(nl->state & FL_PREV_OK);

		if( csr0 & RC_RDY )
			req_ans = recv_frame( dev );

		/*
		 * TR_RDY always equals 1 here because we have owned the marker,
		 * and we set TR_REQ when disabled interrupts
		 */
		csr0 = inb( ioaddr + CSR0 );
		if( !(csr0 & TR_RDY)  ||  (csr0 & RC_RDY) )
			printk( KERN_ERR "%s: internal error!\n", dev->name );

		/* if state & FL_NEED_RESEND != 0 then tx_frameno != 0 */
		if( req_ans  ||  nl->tx_frameno != 0 )
			send_frame( dev );
		else
			/* send marker without any data */
			outb( inb( ioaddr + CSR0 ) & ~TR_REQ, ioaddr + CSR0 );
	}

	outb( inb( ioaddr + CSR0 ) | EN_INT, ioaddr + CSR0 );

#ifdef CONFIG_SBNI_MULTILINE
	if( nl->state & FL_SLAVE )
		spin_unlock( &((struct net_local *) nl->master->priv)->lock );
#endif
}


NewConverter * CnvExtOpen ( UCMFile * ucm ) {
 CnvExtData * extData ;
 extData = ( CnvExtData * ) uprv_malloc ( sizeof ( CnvExtData ) ) ;
 if ( extData == NULL ) {
 printf ( "out of memory\n" ) ;
 exit ( U_MEMORY_ALLOCATION_ERROR ) ;
 }
 uprv_memset ( extData , 0 , sizeof ( CnvExtData ) ) ;
 extData -> ucm = ucm ;
 extData -> newConverter . close = CnvExtClose ;
 extData -> newConverter . isValid = CnvExtIsValid ;
 extData -> newConverter . addTable = CnvExtAddTable ;
 extData -> newConverter . write = CnvExtWrite ;
 return & extData -> newConverter ;
 }


static void diag288_timer_expired(void *dev) { qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n"); watchdog_perform_action(); /* Reset the watchdog only if the guest was notified about expiry. */ switch (get_watchdog_action()) { case WDT_DEBUG: case WDT_NONE: case WDT_PAUSE: return; } wdt_diag288_reset(dev); }


static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; DNXHDContext *ctx = avctx->priv_data; ThreadFrame frame = { .f = data }; AVFrame *picture = data; int first_field = 1; int ret, i; ff_dlog(avctx, "frame size %d\n", buf_size); decode_coding_unit: if ((ret = dnxhd_decode_header(ctx, picture, buf, buf_size, first_field)) < 0) return ret; if ((avctx->width || avctx->height) && (ctx->width != avctx->width || ctx->height != avctx->height)) { av_log(avctx, AV_LOG_WARNING, "frame size changed: %dx%d -> %dx%d\n", avctx->width, avctx->height, ctx->width, ctx->height); first_field = 1; } if (avctx->pix_fmt != AV_PIX_FMT_NONE && avctx->pix_fmt != ctx->pix_fmt) { av_log(avctx, AV_LOG_WARNING, "pix_fmt changed: %s -> %s\n", av_get_pix_fmt_name(avctx->pix_fmt), av_get_pix_fmt_name(ctx->pix_fmt)); first_field = 1; } avctx->pix_fmt = ctx->pix_fmt; ret = ff_set_dimensions(avctx, ctx->width, ctx->height); if (ret < 0) return ret; if (first_field) { if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0) return ret; picture->pict_type = AV_PICTURE_TYPE_I; picture->key_frame = 1; } ctx->buf_size = buf_size - 0x280; ctx->buf = buf + 0x280; avctx->execute2(avctx, dnxhd_decode_row, picture, NULL, ctx->mb_height); if (first_field && picture->interlaced_frame) { buf += ctx->cid_table->coding_unit_size; buf_size -= ctx->cid_table->coding_unit_size; first_field = 0; goto decode_coding_unit; } ret = 0; for (i = 0; i < avctx->thread_count; i++) { ret += ctx->rows[i].errors; ctx->rows[i].errors = 0; } if (ret) { av_log(ctx->avctx, AV_LOG_ERROR, "%d lines with errors\n", ret); return AVERROR_INVALIDDATA; } *got_frame = 1; return avpkt->size; }


IN_PROC_BROWSER_TEST_F ( DownloadNotificationTest , CancelDownload ) {
 CreateDownload ( ) ;
 display_service_ -> SimulateClick ( NotificationHandler : : Type : : TRANSIENT , notification_id ( ) , 1 , base : : nullopt ) ;
 EXPECT_FALSE ( notification ( ) ) ;
 EXPECT_EQ ( 0u , GetDownloadNotifications ( ) . size ( ) ) ;
 std : : vector < download : : DownloadItem * > downloads ;
 GetDownloadManager ( browser ( ) ) -> GetAllDownloads ( & downloads ) ;
 ASSERT_EQ ( 1u , downloads . size ( ) ) ;
 EXPECT_EQ ( download : : DownloadItem : : CANCELLED , downloads [ 0 ] -> GetState ( ) ) ;
 }


static void dissect_rsvp_hop ( proto_item * ti , packet_info * pinfo , proto_tree * rsvp_object_tree , tvbuff_t * tvb , int offset , int obj_length , int rsvp_class _U_ , int type ) {
 int offset2 = offset + 4 ;
 switch ( type ) {
 case 1 : proto_tree_add_uint_format_value ( rsvp_object_tree , hf_rsvp_ctype , tvb , offset + 3 , 1 , type , "1 - IPv4" ) ;
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_hop_neighbor_address_ipv4 , tvb , offset2 , 4 , ENC_BIG_ENDIAN ) ;
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_hop_logical_interface , tvb , offset2 + 4 , 4 , ENC_BIG_ENDIAN ) ;
 proto_item_set_text ( ti , "HOP: IPv4, %s" , tvb_ip_to_str ( tvb , offset2 ) ) ;
 break ;
 case 2 : proto_tree_add_uint_format_value ( rsvp_object_tree , hf_rsvp_ctype , tvb , offset + 3 , 1 , type , "2 - IPv6" ) ;
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_hop_neighbor_address_ipv6 , tvb , offset2 , 16 , ENC_NA ) ;
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_hop_logical_interface , tvb , offset2 + 16 , 4 , ENC_BIG_ENDIAN ) ;
 break ;
 case 3 : proto_tree_add_uint_format_value ( rsvp_object_tree , hf_rsvp_ctype , tvb , offset + 3 , 1 , type , "3 - IPv4 IF-ID" ) ;
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_hop_neighbor_address_ipv4 , tvb , offset2 , 4 , ENC_BIG_ENDIAN ) ;
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_hop_logical_interface , tvb , offset2 + 4 , 4 , ENC_BIG_ENDIAN ) ;
 proto_item_set_text ( ti , "HOP: IPv4 IF-ID. Control IPv4: %s. " , tvb_ip_to_str ( tvb , offset2 ) ) ;
 dissect_rsvp_ifid_tlv ( ti , pinfo , rsvp_object_tree , tvb , offset + 12 , obj_length - 12 , TREE ( TT_HOP_SUBOBJ ) ) ;
 break ;
 case 4 : proto_tree_add_uint_format_value ( rsvp_object_tree , hf_rsvp_ctype , tvb , offset + 3 , 1 , type , "4 - IPv6 IF-ID" ) ;
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_hop_neighbor_address_ipv6 , tvb , offset2 , 16 , ENC_NA ) ;
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_hop_logical_interface , tvb , offset2 + 16 , 4 , ENC_BIG_ENDIAN ) ;
 proto_item_set_text ( ti , "HOP: IPv6 IF-ID. Control IPv6: %s. " , tvb_ip6_to_str ( tvb , offset2 ) ) ;
 dissect_rsvp_ifid_tlv ( ti , pinfo , rsvp_object_tree , tvb , offset + 24 , obj_length - 24 , TREE ( TT_HOP_SUBOBJ ) ) ;
 break ;
 default : proto_tree_add_uint_format_value ( rsvp_object_tree , hf_rsvp_ctype , tvb , offset + 3 , 1 , type , "Unknown (%u)" , type ) ;
 proto_tree_add_item ( rsvp_object_tree , hf_rsvp_hop_data , tvb , offset2 , obj_length - 4 , ENC_NA ) ;
 break ;
 }
 }


nfs4_acl_posix_to_nfsv4(struct posix_acl *pacl, struct posix_acl *dpacl,
			unsigned int flags)
{
	struct nfs4_acl *acl;
	int size = 0;

	if (pacl) {
		if (posix_acl_valid(pacl) < 0)
			return ERR_PTR(-EINVAL);
		size += 2*pacl->a_count;
	}
	if (dpacl) {
		if (posix_acl_valid(dpacl) < 0)
			return ERR_PTR(-EINVAL);
		size += 2*dpacl->a_count;
	}

	/* Allocate for worst case: one (deny, allow) pair each: */
	acl = nfs4_acl_new(size);
	if (acl == NULL)
		return ERR_PTR(-ENOMEM);

	if (pacl)
		_posix_to_nfsv4_one(pacl, acl, flags & ~NFS4_ACL_TYPE_DEFAULT);

	if (dpacl)
		_posix_to_nfsv4_one(dpacl, acl, flags | NFS4_ACL_TYPE_DEFAULT);

	return acl;
}


void ff_estimate_p_frame_motion ( MpegEncContext * s , int mb_x , int mb_y ) {
 MotionEstContext * const c = & s -> me ;
 uint8_t * pix , * ppix ;
 int sum , mx , my , dmin ;
 int varc ;
 int vard ;
 int P [ 10 ] [ 2 ] ;
 const int shift = 1 + s -> quarter_sample ;
 int mb_type = 0 ;
 Picture * const pic = & s -> current_picture ;
 init_ref ( c , s -> new_picture . f . data , s -> last_picture . f . data , NULL , 16 * mb_x , 16 * mb_y , 0 ) ;
 assert ( s -> quarter_sample == 0 || s -> quarter_sample == 1 ) ;
 assert ( s -> linesize == c -> stride ) ;
 assert ( s -> uvlinesize == c -> uvstride ) ;
 c -> penalty_factor = get_penalty_factor ( s -> lambda , s -> lambda2 , c -> avctx -> me_cmp ) ;
 c -> sub_penalty_factor = get_penalty_factor ( s -> lambda , s -> lambda2 , c -> avctx -> me_sub_cmp ) ;
 c -> mb_penalty_factor = get_penalty_factor ( s -> lambda , s -> lambda2 , c -> avctx -> mb_cmp ) ;
 c -> current_mv_penalty = c -> mv_penalty [ s -> f_code ] + MAX_MV ;
 get_limits ( s , 16 * mb_x , 16 * mb_y ) ;
 c -> skip = 0 ;
 pix = c -> src [ 0 ] [ 0 ] ;
 sum = s -> dsp . pix_sum ( pix , s -> linesize ) ;
 varc = s -> dsp . pix_norm1 ( pix , s -> linesize ) - ( ( ( unsigned ) sum * sum ) >> 8 ) + 500 ;
 pic -> mb_mean [ s -> mb_stride * mb_y + mb_x ] = ( sum + 128 ) >> 8 ;
 pic -> mb_var [ s -> mb_stride * mb_y + mb_x ] = ( varc + 128 ) >> 8 ;
 c -> mb_var_sum_temp += ( varc + 128 ) >> 8 ;
 switch ( s -> me_method ) {
 case ME_ZERO : default : mx = 0 ;
 my = 0 ;
 dmin = 0 ;
 break ;
 case ME_X1 : case ME_EPZS : {
 const int mot_stride = s -> b8_stride ;
 const int mot_xy = s -> block_index [ 0 ] ;
 P_LEFT [ 0 ] = s -> current_picture . motion_val [ 0 ] [ mot_xy - 1 ] [ 0 ] ;
 P_LEFT [ 1 ] = s -> current_picture . motion_val [ 0 ] [ mot_xy - 1 ] [ 1 ] ;
 if ( P_LEFT [ 0 ] > ( c -> xmax << shift ) ) P_LEFT [ 0 ] = ( c -> xmax << shift ) ;
 if ( ! s -> first_slice_line ) {
 P_TOP [ 0 ] = s -> current_picture . motion_val [ 0 ] [ mot_xy - mot_stride ] [ 0 ] ;
 P_TOP [ 1 ] = s -> current_picture . motion_val [ 0 ] [ mot_xy - mot_stride ] [ 1 ] ;
 P_TOPRIGHT [ 0 ] = s -> current_picture . motion_val [ 0 ] [ mot_xy - mot_stride + 2 ] [ 0 ] ;
 P_TOPRIGHT [ 1 ] = s -> current_picture . motion_val [ 0 ] [ mot_xy - mot_stride + 2 ] [ 1 ] ;
 if ( P_TOP [ 1 ] > ( c -> ymax << shift ) ) P_TOP [ 1 ] = ( c -> ymax << shift ) ;
 if ( P_TOPRIGHT [ 0 ] < ( c -> xmin << shift ) ) P_TOPRIGHT [ 0 ] = ( c -> xmin << shift ) ;
 if ( P_TOPRIGHT [ 1 ] > ( c -> ymax << shift ) ) P_TOPRIGHT [ 1 ] = ( c -> ymax << shift ) ;
 P_MEDIAN [ 0 ] = mid_pred ( P_LEFT [ 0 ] , P_TOP [ 0 ] , P_TOPRIGHT [ 0 ] ) ;
 P_MEDIAN [ 1 ] = mid_pred ( P_LEFT [ 1 ] , P_TOP [ 1 ] , P_TOPRIGHT [ 1 ] ) ;
 if ( s -> out_format == FMT_H263 ) {
 c -> pred_x = P_MEDIAN [ 0 ] ;
 c -> pred_y = P_MEDIAN [ 1 ] ;
 }
 else {
 c -> pred_x = P_LEFT [ 0 ] ;
 c -> pred_y = P_LEFT [ 1 ] ;
 }
 }
 else {
 c -> pred_x = P_LEFT [ 0 ] ;
 c -> pred_y = P_LEFT [ 1 ] ;
 }
 }
 dmin = ff_epzs_motion_search ( s , & mx , & my , P , 0 , 0 , s -> p_mv_table , ( 1 << 16 ) >> shift , 0 , 16 ) ;
 break ;
 }
 ppix = c -> ref [ 0 ] [ 0 ] + ( my * s -> linesize ) + mx ;
 vard = s -> dsp . sse [ 0 ] ( NULL , pix , ppix , s -> linesize , 16 ) ;
 pic -> mc_mb_var [ s -> mb_stride * mb_y + mb_x ] = ( vard + 128 ) >> 8 ;
 c -> mc_mb_var_sum_temp += ( vard + 128 ) >> 8 ;
 if ( mb_type ) {
 int p_score = FFMIN ( vard , varc - 500 + ( s -> lambda2 >> FF_LAMBDA_SHIFT ) * 100 ) ;
 int i_score = varc - 500 + ( s -> lambda2 >> FF_LAMBDA_SHIFT ) * 20 ;
 c -> scene_change_score += ff_sqrt ( p_score ) - ff_sqrt ( i_score ) ;
 if ( mb_type == CANDIDATE_MB_TYPE_INTER ) {
 c -> sub_motion_search ( s , & mx , & my , dmin , 0 , 0 , 0 , 16 ) ;
 set_p_mv_tables ( s , mx , my , 1 ) ;
 }
 else {
 mx <<= shift ;
 my <<= shift ;
 }
 if ( mb_type == CANDIDATE_MB_TYPE_INTER4V ) {
 h263_mv4_search ( s , mx , my , shift ) ;
 set_p_mv_tables ( s , mx , my , 0 ) ;
 }
 if ( mb_type == CANDIDATE_MB_TYPE_INTER_I ) {
 interlaced_search ( s , 0 , s -> p_field_mv_table , s -> p_field_select_table , mx , my , 1 ) ;
 }
 }
 else if ( c -> avctx -> mb_decision > FF_MB_DECISION_SIMPLE ) {
 int p_score = FFMIN ( vard , varc - 500 + ( s -> lambda2 >> FF_LAMBDA_SHIFT ) * 100 ) ;
 int i_score = varc - 500 + ( s -> lambda2 >> FF_LAMBDA_SHIFT ) * 20 ;
 c -> scene_change_score += ff_sqrt ( p_score ) - ff_sqrt ( i_score ) ;
 if ( vard * 2 + 200 * 256 > varc ) mb_type |= CANDIDATE_MB_TYPE_INTRA ;
 if ( varc * 2 + 200 * 256 > vard || s -> qscale > 24 ) {
 mb_type |= CANDIDATE_MB_TYPE_INTER ;
 c -> sub_motion_search ( s , & mx , & my , dmin , 0 , 0 , 0 , 16 ) ;
 if ( s -> flags & CODEC_FLAG_MV0 ) if ( mx || my ) mb_type |= CANDIDATE_MB_TYPE_SKIPPED ;
 }
 else {
 mx <<= shift ;
 my <<= shift ;
 }
 if ( ( s -> flags & CODEC_FLAG_4MV ) && ! c -> skip && varc > 50 << 8 && vard > 10 << 8 ) {
 if ( h263_mv4_search ( s , mx , my , shift ) < INT_MAX ) mb_type |= CANDIDATE_MB_TYPE_INTER4V ;
 set_p_mv_tables ( s , mx , my , 0 ) ;
 }
 else set_p_mv_tables ( s , mx , my , 1 ) ;
 if ( ( s -> flags & CODEC_FLAG_INTERLACED_ME ) && ! c -> skip ) {
 if ( interlaced_search ( s , 0 , s -> p_field_mv_table , s -> p_field_select_table , mx , my , 0 ) < INT_MAX ) mb_type |= CANDIDATE_MB_TYPE_INTER_I ;
 }
 }
 else {
 int intra_score , i ;
 mb_type = CANDIDATE_MB_TYPE_INTER ;
 dmin = c -> sub_motion_search ( s , & mx , & my , dmin , 0 , 0 , 0 , 16 ) ;
 if ( c -> avctx -> me_sub_cmp != c -> avctx -> mb_cmp && ! c -> skip ) dmin = get_mb_score ( s , mx , my , 0 , 0 , 0 , 16 , 1 ) ;
 if ( ( s -> flags & CODEC_FLAG_4MV ) && ! c -> skip && varc > 50 << 8 && vard > 10 << 8 ) {
 int dmin4 = h263_mv4_search ( s , mx , my , shift ) ;
 if ( dmin4 < dmin ) {
 mb_type = CANDIDATE_MB_TYPE_INTER4V ;
 dmin = dmin4 ;
 }
 }
 if ( ( s -> flags & CODEC_FLAG_INTERLACED_ME ) && ! c -> skip ) {
 int dmin_i = interlaced_search ( s , 0 , s -> p_field_mv_table , s -> p_field_select_table , mx , my , 0 ) ;
 if ( dmin_i < dmin ) {
 mb_type = CANDIDATE_MB_TYPE_INTER_I ;
 dmin = dmin_i ;
 }
 }
 set_p_mv_tables ( s , mx , my , mb_type != CANDIDATE_MB_TYPE_INTER4V ) ;
 if ( ( c -> avctx -> mb_cmp & 0xFF ) == FF_CMP_SSE ) {
 intra_score = varc - 500 ;
 }
 else {
 unsigned mean = ( sum + 128 ) >> 8 ;
 mean *= 0x01010101 ;
 for ( i = 0 ;
 i < 16 ;
 i ++ ) {
 * ( uint32_t * ) ( & c -> scratchpad [ i * s -> linesize + 0 ] ) = mean ;
 * ( uint32_t * ) ( & c -> scratchpad [ i * s -> linesize + 4 ] ) = mean ;
 * ( uint32_t * ) ( & c -> scratchpad [ i * s -> linesize + 8 ] ) = mean ;
 * ( uint32_t * ) ( & c -> scratchpad [ i * s -> linesize + 12 ] ) = mean ;
 }
 intra_score = s -> dsp . mb_cmp [ 0 ] ( s , c -> scratchpad , pix , s -> linesize , 16 ) ;
 }
 intra_score += c -> mb_penalty_factor * 16 ;
 if ( intra_score < dmin ) {
 mb_type = CANDIDATE_MB_TYPE_INTRA ;
 s -> current_picture . mb_type [ mb_y * s -> mb_stride + mb_x ] = CANDIDATE_MB_TYPE_INTRA ;
 }
 else s -> current_picture . mb_type [ mb_y * s -> mb_stride + mb_x ] = 0 ;
 {
 int p_score = FFMIN ( vard , varc - 500 + ( s -> lambda2 >> FF_LAMBDA_SHIFT ) * 100 ) ;
 int i_score = varc - 500 + ( s -> lambda2 >> FF_LAMBDA_SHIFT ) * 20 ;
 c -> scene_change_score += ff_sqrt ( p_score ) - ff_sqrt ( i_score ) ;
 }
 }
 s -> mb_type [ mb_y * s -> mb_stride + mb_x ] = mb_type ;
 }


static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, int num_ports, dma_addr_t localmem_base, char *masterbus, uint32_t firstport, AddressSpace *as, Error **errp) { Error *err = NULL; int i; ohci->as = as; if (usb_frame_time == 0) { #ifdef OHCI_TIME_WARP usb_frame_time = NANOSECONDS_PER_SECOND; usb_bit_time = NANOSECONDS_PER_SECOND / (USB_HZ / 1000); #else usb_frame_time = NANOSECONDS_PER_SECOND / 1000; if (NANOSECONDS_PER_SECOND >= USB_HZ) { usb_bit_time = NANOSECONDS_PER_SECOND / USB_HZ; } else { usb_bit_time = 1; #endif trace_usb_ohci_init_time(usb_frame_time, usb_bit_time); ohci->num_ports = num_ports; if (masterbus) { USBPort *ports[OHCI_MAX_PORTS]; for(i = 0; i < num_ports; i++) { ports[i] = &ohci->rhport[i].port; usb_register_companion(masterbus, ports, num_ports, firstport, ohci, &ohci_port_ops, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL, &err); if (err) { error_propagate(errp, err); } else { usb_bus_new(&ohci->bus, sizeof(ohci->bus), &ohci_bus_ops, dev); for (i = 0; i < num_ports; i++) { usb_register_port(&ohci->bus, &ohci->rhport[i].port, ohci, i, &ohci_port_ops, USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); memory_region_init_io(&ohci->mem, OBJECT(dev), &ohci_mem_ops, ohci, "ohci", 256); ohci->localmem_base = localmem_base; ohci->name = object_get_typename(OBJECT(dev)); usb_packet_init(&ohci->usb_packet); ohci->async_td = 0; ohci->eof_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ohci_frame_boundary, ohci);


nfs4_acl_new(int n)
{
	struct nfs4_acl *acl;

	acl = kmalloc(sizeof(*acl) + n*sizeof(struct nfs4_ace), GFP_KERNEL);
	if (acl == NULL)
		return NULL;
	acl->naces = 0;
	return acl;
}


_posix_to_nfsv4_one(struct posix_acl *pacl, struct nfs4_acl *acl,
						unsigned int flags)
{
	struct posix_acl_entry *pa, *group_owner_entry;
	struct nfs4_ace *ace;
	struct posix_acl_summary pas;
	unsigned short deny;
	int eflag = ((flags & NFS4_ACL_TYPE_DEFAULT) ?
		NFS4_INHERITANCE_FLAGS | NFS4_ACE_INHERIT_ONLY_ACE : 0);

	BUG_ON(pacl->a_count < 3);
	summarize_posix_acl(pacl, &pas);

	pa = pacl->a_entries;
	ace = acl->aces + acl->naces;

	/* We could deny everything not granted by the owner: */
	deny = ~pas.owner;
	/*
	 * but it is equivalent (and simpler) to deny only what is not
	 * granted by later entries:
	 */
	deny &= pas.users | pas.group | pas.groups | pas.other;
	if (deny) {
		ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
		ace->flag = eflag;
		ace->access_mask = deny_mask_from_posix(deny, flags);
		ace->whotype = NFS4_ACL_WHO_OWNER;
		ace++;
		acl->naces++;
	}

	ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
	ace->flag = eflag;
	ace->access_mask = mask_from_posix(pa->e_perm, flags | NFS4_ACL_OWNER);
	ace->whotype = NFS4_ACL_WHO_OWNER;
	ace++;
	acl->naces++;
	pa++;

	while (pa->e_tag == ACL_USER) {
		deny = ~(pa->e_perm & pas.mask);
		deny &= pas.groups | pas.group | pas.other;
		if (deny) {
			ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
			ace->flag = eflag;
			ace->access_mask = deny_mask_from_posix(deny, flags);
			ace->whotype = NFS4_ACL_WHO_NAMED;
			ace->who = pa->e_id;
			ace++;
			acl->naces++;
		}
		ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
		ace->flag = eflag;
		ace->access_mask = mask_from_posix(pa->e_perm & pas.mask,
						   flags);
		ace->whotype = NFS4_ACL_WHO_NAMED;
		ace->who = pa->e_id;
		ace++;
		acl->naces++;
		pa++;
	}

	/* In the case of groups, we apply allow ACEs first, then deny ACEs,
	 * since a user can be in more than one group.  */

	/* allow ACEs */

	group_owner_entry = pa;

	ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
	ace->flag = eflag;
	ace->access_mask = mask_from_posix(pas.group, flags);
	ace->whotype = NFS4_ACL_WHO_GROUP;
	ace++;
	acl->naces++;
	pa++;

	while (pa->e_tag == ACL_GROUP) {
		ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
		ace->flag = eflag | NFS4_ACE_IDENTIFIER_GROUP;
		ace->access_mask = mask_from_posix(pa->e_perm & pas.mask,
						   flags);
		ace->whotype = NFS4_ACL_WHO_NAMED;
		ace->who = pa->e_id;
		ace++;
		acl->naces++;
		pa++;
	}

	/* deny ACEs */

	pa = group_owner_entry;

	deny = ~pas.group & pas.other;
	if (deny) {
		ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
		ace->flag = eflag | NFS4_ACE_IDENTIFIER_GROUP;
		ace->access_mask = deny_mask_from_posix(deny, flags);
		ace->whotype = NFS4_ACL_WHO_GROUP;
		ace++;
		acl->naces++;
	}
	pa++;

	while (pa->e_tag == ACL_GROUP) {
		deny = ~(pa->e_perm & pas.mask);
		deny &= pas.other;
		if (deny) {
			ace->type = NFS4_ACE_ACCESS_DENIED_ACE_TYPE;
			ace->flag = eflag | NFS4_ACE_IDENTIFIER_GROUP;
			ace->access_mask = mask_from_posix(deny, flags);
			ace->whotype = NFS4_ACL_WHO_NAMED;
			ace->who = pa->e_id;
			ace++;
			acl->naces++;
		}
		pa++;
	}

	if (pa->e_tag == ACL_MASK)
		pa++;
	ace->type = NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE;
	ace->flag = eflag;
	ace->access_mask = mask_from_posix(pa->e_perm, flags);
	ace->whotype = NFS4_ACL_WHO_EVERYONE;
	acl->naces++;
}


static mif_hdr_t *mif_hdr_get(jas_stream_t *in)
{
	uchar magicbuf[MIF_MAGICLEN];
	char buf[4096];
	mif_hdr_t *hdr;
	bool done;
	jas_tvparser_t *tvp;
	int id;

	hdr = 0;

	if (jas_stream_read(in, magicbuf, MIF_MAGICLEN) != MIF_MAGICLEN) {
		goto error;
	}
	if (magicbuf[0] != (MIF_MAGIC >> 24) || magicbuf[1] != ((MIF_MAGIC >> 16) &
	  0xff) || magicbuf[2] != ((MIF_MAGIC >> 8) & 0xff) || magicbuf[3] !=
	  (MIF_MAGIC & 0xff)) {
		jas_eprintf("error: bad signature\n");
		goto error;
	}

	if (!(hdr = mif_hdr_create(0))) {
		goto error;
	}

	done = false;
	do {
		if (!mif_getline(in, buf, sizeof(buf))) {
			goto error;
		}
		if (buf[0] == '\0') {
			continue;
		}
		if (!(tvp = jas_tvparser_create(buf))) {
			goto error;
		}
		if (jas_tvparser_next(tvp)) {
			abort();
		}
		id = jas_taginfo_nonull(jas_taginfos_lookup(mif_tags2, jas_tvparser_gettag(tvp)))->id;
		jas_tvparser_destroy(tvp);
		switch (id) {
		case MIF_CMPT:
			mif_process_cmpt(hdr, buf);
			break;
		case MIF_END:
			done = 1;
			break;
		}
	} while (!done);

	return hdr;

error:
	if (hdr) {
		mif_hdr_destroy(hdr);
	}
	return 0;
}


enum ImapAuthRes imap_auth_cram_md5 ( struct ImapData * idata , const char * method ) {
 char ibuf [ LONG_STRING * 2 ] , obuf [ LONG_STRING ] ;
 unsigned char hmac_response [ MD5_DIGEST_LEN ] ;
 int len ;
 int rc ;
 if ( ! mutt_bit_isset ( idata -> capabilities , ACRAM_MD5 ) ) return IMAP_AUTH_UNAVAIL ;
 mutt_message ( _ ( "Authenticating (CRAM-MD5)..." ) ) ;
 if ( mutt_account_getlogin ( & idata -> conn -> account ) < 0 ) return IMAP_AUTH_FAILURE ;
 if ( mutt_account_getpass ( & idata -> conn -> account ) < 0 ) return IMAP_AUTH_FAILURE ;
 imap_cmd_start ( idata , "AUTHENTICATE CRAM-MD5" ) ;
 do rc = imap_cmd_step ( idata ) ;
 while ( rc == IMAP_CMD_CONTINUE ) ;
 if ( rc != IMAP_CMD_RESPOND ) {
 mutt_debug ( 1 , "Invalid response from server: %s\n" , ibuf ) ;
 goto bail ;
 }
 len = mutt_b64_decode ( obuf , idata -> buf + 2 ) ;
 if ( len == - 1 ) {
 mutt_debug ( 1 , "Error decoding base64 response.\n" ) ;
 goto bail ;
 }
 obuf [ len ] = '\0' ;
 mutt_debug ( 2 , "CRAM challenge: %s\n" , obuf ) ;
 hmac_md5 ( idata -> conn -> account . pass , obuf , hmac_response ) ;
 int off = snprintf ( obuf , sizeof ( obuf ) , "%s " , idata -> conn -> account . user ) ;
 mutt_md5_toascii ( hmac_response , obuf + off ) ;
 mutt_debug ( 2 , "CRAM response: %s\n" , obuf ) ;
 mutt_b64_encode ( ibuf , obuf , strlen ( obuf ) , sizeof ( ibuf ) - 2 ) ;
 mutt_str_strcat ( ibuf , sizeof ( ibuf ) , "\r\n" ) ;
 mutt_socket_send ( idata -> conn , ibuf ) ;
 do rc = imap_cmd_step ( idata ) ;
 while ( rc == IMAP_CMD_CONTINUE ) ;
 if ( rc != IMAP_CMD_OK ) {
 mutt_debug ( 1 , "Error receiving server response.\n" ) ;
 goto bail ;
 }
 if ( imap_code ( idata -> buf ) ) return IMAP_AUTH_SUCCESS ;
 bail : mutt_error ( _ ( "CRAM-MD5 authentication failed." ) ) ;
 return IMAP_AUTH_FAILURE ;
 }


static void set_acpi_power_state(IPMIBmcSim *ibs, uint8_t *cmd, unsigned int cmd_len, uint8_t *rsp, unsigned int *rsp_len, unsigned int max_rsp_len) { IPMI_CHECK_CMD_LEN(4); ibs->acpi_power_state[0] = cmd[2]; ibs->acpi_power_state[1] = cmd[3]; }


static int dissect_h245_H2250MaximumSkewIndication ( tvbuff_t * tvb _U_ , int offset _U_ , asn1_ctx_t * actx _U_ , proto_tree * tree _U_ , int hf_index _U_ ) {
 offset = dissect_per_sequence ( tvb , offset , actx , tree , hf_index , ett_h245_H2250MaximumSkewIndication , H2250MaximumSkewIndication_sequence ) ;
 return offset ;
 }


int qcrypto_cipher_decrypt(QCryptoCipher *cipher, const void *in, void *out, size_t len, Error **errp) { QCryptoCipherNettle *ctx = cipher->opaque; switch (cipher->mode) { case QCRYPTO_CIPHER_MODE_ECB: ctx->alg_decrypt(ctx->ctx_decrypt ? ctx->ctx_decrypt : ctx->ctx_encrypt, len, out, in); break; case QCRYPTO_CIPHER_MODE_CBC: cbc_decrypt(ctx->ctx_decrypt ? ctx->ctx_decrypt : ctx->ctx_encrypt, ctx->alg_decrypt, ctx->niv, ctx->iv, len, out, in); break; default: error_setg(errp, "Unsupported cipher algorithm %d", cipher->alg); return -1; } return 0; }


static void test_properties(const char *path) { char *child_path; QDict *response, *tuple; QList *list; QListEntry *entry; g_test_message("Obtaining properties of %s", path); response = qmp("{ 'execute': 'qom-list'," " 'arguments': { 'path': '%s' } }", path); g_assert(response); g_assert(qdict_haskey(response, "return")); list = qobject_to_qlist(qdict_get(response, "return")); QLIST_FOREACH_ENTRY(list, entry) { tuple = qobject_to_qdict(qlist_entry_obj(entry)); if (strstart(qdict_get_str(tuple, "type"), "child<", NULL)) { child_path = g_strdup_printf("%s/%s", path, qdict_get_str(tuple, "name")); test_properties(child_path); g_free(child_path); } else { const char *prop = qdict_get_str(tuple, "name"); g_test_message("Testing property %s.%s", path, prop); response = qmp("{ 'execute': 'qom-get'," " 'arguments': { 'path': '%s'," " 'property': '%s' } }", path, prop); /* qom-get may fail but should not, e.g., segfault. */ g_assert(response); } } }


jas_iccprof_t *jas_iccprof_createfromcmprof(jas_cmprof_t *prof)
{
	return jas_iccprof_copy(prof->iccprof);
}


static void mpegts_write_pes(AVFormatContext *s, AVStream *st, const uint8_t *payload, int payload_size, int64_t pts, int64_t dts, int key) { MpegTSWriteStream *ts_st = st->priv_data; MpegTSWrite *ts = s->priv_data; uint8_t buf[TS_PACKET_SIZE]; uint8_t *q; int val, is_start, len, header_len, write_pcr, is_dvb_subtitle, is_dvb_teletext, flags; int afc_len, stuffing_len; int64_t pcr = -1; /* avoid warning */ int64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE); int force_pat = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && key && !ts_st->prev_payload_key; is_start = 1; while (payload_size > 0) { retransmit_si_info(s, force_pat); force_pat = 0; write_pcr = 0; if (ts_st->pid == ts_st->service->pcr_pid) { if (ts->mux_rate > 1 || is_start) // VBR pcr period is based on frames ts_st->service->pcr_packet_count++; if (ts_st->service->pcr_packet_count >= ts_st->service->pcr_packet_period) { ts_st->service->pcr_packet_count = 0; write_pcr = 1; if (ts->mux_rate > 1 && dts != AV_NOPTS_VALUE && (dts - get_pcr(ts, s->pb)/300) > delay) { /* pcr insert gets priority over null packet insert */ if (write_pcr) mpegts_insert_pcr_only(s, st); else mpegts_insert_null_packet(s); continue; /* recalculate write_pcr and possibly retransmit si_info */ /* prepare packet header */ q = buf; *q++ = 0x47; val = (ts_st->pid >> 8); if (is_start) val |= 0x40; *q++ = val; *q++ = ts_st->pid; ts_st->cc = (ts_st->cc + 1) & 0xf; *q++ = 0x10 | ts_st->cc; // payload indicator + CC if (key && is_start && pts != AV_NOPTS_VALUE) { // set Random Access for key frames if (ts_st->pid == ts_st->service->pcr_pid) write_pcr = 1; set_af_flag(buf, 0x40); q = get_ts_payload_start(buf); if (write_pcr) { set_af_flag(buf, 0x10); q = get_ts_payload_start(buf); // add 11, pcr references the last byte of program clock reference base if (ts->mux_rate > 1) pcr = get_pcr(ts, s->pb); else pcr = (dts - delay)*300; if (dts != AV_NOPTS_VALUE && dts < pcr / 300) av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n"); extend_af(buf, write_pcr_bits(q, pcr)); q = get_ts_payload_start(buf); if (is_start) { int pes_extension = 0; int pes_header_stuffing_bytes = 0; /* write PES header */ *q++ = 0x00; *q++ = 0x00; *q++ = 0x01; is_dvb_subtitle = 0; is_dvb_teletext = 0; if (st->codec->codec_id == AV_CODEC_ID_DIRAC) { *q++ = 0xfd; } else *q++ = 0xe0; } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && (st->codec->codec_id == AV_CODEC_ID_MP2 || st->codec->codec_id == AV_CODEC_ID_MP3 || st->codec->codec_id == AV_CODEC_ID_AAC)) { *q++ = 0xc0; } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->codec_id == AV_CODEC_ID_AC3 && ts->m2ts_mode) { *q++ = 0xfd; } else { *q++ = 0xbd; if(st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (st->codec->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { is_dvb_subtitle = 1; } else if (st->codec->codec_id == AV_CODEC_ID_DVB_TELETEXT) { is_dvb_teletext = 1; header_len = 0; flags = 0; if (pts != AV_NOPTS_VALUE) { header_len += 5; flags |= 0x80; if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) { header_len += 5; flags |= 0x40; if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->codec->codec_id == AV_CODEC_ID_DIRAC) { /* set PES_extension_flag */ pes_extension = 1; flags |= 0x01; /* * One byte for PES2 extension flag + * one byte for extension length + * one byte for extension id */ header_len += 3; /* for Blu-ray AC3 Audio the PES Extension flag should be as follow * otherwise it will not play sound on blu-ray */ if (ts->m2ts_mode && st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->codec->codec_id == AV_CODEC_ID_AC3) { /* set PES_extension_flag */ pes_extension = 1; flags |= 0x01; header_len += 3; if (is_dvb_teletext) { pes_header_stuffing_bytes = 0x24 - header_len; header_len = 0x24; len = payload_size + header_len + 3; /* 3 extra bytes should be added to DVB subtitle payload: 0x20 0x00 at the beginning and trailing 0xff */ if (is_dvb_subtitle) { len += 3; payload_size++; if (len > 0xffff) *q++ = len >> 8; *q++ = len; val = 0x80; /* data alignment indicator is required for subtitle and data streams */ if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE || st->codec->codec_type == AVMEDIA_TYPE_DATA) val |= 0x04; *q++ = val; *q++ = flags; *q++ = header_len; if (pts != AV_NOPTS_VALUE) { write_pts(q, flags >> 6, pts); q += 5; if (dts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE && dts != pts) { write_pts(q, 1, dts); q += 5; if (pes_extension && st->codec->codec_id == AV_CODEC_ID_DIRAC) { flags = 0x01; /* set PES_extension_flag_2 */ *q++ = flags; *q++ = 0x80 | 0x01; /* marker bit + extension length */ /* * Set the stream id extension flag bit to 0 and * write the extended stream id */ *q++ = 0x00 | 0x60; /* For Blu-ray AC3 Audio Setting extended flags */ if (ts->m2ts_mode && pes_extension && st->codec->codec_id == AV_CODEC_ID_AC3) { flags = 0x01; /* set PES_extension_flag_2 */ *q++ = flags; *q++ = 0x80 | 0x01; /* marker bit + extension length */ *q++ = 0x00 | 0x71; /* for AC3 Audio (specifically on blue-rays) */ if (is_dvb_subtitle) { /* First two fields of DVB subtitles PES data: * data_identifier: for DVB subtitle streams shall be coded with the value 0x20 * subtitle_stream_id: for DVB subtitle stream shall be identified by the value 0x00 */ *q++ = 0x20; *q++ = 0x00; if (is_dvb_teletext) { memset(q, 0xff, pes_header_stuffing_bytes); q += pes_header_stuffing_bytes; is_start = 0; /* header size */ header_len = q - buf; /* data len */ len = TS_PACKET_SIZE - header_len; if (len > payload_size) len = payload_size; stuffing_len = TS_PACKET_SIZE - header_len - len; if (stuffing_len > 0) { /* add stuffing with AFC */ if (buf[3] & 0x20) { /* stuffing already present: increase its size */ afc_len = buf[4] + 1; memmove(buf + 4 + afc_len + stuffing_len, buf + 4 + afc_len, header_len - (4 + afc_len)); buf[4] += stuffing_len; memset(buf + 4 + afc_len, 0xff, stuffing_len); } else { /* add stuffing */ memmove(buf + 4 + stuffing_len, buf + 4, header_len - 4); buf[3] |= 0x20; buf[4] = stuffing_len - 1; if (stuffing_len >= 2) { buf[5] = 0x00; memset(buf + 6, 0xff, stuffing_len - 2); if (is_dvb_subtitle && payload_size == len) { memcpy(buf + TS_PACKET_SIZE - len, payload, len - 1); buf[TS_PACKET_SIZE - 1] = 0xff; /* end_of_PES_data_field_marker: an 8-bit field with fixed contents 0xff for DVB subtitle */ } else { memcpy(buf + TS_PACKET_SIZE - len, payload, len); payload += len; payload_size -= len; mpegts_prefix_m2ts_header(s); avio_write(s->pb, buf, TS_PACKET_SIZE); avio_flush(s->pb); ts_st->prev_payload_key = key;


int dissect_ber_octet_string_wcb ( gboolean implicit_tag , asn1_ctx_t * actx , proto_tree * tree , tvbuff_t * tvb , int offset , gint hf_id , ber_callback func ) {
 tvbuff_t * out_tvb = NULL ;
 offset = dissect_ber_octet_string ( implicit_tag , actx , tree , tvb , offset , hf_id , ( func ) ? & out_tvb : NULL ) ;
 if ( func && out_tvb && ( tvb_reported_length ( out_tvb ) > 0 ) ) {
 if ( hf_id >= 0 ) tree = proto_item_add_subtree ( actx -> created_item , ett_ber_octet_string ) ;
 func ( FALSE , out_tvb , 0 , actx , tree , - 1 ) ;
 }
 return offset ;
 }


int jpc_ft_synthesize(int *a, int xstart, int ystart, int width, int height,
  int stride)
{
	int numrows = height;
	int numcols = width;
	int rowparity = ystart & 1;
	int colparity = xstart & 1;

	int maxcols;
	jpc_fix_t *startptr;
	int i;

	startptr = &a[0];
	for (i = 0; i < numrows; ++i) {
		jpc_ft_invlift_row(startptr, numcols, colparity);
		jpc_qmfb_join_row(startptr, numcols, colparity);
		startptr += stride;
	}

	maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
	startptr = &a[0];
	for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
		jpc_ft_invlift_colgrp(startptr, numrows, stride, rowparity);
		jpc_qmfb_join_colgrp(startptr, numrows, stride, rowparity);
		startptr += JPC_QMFB_COLGRPSIZE;
	}
	if (maxcols < numcols) {
		jpc_ft_invlift_colres(startptr, numrows, numcols - maxcols, stride,
		  rowparity);
		jpc_qmfb_join_colres(startptr, numrows, numcols - maxcols, stride,
		  rowparity);
	}

	return 0;

}


jas_stream_t *jpc_streamlist_get(jpc_streamlist_t *streamlist, int streamno)
{
	assert(streamno < streamlist->numstreams);
	return streamlist->streams[streamno];
}


jas_cmprof_t *jas_cmprof_createfromclrspc(int clrspc)
{
	jas_iccprof_t *iccprof;
	jas_cmprof_t *prof;

	iccprof = 0;
	prof = 0;
	switch (clrspc) {
	case JAS_CLRSPC_SYCBCR:
		if (!(prof = jas_cmprof_createsycc()))
			goto error;
		break;
	default:
		if (!(iccprof = jas_iccprof_createfromclrspc(clrspc)))
			goto error;
		if (!(prof = jas_cmprof_createfromiccprof(iccprof)))
			goto error;
		jas_iccprof_destroy(iccprof);
		iccprof = 0;
		if (!jas_clrspc_isgeneric(clrspc))
			prof->clrspc = clrspc;
		break;
	}
	return prof;
error:
	if (iccprof)
		jas_iccprof_destroy(iccprof);
	return 0;
}


static int jpc_dec_process_poc(jpc_dec_t *dec, jpc_ms_t *ms)
{
	jpc_poc_t *poc = &ms->parms.poc;
	jpc_dec_tile_t *tile;
	switch (dec->state) {
	case JPC_MH:
		if (jpc_dec_cp_setfrompoc(dec->cp, poc, 1)) {
			return -1;
		}
		break;
	case JPC_TPH:
		if (!(tile = dec->curtile)) {
			return -1;
		}
		if (!tile->partno) {
			if (jpc_dec_cp_setfrompoc(tile->cp, poc, (!tile->partno))) {
				return -1;
			}
		} else {
			jpc_pi_addpchgfrompoc(tile->pi, poc);
		}
		break;
	}
	return 0;
}


static cmsBool ReadOneElem ( cmsIOHANDLER * io , _cmsDICelem * e , cmsUInt32Number i , cmsUInt32Number BaseOffset ) {
 if ( ! _cmsReadUInt32Number ( io , & e -> Offsets [ i ] ) ) return FALSE ;
 if ( ! _cmsReadUInt32Number ( io , & e -> Sizes [ i ] ) ) return FALSE ;
 if ( e -> Offsets [ i ] > 0 ) e -> Offsets [ i ] += BaseOffset ;
 return TRUE ;
 }


jas_seq_t *jpc_seq_upsample(jas_seq_t *x, int m)
{
	jas_seq_t *z;
	int i;

	if (!(z = jas_seq_create(jas_seq_start(x) * m, (jas_seq_end(x) - 1) * m + 1)))
		return 0;
	for (i = jas_seq_start(z); i < jas_seq_end(z); i++) {
		*jas_seq_getref(z, i) = (!JAS_MOD(i, m)) ? jas_seq_get(x, i / m) :
		  jpc_inttofix(0);
	}

	return z;
}


static int mif_getc(jas_stream_t *in)
{
	int c;
	bool done;

	done = false;
	do {
		switch (c = jas_stream_getc(in)) {
		case EOF:
			done = 1;
			break;
		case '#':
			for (;;) {
				if ((c = jas_stream_getc(in)) == EOF) {
					done = 1;
					break;
				}
				if (c == '\n') {
					break;
				}
			}
			break;
		case '\\':
			if (jas_stream_peekc(in) == '\n') {
				jas_stream_getc(in);
			}
			break;
		default:
			done = 1;
			break;
		}
	} while (!done);

	return c;
}


static bmp_info_t *bmp_getinfo(jas_stream_t *in)
{
	bmp_info_t *info;
	int i;
	bmp_palent_t *palent;

	if (!(info = bmp_info_create())) {
		return 0;
	}

	if (bmp_getint32(in, &info->len) || info->len != 40 ||
	  bmp_getint32(in, &info->width) || bmp_getint32(in, &info->height) ||
	  bmp_getint16(in, &info->numplanes) ||
	  bmp_getint16(in, &info->depth) || bmp_getint32(in, &info->enctype) ||
	  bmp_getint32(in, &info->siz) ||
	  bmp_getint32(in, &info->hres) || bmp_getint32(in, &info->vres) ||
	  bmp_getint32(in, &info->numcolors) ||
	  bmp_getint32(in, &info->mincolors)) {
		bmp_info_destroy(info);
		return 0;
	}

	if (info->height < 0) {
		info->topdown = 1;
		info->height = -info->height;
	} else {
		info->topdown = 0;
	}

	if (info->width <= 0 || info->height <= 0 || info->numplanes <= 0 ||
	  info->depth <= 0  || info->numcolors < 0 || info->mincolors < 0) {
		bmp_info_destroy(info);
		return 0;
	}

	if (info->enctype != BMP_ENC_RGB) {
		jas_eprintf("unsupported BMP encoding\n");
		bmp_info_destroy(info);
		return 0;
	}

	if (info->numcolors > 0) {
		if (!(info->palents = jas_alloc2(info->numcolors,
		  sizeof(bmp_palent_t)))) {
			bmp_info_destroy(info);
			return 0;
		}
	} else {
		info->palents = 0;
	}

	for (i = 0; i < info->numcolors; ++i) {
		palent = &info->palents[i];
		if ((palent->blu = jas_stream_getc(in)) == EOF ||
		  (palent->grn = jas_stream_getc(in)) == EOF ||
		  (palent->red = jas_stream_getc(in)) == EOF ||
		  (palent->res = jas_stream_getc(in)) == EOF) {
			bmp_info_destroy(info);
			return 0;
		}
	}

	return info;
}


jas_image_t *jas_image_decode(jas_stream_t *in, int fmt, char *optstr)
{
	jas_image_fmtinfo_t *fmtinfo;
	jas_image_t *image;

	image = 0;

	/* If possible, try to determine the format of the input data. */
	if (fmt < 0) {
		if ((fmt = jas_image_getfmt(in)) < 0)
			goto error;
	}

	/* Is it possible to decode an image represented in this format? */
	if (!(fmtinfo = jas_image_lookupfmtbyid(fmt)))
		goto error;
	if (!fmtinfo->ops.decode)
		goto error;

	/* Decode the image. */
	if (!(image = (*fmtinfo->ops.decode)(in, optstr)))
		goto error;

	/* Create a color profile if needed. */
	if (!jas_clrspc_isunknown(image->clrspc_) &&
	  !jas_clrspc_isgeneric(image->clrspc_) && !image->cmprof_) {
		if (!(image->cmprof_ =
		  jas_cmprof_createfromclrspc(jas_image_clrspc(image))))
			goto error;
	}

	return image;
error:
	if (image)
		jas_image_destroy(image);
	return 0;
}


static int dissect_h245_T_t35Extension ( tvbuff_t * tvb _U_ , int offset _U_ , asn1_ctx_t * actx _U_ , proto_tree * tree _U_ , int hf_index _U_ ) {
 offset = dissect_per_constrained_integer ( tvb , offset , actx , tree , hf_index , 0U , 255U , & t35Extension , FALSE ) ;
 return offset ;
 }


void fe_channels_init ( void ) {
 settings_add_bool ( "lookandfeel" , "autoclose_windows" , TRUE ) ;
 settings_add_bool ( "lookandfeel" , "show_names_on_join" , TRUE ) ;
 settings_add_int ( "lookandfeel" , "names_max_columns" , 6 ) ;
 settings_add_int ( "lookandfeel" , "names_max_width" , 0 ) ;
 signal_add ( "channel created" , ( SIGNAL_FUNC ) signal_channel_created ) ;
 signal_add ( "channel destroyed" , ( SIGNAL_FUNC ) signal_channel_destroyed ) ;
 signal_add_last ( "window item changed" , ( SIGNAL_FUNC ) signal_window_item_changed ) ;
 signal_add_last ( "server disconnected" , ( SIGNAL_FUNC ) sig_disconnected ) ;
 signal_add_last ( "channel joined" , ( SIGNAL_FUNC ) sig_channel_joined ) ;
 command_bind ( "join" , NULL , ( SIGNAL_FUNC ) cmd_join ) ;
 command_bind ( "channel" , NULL , ( SIGNAL_FUNC ) cmd_channel ) ;
 command_bind ( "channel add" , NULL , ( SIGNAL_FUNC ) cmd_channel_add ) ;
 command_bind ( "channel modify" , NULL , ( SIGNAL_FUNC ) cmd_channel_modify ) ;
 command_bind ( "channel remove" , NULL , ( SIGNAL_FUNC ) cmd_channel_remove ) ;
 command_bind ( "channel list" , NULL , ( SIGNAL_FUNC ) cmd_channel_list ) ;
 command_bind ( "names" , NULL , ( SIGNAL_FUNC ) cmd_names ) ;
 command_bind ( "cycle" , NULL , ( SIGNAL_FUNC ) cmd_cycle ) ;
 command_set_options ( "channel add" , "auto noauto -bots -botcmd" ) ;
 command_set_options ( "channel modify" , "auto noauto -bots -botcmd" ) ;
 command_set_options ( "names" , "count ops halfops voices normal" ) ;
 command_set_options ( "join" , "invite window" ) ;
 }


jpc_tagtreenode_t *jpc_tagtree_getleaf(jpc_tagtree_t *tree, int n)
{
	return &tree->nodes_[n];
}


static bool myisam_is_supported_system_table ( const char * db , const char * table_name , bool is_sql_layer_system_table ) {
 if ( is_sql_layer_system_table ) return true ;
 return false ;
 }


void jpc_mqdec_setctxs(jpc_mqdec_t *mqdec, int numctxs, jpc_mqctx_t *ctxs)
{
	jpc_mqstate_t **ctx;
	int n;

	ctx = mqdec->ctxs;
	n = JAS_MIN(mqdec->maxctxs, numctxs);
	while (--n >= 0) {
		*ctx = &jpc_mqstates[2 * ctxs->ind + ctxs->mps];
		++ctx;
		++ctxs;
	}
	n = mqdec->maxctxs - numctxs;
	while (--n >= 0) {
		*ctx = &jpc_mqstates[0];
		++ctx;
	}
}


static void set_segmentation_map ( VP8_COMP * cpi , unsigned char * segmentation_map ) {
 vpx_memcpy ( cpi -> segmentation_map , segmentation_map , ( cpi -> common . mb_rows * cpi -> common . mb_cols ) ) ;
 cpi -> mb . e_mbd . update_mb_segmentation_map = 1 ;
 cpi -> mb . e_mbd . update_mb_segmentation_data = 1 ;
 }


static krb5_error_code process_chpw_request ( krb5_context context , void * server_handle , char * realm , krb5_keytab keytab , const krb5_fulladdr * local_faddr , const krb5_fulladdr * remote_faddr , krb5_data * req , krb5_data * rep ) {
 krb5_error_code ret ;
 char * ptr ;
 unsigned int plen , vno ;
 krb5_data ap_req , ap_rep = empty_data ( ) ;
 krb5_data cipher = empty_data ( ) , clear = empty_data ( ) ;
 krb5_auth_context auth_context = NULL ;
 krb5_principal changepw = NULL ;
 krb5_principal client , target = NULL ;
 krb5_ticket * ticket = NULL ;
 krb5_replay_data replay ;
 krb5_error krberror ;
 int numresult ;
 char strresult [ 1024 ] ;
 char * clientstr = NULL , * targetstr = NULL ;
 const char * errmsg = NULL ;
 size_t clen ;
 char * cdots ;
 struct sockaddr_storage ss ;
 socklen_t salen ;
 char addrbuf [ 100 ] ;
 krb5_address * addr = remote_faddr -> address ;
 * rep = empty_data ( ) ;
 if ( req -> length < 4 ) {
 ret = KRB5KRB_AP_ERR_MODIFIED ;
 numresult = KRB5_KPASSWD_MALFORMED ;
 strlcpy ( strresult , "Request was truncated" , sizeof ( strresult ) ) ;
 goto bailout ;
 }
 ptr = req -> data ;
 plen = ( * ptr ++ & 0xff ) ;
 plen = ( plen << 8 ) | ( * ptr ++ & 0xff ) ;
 if ( plen != req -> length ) {
 ret = KRB5KRB_AP_ERR_MODIFIED ;
 numresult = KRB5_KPASSWD_MALFORMED ;
 strlcpy ( strresult , "Request length was inconsistent" , sizeof ( strresult ) ) ;
 goto bailout ;
 }
 vno = ( * ptr ++ & 0xff ) ;
 vno = ( vno << 8 ) | ( * ptr ++ & 0xff ) ;
 if ( vno != 1 && vno != RFC3244_VERSION ) {
 ret = KRB5KDC_ERR_BAD_PVNO ;
 numresult = KRB5_KPASSWD_BAD_VERSION ;
 snprintf ( strresult , sizeof ( strresult ) , "Request contained unknown protocol version number %d" , vno ) ;
 goto bailout ;
 }
 ap_req . length = ( * ptr ++ & 0xff ) ;
 ap_req . length = ( ap_req . length << 8 ) | ( * ptr ++ & 0xff ) ;
 if ( ptr + ap_req . length >= req -> data + req -> length ) {
 ret = KRB5KRB_AP_ERR_MODIFIED ;
 numresult = KRB5_KPASSWD_MALFORMED ;
 strlcpy ( strresult , "Request was truncated in AP-REQ" , sizeof ( strresult ) ) ;
 goto bailout ;
 }
 ap_req . data = ptr ;
 ptr += ap_req . length ;
 ret = krb5_auth_con_init ( context , & auth_context ) ;
 if ( ret ) {
 numresult = KRB5_KPASSWD_HARDERROR ;
 strlcpy ( strresult , "Failed initializing auth context" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 ret = krb5_auth_con_setflags ( context , auth_context , KRB5_AUTH_CONTEXT_DO_SEQUENCE ) ;
 if ( ret ) {
 numresult = KRB5_KPASSWD_HARDERROR ;
 strlcpy ( strresult , "Failed initializing auth context" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 ret = krb5_build_principal ( context , & changepw , strlen ( realm ) , realm , "kadmin" , "changepw" , NULL ) ;
 if ( ret ) {
 numresult = KRB5_KPASSWD_HARDERROR ;
 strlcpy ( strresult , "Failed building kadmin/changepw principal" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 ret = krb5_rd_req ( context , & auth_context , & ap_req , changepw , keytab , NULL , & ticket ) ;
 if ( ret ) {
 numresult = KRB5_KPASSWD_AUTHERROR ;
 strlcpy ( strresult , "Failed reading application request" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 ret = krb5_mk_rep ( context , auth_context , & ap_rep ) ;
 if ( ret ) {
 numresult = KRB5_KPASSWD_AUTHERROR ;
 strlcpy ( strresult , "Failed replying to application request" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 cipher . length = ( req -> data + req -> length ) - ptr ;
 cipher . data = ptr ;
 ret = krb5_rd_priv ( context , auth_context , & cipher , & clear , & replay ) ;
 if ( ret ) {
 numresult = KRB5_KPASSWD_HARDERROR ;
 strlcpy ( strresult , "Failed decrypting request" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 client = ticket -> enc_part2 -> client ;
 if ( vno == RFC3244_VERSION ) {
 krb5_data * clear_data ;
 ret = decode_krb5_setpw_req ( & clear , & clear_data , & target ) ;
 if ( ret != 0 ) {
 numresult = KRB5_KPASSWD_MALFORMED ;
 strlcpy ( strresult , "Failed decoding ChangePasswdData" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 zapfree ( clear . data , clear . length ) ;
 clear = * clear_data ;
 free ( clear_data ) ;
 if ( target != NULL ) {
 ret = krb5_unparse_name ( context , target , & targetstr ) ;
 if ( ret != 0 ) {
 numresult = KRB5_KPASSWD_HARDERROR ;
 strlcpy ( strresult , "Failed unparsing target name for log" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 }
 }
 ret = krb5_unparse_name ( context , client , & clientstr ) ;
 if ( ret ) {
 numresult = KRB5_KPASSWD_HARDERROR ;
 strlcpy ( strresult , "Failed unparsing client name for log" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 if ( vno == 1 && ( ticket -> enc_part2 -> flags & TKT_FLG_INITIAL ) == 0 ) {
 numresult = KRB5_KPASSWD_INITIAL_FLAG_NEEDED ;
 strlcpy ( strresult , "Ticket must be derived from a password" , sizeof ( strresult ) ) ;
 goto chpwfail ;
 }
 ptr = k5memdup0 ( clear . data , clear . length , & ret ) ;
 ret = schpw_util_wrapper ( server_handle , client , target , ( ticket -> enc_part2 -> flags & TKT_FLG_INITIAL ) != 0 , ptr , NULL , strresult , sizeof ( strresult ) ) ;
 if ( ret ) errmsg = krb5_get_error_message ( context , ret ) ;
 zapfree ( clear . data , clear . length ) ;
 zapfree ( ptr , clear . length ) ;
 clear = empty_data ( ) ;
 clen = strlen ( clientstr ) ;
 trunc_name ( & clen , & cdots ) ;
 switch ( addr -> addrtype ) {
 case ADDRTYPE_INET : {
 struct sockaddr_in * sin = ss2sin ( & ss ) ;
 sin -> sin_family = AF_INET ;
 memcpy ( & sin -> sin_addr , addr -> contents , addr -> length ) ;
 sin -> sin_port = htons ( remote_faddr -> port ) ;
 salen = sizeof ( * sin ) ;
 break ;
 }
 case ADDRTYPE_INET6 : {
 struct sockaddr_in6 * sin6 = ss2sin6 ( & ss ) ;
 sin6 -> sin6_family = AF_INET6 ;
 memcpy ( & sin6 -> sin6_addr , addr -> contents , addr -> length ) ;
 sin6 -> sin6_port = htons ( remote_faddr -> port ) ;
 salen = sizeof ( * sin6 ) ;
 break ;
 }
 default : {
 struct sockaddr * sa = ss2sa ( & ss ) ;
 sa -> sa_family = AF_UNSPEC ;
 salen = sizeof ( * sa ) ;
 break ;
 }
 }
 if ( getnameinfo ( ss2sa ( & ss ) , salen , addrbuf , sizeof ( addrbuf ) , NULL , 0 , NI_NUMERICHOST | NI_NUMERICSERV ) != 0 ) strlcpy ( addrbuf , "<unprintable>" , sizeof ( addrbuf ) ) ;
 if ( vno == RFC3244_VERSION ) {
 size_t tlen ;
 char * tdots ;
 const char * targetp ;
 if ( target == NULL ) {
 tlen = clen ;
 tdots = cdots ;
 targetp = targetstr ;
 }
 else {
 tlen = strlen ( targetstr ) ;
 trunc_name ( & tlen , & tdots ) ;
 targetp = clientstr ;
 }
 krb5_klog_syslog ( LOG_NOTICE , _ ( "setpw request from %s by %.*s%s for " "%.*s%s: %s" ) , addrbuf , ( int ) clen , clientstr , cdots , ( int ) tlen , targetp , tdots , errmsg ? errmsg : "success" ) ;
 }
 else {
 krb5_klog_syslog ( LOG_NOTICE , _ ( "chpw request from %s for %.*s%s: %s" ) , addrbuf , ( int ) clen , clientstr , cdots , errmsg ? errmsg : "success" ) ;
 }
 switch ( ret ) {
 case KADM5_AUTH_CHANGEPW : numresult = KRB5_KPASSWD_ACCESSDENIED ;
 break ;
 case KADM5_PASS_Q_TOOSHORT : case KADM5_PASS_REUSE : case KADM5_PASS_Q_CLASS : case KADM5_PASS_Q_DICT : case KADM5_PASS_Q_GENERIC : case KADM5_PASS_TOOSOON : numresult = KRB5_KPASSWD_SOFTERROR ;
 break ;
 case 0 : numresult = KRB5_KPASSWD_SUCCESS ;
 strlcpy ( strresult , "" , sizeof ( strresult ) ) ;
 break ;
 default : numresult = KRB5_KPASSWD_HARDERROR ;
 break ;
 }
 chpwfail : clear . length = 2 + strlen ( strresult ) ;
 clear . data = ( char * ) malloc ( clear . length ) ;
 ptr = clear . data ;
 * ptr ++ = ( numresult >> 8 ) & 0xff ;
 * ptr ++ = numresult & 0xff ;
 memcpy ( ptr , strresult , strlen ( strresult ) ) ;
 cipher = empty_data ( ) ;
 if ( ap_rep . length ) {
 ret = krb5_auth_con_setaddrs ( context , auth_context , local_faddr -> address , NULL ) ;
 if ( ret ) {
 numresult = KRB5_KPASSWD_HARDERROR ;
 strlcpy ( strresult , "Failed storing client and server internet addresses" , sizeof ( strresult ) ) ;
 }
 else {
 ret = krb5_mk_priv ( context , auth_context , & clear , & cipher , & replay ) ;
 if ( ret ) {
 numresult = KRB5_KPASSWD_HARDERROR ;
 strlcpy ( strresult , "Failed encrypting reply" , sizeof ( strresult ) ) ;
 }
 }
 }
 if ( cipher . length == 0 ) {
 if ( ap_rep . length ) {
 free ( ap_rep . data ) ;
 ap_rep = empty_data ( ) ;
 }
 krberror . ctime = 0 ;
 krberror . cusec = 0 ;
 krberror . susec = 0 ;
 ret = krb5_timeofday ( context , & krberror . stime ) ;
 if ( ret ) goto bailout ;
 krberror . error = ret ;
 krberror . error -= ERROR_TABLE_BASE_krb5 ;
 if ( krberror . error < 0 || krberror . error > 128 ) krberror . error = KRB_ERR_GENERIC ;
 krberror . client = NULL ;
 ret = krb5_build_principal ( context , & krberror . server , strlen ( realm ) , realm , "kadmin" , "changepw" , NULL ) ;
 if ( ret ) goto bailout ;
 krberror . text . length = 0 ;
 krberror . e_data = clear ;
 ret = krb5_mk_error ( context , & krberror , & cipher ) ;
 krb5_free_principal ( context , krberror . server ) ;
 if ( ret ) goto bailout ;
 }
 ret = alloc_data ( rep , 6 + ap_rep . length + cipher . length ) ;
 if ( ret ) goto bailout ;
 ptr = rep -> data ;
 * ptr ++ = ( rep -> length >> 8 ) & 0xff ;
 * ptr ++ = rep -> length & 0xff ;
 * ptr ++ = 0 ;
 * ptr ++ = 1 ;
 * ptr ++ = ( ap_rep . length >> 8 ) & 0xff ;
 * ptr ++ = ap_rep . length & 0xff ;
 if ( ap_rep . length ) {
 memcpy ( ptr , ap_rep . data , ap_rep . length ) ;
 ptr += ap_rep . length ;
 }
 memcpy ( ptr , cipher . data , cipher . length ) ;
 bailout : krb5_auth_con_free ( context , auth_context ) ;
 krb5_free_principal ( context , changepw ) ;
 krb5_free_ticket ( context , ticket ) ;
 free ( ap_rep . data ) ;
 free ( clear . data ) ;
 free ( cipher . data ) ;
 krb5_free_principal ( context , target ) ;
 krb5_free_unparsed_name ( context , targetstr ) ;
 krb5_free_unparsed_name ( context , clientstr ) ;
 krb5_free_error_message ( context , errmsg ) ;
 return ret ;
 }


static void handle_raw_data ( char * packet , int len , struct query * q , int dns_fd , int tun_fd , int userid ) {
 if ( check_user_and_ip ( userid , q ) != 0 ) {
 return ;
 }
 users [ userid ] . last_pkt = time ( NULL ) ;
 memcpy ( & ( users [ userid ] . q ) , q , sizeof ( struct query ) ) ;
 users [ userid ] . inpacket . offset = 0 ;
 memcpy ( users [ userid ] . inpacket . data , packet , len ) ;
 users [ userid ] . inpacket . len = len ;
 if ( debug >= 1 ) {
 fprintf ( stderr , "IN pkt raw, total %d, from user %d\n" , users [ userid ] . inpacket . len , userid ) ;
 }
 handle_full_packet ( tun_fd , dns_fd , userid ) ;
 }


static int rtp_packetize_h263 ( sout_stream_id_sys_t * id , block_t * in ) {
 uint8_t * p_data = in -> p_buffer ;
 int i_data = in -> i_buffer ;
 int i ;
 int i_max = rtp_mtu ( id ) - RTP_H263_HEADER_SIZE ;
 int i_count ;
 int b_p_bit ;
 int b_v_bit = 0 ;
 int i_plen = 0 ;
 int i_pebit = 0 ;
 uint16_t h ;
 if ( i_data < 2 ) {
 block_Release ( in ) ;
 return VLC_EGENERIC ;
 }
 if ( p_data [ 0 ] || p_data [ 1 ] ) {
 block_Release ( in ) ;
 return VLC_EGENERIC ;
 }
 p_data += 2 ;
 i_data -= 2 ;
 i_count = ( i_data + i_max - 1 ) / i_max ;
 for ( i = 0 ;
 i < i_count ;
 i ++ ) {
 int i_payload = __MIN ( i_max , i_data ) ;
 block_t * out = block_Alloc ( RTP_H263_PAYLOAD_START + i_payload ) ;
 b_p_bit = ( i == 0 ) ? 1 : 0 ;
 h = ( b_p_bit << 10 ) | ( b_v_bit << 9 ) | ( i_plen << 3 ) | i_pebit ;
 rtp_packetize_common ( id , out , ( i == i_count - 1 ) ? 1 : 0 , in -> i_pts > VLC_TS_INVALID ? in -> i_pts : in -> i_dts ) ;
 SetWBE ( out -> p_buffer + 12 , h ) ;
 memcpy ( & out -> p_buffer [ RTP_H263_PAYLOAD_START ] , p_data , i_payload ) ;
 out -> i_dts = in -> i_dts + i * in -> i_length / i_count ;
 out -> i_length = in -> i_length / i_count ;
 rtp_packetize_send ( id , out ) ;
 p_data += i_payload ;
 i_data -= i_payload ;
 }
 block_Release ( in ) ;
 return VLC_SUCCESS ;
 }


int jas_stream_fillbuf(jas_stream_t *stream, int getflag)
{
	int c;

	/* The stream must not be in an error or EOF state. */
	if ((stream->flags_ & (JAS_STREAM_ERRMASK)) != 0) {
		return EOF;
	}

	/* The stream must be open for reading. */
	if ((stream->openmode_ & JAS_STREAM_READ) == 0) {
		return EOF;
	}

	/* Make a half-hearted attempt to confirm that the buffer is not
	currently being used for writing.  This check is not intended
	to be foolproof! */
	assert((stream->bufmode_ & JAS_STREAM_WRBUF) == 0);

	assert(stream->ptr_ - stream->bufstart_ <= stream->bufsize_);

	/* Mark the buffer as being used for reading. */
	stream->bufmode_ |= JAS_STREAM_RDBUF;

	/* Read new data into the buffer. */
	stream->ptr_ = stream->bufstart_;
	if ((stream->cnt_ = (*stream->ops_->read_)(stream->obj_,
	  (char *) stream->bufstart_, stream->bufsize_)) <= 0) {
		if (stream->cnt_ < 0) {
			stream->flags_ |= JAS_STREAM_ERR;
		} else {
			stream->flags_ |= JAS_STREAM_EOF;
		}
		stream->cnt_ = 0;
		return EOF;
	}

	assert(stream->cnt_ > 0);
	/* Get or peek at the first character in the buffer. */
	c = (getflag) ? jas_stream_getc2(stream) : (*stream->ptr_);

	return c;
}


int mif_encode(jas_image_t *image, jas_stream_t *out, char *optstr)
{
	mif_hdr_t *hdr;
	jas_image_t *tmpimage;
	int fmt;
	int cmptno;
	mif_cmpt_t *cmpt;
	jas_image_cmptparm_t cmptparm;
	jas_seq2d_t *data;
	int_fast32_t x;
	int_fast32_t y;
	int bias;

	hdr = 0;
	tmpimage = 0;
	data = 0;

	if (optstr && *optstr != '\0') {
		jas_eprintf("warning: ignoring unsupported options\n");
	}

	if ((fmt = jas_image_strtofmt("pnm")) < 0) {
		jas_eprintf("error: PNM support required\n");
		goto error;
	}

	if (!(hdr = mif_makehdrfromimage(image))) {
		goto error;
	}
	if (mif_hdr_put(hdr, out)) {
		goto error;
	}

	/* Output component data. */
	for (cmptno = 0; cmptno < hdr->numcmpts; ++cmptno) {
		cmpt = hdr->cmpts[cmptno];
		if (!cmpt->data) {
			if (!(tmpimage = jas_image_create0())) {
				goto error;
			}
			cmptparm.tlx = 0;
			cmptparm.tly = 0;
			cmptparm.hstep = cmpt->sampperx;
			cmptparm.vstep = cmpt->samppery;
			cmptparm.width = cmpt->width;
			cmptparm.height = cmpt->height;
			cmptparm.prec = cmpt->prec;
			cmptparm.sgnd = false;
			if (jas_image_addcmpt(tmpimage, jas_image_numcmpts(tmpimage), &cmptparm)) {
				goto error;
			}
			if (!(data = jas_seq2d_create(0, 0, cmpt->width, cmpt->height))) {
				goto error;
			}
			if (jas_image_readcmpt(image, cmptno, 0, 0, cmpt->width, cmpt->height,
			  data)) {
				goto error;
			}
			if (cmpt->sgnd) {
				bias = 1 << (cmpt->prec - 1);
				for (y = 0; y < cmpt->height; ++y) {
					for (x = 0; x < cmpt->width; ++x) {
						*jas_seq2d_getref(data, x, y) += bias;
					}
				}
			}
			if (jas_image_writecmpt(tmpimage, 0, 0, 0, cmpt->width, cmpt->height,
			  data)) {
				goto error;
			}
			jas_seq2d_destroy(data);
			data = 0;
			if (jas_image_encode(tmpimage, out, fmt, 0)) {
				goto error;
			}
			jas_image_destroy(tmpimage);
			tmpimage = 0;
		}
	}

	mif_hdr_destroy(hdr);

	return 0;

error:
	if (hdr) {
		mif_hdr_destroy(hdr);
	}
	if (tmpimage) {
		jas_image_destroy(tmpimage);
	}
	if (data) {
		jas_seq2d_destroy(data);
	}
	return -1;
}


void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart, int ystart,
  int xend, int yend)
{
	jas_matrix_bindsub(s, s1, ystart - s1->ystart_, xstart - s1->xstart_,
	  yend - s1->ystart_ - 1, xend - s1->xstart_ - 1);
}


static void log_invalid_scale_factor ( SvcContext * svc_ctx , const char * value ) {
 svc_log ( svc_ctx , SVC_LOG_ERROR , "svc scale-factors: invalid value %s\n" , value ) ;
 }


int gdev_mem_open_scan_lines ( gx_device_memory * mdev , int setup_height ) {
 bool line_pointers_adjacent = true ;
 ulong size ;
 if ( setup_height < 0 || setup_height > mdev -> height ) return_error ( gs_error_rangecheck ) ;
 if ( mdev -> bitmap_memory != 0 ) {
 int align ;
 if ( gdev_mem_bitmap_size ( mdev , & size ) < 0 ) return_error ( gs_error_VMerror ) ;
 if ( ( uint ) size != size ) return_error ( gs_error_limitcheck ) ;
 mdev -> base = gs_alloc_bytes ( mdev -> bitmap_memory , ( uint ) size , "mem_open" ) ;
 if ( mdev -> base == 0 ) return_error ( gs_error_VMerror ) ;
 # ifdef PACIFY_VALGRIND memset ( mdev -> base , 0x00 , size ) ;
 # endif align = 1 << mdev -> log2_align_mod ;
 mdev -> base += ( - ( int ) ( intptr_t ) mdev -> base ) & ( align - 1 ) ;
 mdev -> foreign_bits = false ;
 }
 else if ( mdev -> line_pointer_memory != 0 ) {
 mdev -> line_ptrs = ( byte * * ) gs_alloc_byte_array ( mdev -> line_pointer_memory , mdev -> height , sizeof ( byte * ) * ( mdev -> is_planar ? mdev -> color_info . num_components : 1 ) , "gdev_mem_open_scan_lines" ) ;
 if ( mdev -> line_ptrs == 0 ) return_error ( gs_error_VMerror ) ;
 mdev -> foreign_line_pointers = false ;
 line_pointers_adjacent = false ;
 }
 if ( line_pointers_adjacent ) {
 int code ;
 if ( mdev -> base == 0 ) return_error ( gs_error_rangecheck ) ;
 code = gdev_mem_bits_size ( mdev , mdev -> width , mdev -> height , & size ) ;
 if ( code < 0 ) return code ;
 mdev -> line_ptrs = ( byte * * ) ( mdev -> base + size ) ;
 }
 mdev -> raster = gx_device_raster ( ( gx_device * ) mdev , 1 ) ;
 return gdev_mem_set_line_ptrs ( mdev , NULL , 0 , NULL , setup_height ) ;
 }


int jpc_tagtree_decode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
  int threshold, jpc_bitstream_t *in)
{
	jpc_tagtreenode_t *stk[JPC_TAGTREE_MAXDEPTH - 1];
	jpc_tagtreenode_t **stkptr;
	jpc_tagtreenode_t *node;
	int low;
	int ret;

	/* Avoid compiler warnings about unused parameters. */
	tree = 0;

	assert(threshold >= 0);

	/* Traverse to the root of the tree, recording the path taken. */
	stkptr = stk;
	node = leaf;
	while (node->parent_) {
		*stkptr++ = node;
		node = node->parent_;
	}

	low = 0;
	for (;;) {
		if (low > node->low_) {
			node->low_ = low;
		} else {
			low = node->low_;
		}
		while (low < threshold && low < node->value_) {
			if ((ret = jpc_bitstream_getbit(in)) < 0) {
				return -1;
			}
			if (ret) {
				node->value_ = low;
			} else {
				++low;
			}
		}
		node->low_ = low;
		if (stkptr == stk) {
			break;
		}
		node = *--stkptr;
	}

	return (node->value_ < threshold) ? 1 : 0;
}


REGRESSION_TEST ( SDK_API_TSIOBufferReaderConsume ) ( RegressionTest * test , int , int * pstatus ) {
 bool test_passed = false ;
 * pstatus = REGRESSION_TEST_INPROGRESS ;
 TSIOBuffer bufp = TSIOBufferSizedCreate ( TS_IOBUFFER_SIZE_INDEX_4K ) ;
 TSIOBufferReader readerp = TSIOBufferReaderAlloc ( bufp ) ;
 TSIOBufferProduce ( bufp , 10 ) ;
 TSIOBufferReaderConsume ( readerp , 10 ) ;
 int64_t reader_avail = TSIOBufferReaderAvail ( readerp ) ;
 if ( reader_avail == 0 ) {
 SDK_RPRINT ( test , "TSIOBufferReaderConsume" , "TestCase1" , TC_PASS , "ok" ) ;
 test_passed = true ;
 }
 else {
 SDK_RPRINT ( test , "TSIOBufferReaderConsume" , "TestCase1" , TC_FAIL , "failed" ) ;
 }
 * pstatus = ( ( test_passed == true ) ? REGRESSION_TEST_PASSED : REGRESSION_TEST_FAILED ) ;
 return ;
 }


static int jas_icclut8_output(jas_iccattrval_t *attrval, jas_stream_t *out)
{
	jas_icclut8_t *lut8 = &attrval->data.lut8;
	int i;
	int j;
	int n;
	lut8->clut = 0;
	lut8->intabs = 0;
	lut8->intabsbuf = 0;
	lut8->outtabs = 0;
	lut8->outtabsbuf = 0;
	if (jas_stream_putc(out, lut8->numinchans) == EOF ||
	  jas_stream_putc(out, lut8->numoutchans) == EOF ||
	  jas_stream_putc(out, lut8->clutlen) == EOF ||
	  jas_stream_putc(out, 0) == EOF)
		goto error;
	for (i = 0; i < 3; ++i) {
		for (j = 0; j < 3; ++j) {
			if (jas_iccputsint32(out, lut8->e[i][j]))
				goto error;
		}
	}
	if (jas_iccputuint16(out, lut8->numintabents) ||
	  jas_iccputuint16(out, lut8->numouttabents))
		goto error;
	n = lut8->numinchans * lut8->numintabents;
	for (i = 0; i < n; ++i) {
		if (jas_iccputuint8(out, lut8->intabsbuf[i]))
			goto error;
	}
	n = lut8->numoutchans * lut8->numouttabents;
	for (i = 0; i < n; ++i) {
		if (jas_iccputuint8(out, lut8->outtabsbuf[i]))
			goto error;
	}
	n = jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans;
	for (i = 0; i < n; ++i) {
		if (jas_iccputuint8(out, lut8->clut[i]))
			goto error;
	}
	return 0;
error:
	return -1;
}


hb_face_t * hb_face_get_empty ( void ) {
 return const_cast < hb_face_t * > ( & _hb_face_nil ) ;
 }


static int estimate_best_b_count ( MpegEncContext * s ) {
 AVCodec * codec = avcodec_find_encoder ( s -> avctx -> codec_id ) ;
 AVCodecContext * c = avcodec_alloc_context3 ( NULL ) ;
 AVFrame input [ FF_MAX_B_FRAMES + 2 ] ;
 const int scale = s -> avctx -> brd_scale ;
 int i , j , out_size , p_lambda , b_lambda , lambda2 ;
 int64_t best_rd = INT64_MAX ;
 int best_b_count = - 1 ;
 assert ( scale >= 0 && scale <= 3 ) ;
 p_lambda = s -> last_lambda_for [ AV_PICTURE_TYPE_P ] ;
 b_lambda = s -> last_lambda_for [ AV_PICTURE_TYPE_B ] ;
 if ( ! b_lambda ) b_lambda = p_lambda ;
 lambda2 = ( b_lambda * b_lambda + ( 1 << FF_LAMBDA_SHIFT ) / 2 ) >> FF_LAMBDA_SHIFT ;
 c -> width = s -> width >> scale ;
 c -> height = s -> height >> scale ;
 c -> flags = CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED ;
 c -> flags |= s -> avctx -> flags & CODEC_FLAG_QPEL ;
 c -> mb_decision = s -> avctx -> mb_decision ;
 c -> me_cmp = s -> avctx -> me_cmp ;
 c -> mb_cmp = s -> avctx -> mb_cmp ;
 c -> me_sub_cmp = s -> avctx -> me_sub_cmp ;
 c -> pix_fmt = AV_PIX_FMT_YUV420P ;
 c -> time_base = s -> avctx -> time_base ;
 c -> max_b_frames = s -> max_b_frames ;
 if ( avcodec_open2 ( c , codec , NULL ) < 0 ) return - 1 ;
 for ( i = 0 ;
 i < s -> max_b_frames + 2 ;
 i ++ ) {
 int ysize = c -> width * c -> height ;
 int csize = ( c -> width / 2 ) * ( c -> height / 2 ) ;
 Picture pre_input , * pre_input_ptr = i ? s -> input_picture [ i - 1 ] : s -> next_picture_ptr ;
 avcodec_get_frame_defaults ( & input [ i ] ) ;
 input [ i ] . data [ 0 ] = av_malloc ( ysize + 2 * csize ) ;
 input [ i ] . data [ 1 ] = input [ i ] . data [ 0 ] + ysize ;
 input [ i ] . data [ 2 ] = input [ i ] . data [ 1 ] + csize ;
 input [ i ] . linesize [ 0 ] = c -> width ;
 input [ i ] . linesize [ 1 ] = input [ i ] . linesize [ 2 ] = c -> width / 2 ;
 if ( pre_input_ptr && ( ! i || s -> input_picture [ i - 1 ] ) ) {
 pre_input = * pre_input_ptr ;
 if ( pre_input . f . type != FF_BUFFER_TYPE_SHARED && i ) {
 pre_input . f . data [ 0 ] += INPLACE_OFFSET ;
 pre_input . f . data [ 1 ] += INPLACE_OFFSET ;
 pre_input . f . data [ 2 ] += INPLACE_OFFSET ;
 }
 s -> dsp . shrink [ scale ] ( input [ i ] . data [ 0 ] , input [ i ] . linesize [ 0 ] , pre_input . f . data [ 0 ] , pre_input . f . linesize [ 0 ] , c -> width , c -> height ) ;
 s -> dsp . shrink [ scale ] ( input [ i ] . data [ 1 ] , input [ i ] . linesize [ 1 ] , pre_input . f . data [ 1 ] , pre_input . f . linesize [ 1 ] , c -> width >> 1 , c -> height >> 1 ) ;
 s -> dsp . shrink [ scale ] ( input [ i ] . data [ 2 ] , input [ i ] . linesize [ 2 ] , pre_input . f . data [ 2 ] , pre_input . f . linesize [ 2 ] , c -> width >> 1 , c -> height >> 1 ) ;
 }
 }
 for ( j = 0 ;
 j < s -> max_b_frames + 1 ;
 j ++ ) {
 int64_t rd = 0 ;
 if ( ! s -> input_picture [ j ] ) break ;
 c -> error [ 0 ] = c -> error [ 1 ] = c -> error [ 2 ] = 0 ;
 input [ 0 ] . pict_type = AV_PICTURE_TYPE_I ;
 input [ 0 ] . quality = 1 * FF_QP2LAMBDA ;
 out_size = encode_frame ( c , & input [ 0 ] ) ;
 for ( i = 0 ;
 i < s -> max_b_frames + 1 ;
 i ++ ) {
 int is_p = i % ( j + 1 ) == j || i == s -> max_b_frames ;
 input [ i + 1 ] . pict_type = is_p ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B ;
 input [ i + 1 ] . quality = is_p ? p_lambda : b_lambda ;
 out_size = encode_frame ( c , & input [ i + 1 ] ) ;
 rd += ( out_size * lambda2 ) >> ( FF_LAMBDA_SHIFT - 3 ) ;
 }
 while ( out_size ) {
 out_size = encode_frame ( c , NULL ) ;
 rd += ( out_size * lambda2 ) >> ( FF_LAMBDA_SHIFT - 3 ) ;
 }
 rd += c -> error [ 0 ] + c -> error [ 1 ] + c -> error [ 2 ] ;
 if ( rd < best_rd ) {
 best_rd = rd ;
 best_b_count = j ;
 }
 }
 avcodec_close ( c ) ;
 av_freep ( & c ) ;
 for ( i = 0 ;
 i < s -> max_b_frames + 2 ;
 i ++ ) {
 av_freep ( & input [ i ] . data [ 0 ] ) ;
 }
 return best_b_count ;
 }


jas_image_t *jas_image_copy(jas_image_t *image)
{
	jas_image_t *newimage;
	int cmptno;

	newimage = jas_image_create0();
	if (jas_image_growcmpts(newimage, image->numcmpts_)) {
		goto error;
	}
	for (cmptno = 0; cmptno < image->numcmpts_; ++cmptno) {
		if (!(newimage->cmpts_[cmptno] = jas_image_cmpt_copy(image->cmpts_[cmptno]))) {
			goto error;
		}
		++newimage->numcmpts_;
	}

	jas_image_setbbox(newimage);

	if (image->cmprof_) {
		if (!(newimage->cmprof_ = jas_cmprof_copy(image->cmprof_)))
			goto error;
	}

	return newimage;
error:
	if (newimage) {
		jas_image_destroy(newimage);
	}
	return 0;
}


static int test_if_case_insensitive ( const char * dir_name ) {
 int result = 0 ;
 File file ;
 char buff [ FN_REFLEN ] , buff2 [ FN_REFLEN ] ;
 MY_STAT stat_info ;
 DBUG_ENTER ( "test_if_case_insensitive" ) ;
 fn_format ( buff , glob_hostname , dir_name , ".lower-test" , MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR ) ;
 fn_format ( buff2 , glob_hostname , dir_name , ".LOWER-TEST" , MY_UNPACK_FILENAME | MY_REPLACE_EXT | MY_REPLACE_DIR ) ;
 mysql_file_delete ( key_file_casetest , buff2 , MYF ( 0 ) ) ;
 if ( ( file = mysql_file_create ( key_file_casetest , buff , 0666 , O_RDWR , MYF ( 0 ) ) ) < 0 ) {
 if ( ! opt_abort ) sql_print_warning ( "Can't create test file %s" , buff ) ;
 DBUG_RETURN ( - 1 ) ;
 }
 mysql_file_close ( file , MYF ( 0 ) ) ;
 if ( mysql_file_stat ( key_file_casetest , buff2 , & stat_info , MYF ( 0 ) ) ) result = 1 ;
 mysql_file_delete ( key_file_casetest , buff , MYF ( MY_WME ) ) ;
 DBUG_PRINT ( "exit" , ( "result: %d" , result ) ) ;
 DBUG_RETURN ( result ) ;
 }


static char * keep_pack ( const char * curr_index_name ) {
 static char name [ PATH_MAX ] ;
 static const char * keep_msg = "fast-import" ;
 int keep_fd ;
 keep_fd = odb_pack_keep ( name , sizeof ( name ) , pack_data -> sha1 ) ;
 if ( keep_fd < 0 ) die_errno ( "cannot create keep file" ) ;
 write_or_die ( keep_fd , keep_msg , strlen ( keep_msg ) ) ;
 if ( close ( keep_fd ) ) die_errno ( "failed to write keep file" ) ;
 snprintf ( name , sizeof ( name ) , "%s/pack/pack-%s.pack" , get_object_directory ( ) , sha1_to_hex ( pack_data -> sha1 ) ) ;
 if ( finalize_object_file ( pack_data -> pack_name , name ) ) die ( "cannot store pack file" ) ;
 snprintf ( name , sizeof ( name ) , "%s/pack/pack-%s.idx" , get_object_directory ( ) , sha1_to_hex ( pack_data -> sha1 ) ) ;
 if ( finalize_object_file ( curr_index_name , name ) ) die ( "cannot store index file" ) ;
 free ( ( void * ) curr_index_name ) ;
 return name ;
 }


static int ebml_level_end ( MatroskaDemuxContext * matroska ) {
 AVIOContext * pb = matroska -> ctx -> pb ;
 int64_t pos = avio_tell ( pb ) ;
 if ( matroska -> num_levels > 0 ) {
 MatroskaLevel * level = & matroska -> levels [ matroska -> num_levels - 1 ] ;
 if ( pos - level -> start >= level -> length || matroska -> current_id ) {
 matroska -> num_levels -- ;
 return 1 ;
 }
 }
 return 0 ;
 }


void jas_matrix_destroy(jas_matrix_t *matrix)
{
	if (matrix->data_) {
		assert(!(matrix->flags_ & JAS_MATRIX_REF));
		jas_free(matrix->data_);
		matrix->data_ = 0;
	}
	if (matrix->rows_) {
		jas_free(matrix->rows_);
		matrix->rows_ = 0;
	}
	jas_free(matrix);
}


void *jas_malloc(size_t size)
{
	return malloc(size);
}


void jpc_ft_fwdlift_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
  int parity)
{

	jpc_fix_t *lptr;
	jpc_fix_t *hptr;
	register jpc_fix_t *lptr2;
	register jpc_fix_t *hptr2;
	register int n;
	register int i;
	int llen;

	llen = (numrows + 1 - parity) >> 1;

	if (numrows > 1) {

		/* Apply the first lifting step. */
		lptr = &a[0];
		hptr = &a[llen * stride];
		if (parity) {
			lptr2 = lptr;
			hptr2 = hptr;
			for (i = 0; i < numcols; ++i) {
				hptr2[0] -= lptr2[0];
				++hptr2;
				++lptr2;
			}
			hptr += stride;
		}
		n = numrows - llen - parity - (parity == (numrows & 1));
		while (n-- > 0) {
			lptr2 = lptr;
			hptr2 = hptr;
			for (i = 0; i < numcols; ++i) {
				hptr2[0] -= (lptr2[0] + lptr2[stride]) >> 1;
				++lptr2;
				++hptr2;
			}
			hptr += stride;
			lptr += stride;
		}
		if (parity == (numrows & 1)) {
			lptr2 = lptr;
			hptr2 = hptr;
			for (i = 0; i < numcols; ++i) {
				hptr2[0] -= lptr2[0];
				++lptr2;
				++hptr2;
			}
		}

		/* Apply the second lifting step. */
		lptr = &a[0];
		hptr = &a[llen * stride];
		if (!parity) {
			lptr2 = lptr;
			hptr2 = hptr;
			for (i = 0; i < numcols; ++i) {
				lptr2[0] += (hptr2[0] + 1) >> 1;
				++lptr2;
				++hptr2;
			}
			lptr += stride;
		}
		n = llen - (!parity) - (parity != (numrows & 1));
		while (n-- > 0) {
			lptr2 = lptr;
			hptr2 = hptr;
			for (i = 0; i < numcols; ++i) {
				lptr2[0] += (hptr2[0] + hptr2[stride] + 2) >> 2;
				++lptr2;
				++hptr2;
			}
			lptr += stride;
			hptr += stride;
		}
		if (parity != (numrows & 1)) {
			lptr2 = lptr;
			hptr2 = hptr;
			for (i = 0; i < numcols; ++i) {
				lptr2[0] += (hptr2[0] + 1) >> 1;
				++lptr2;
				++hptr2;
			}
		}

	} else {

		if (parity) {
			lptr2 = &a[0];
			for (i = 0; i < numcols; ++i) {
				lptr2[0] <<= 1;
				++lptr2;
			}
		}

	}

}


int parse_CNatLanguageRestriction ( tvbuff_t * tvb , int offset , proto_tree * parent_tree , proto_tree * pad_tree , struct CNatLanguageRestriction * v , const char * fmt , ... ) {
 proto_tree * tree ;
 proto_item * item ;
 va_list ap ;
 guint32 cc ;
 const char * txt ;
 va_start ( ap , fmt ) ;
 txt = wmem_strdup_vprintf ( wmem_packet_scope ( ) , fmt , ap ) ;
 va_end ( ap ) ;
 tree = proto_tree_add_subtree ( parent_tree , tvb , offset , 0 , ett_CNatLanguageRestriction , & item , txt ) ;
 offset = parse_CFullPropSpec ( tvb , offset , tree , pad_tree , & v -> property , "Property" ) ;
 offset = parse_padding ( tvb , offset , 4 , pad_tree , "padding_cc" ) ;
 cc = tvb_get_letohl ( tvb , offset ) ;
 proto_tree_add_uint ( tree , hf_mswsp_natlangrestrict_cc , tvb , offset , 4 , cc ) ;
 offset += 4 ;
 proto_tree_add_item_ret_string ( tree , hf_mswsp_natlangrestrict_phrase , tvb , offset , 2 * cc , ENC_LITTLE_ENDIAN | ENC_UCS_2 , wmem_packet_scope ( ) , & v -> phrase ) ;
 offset += 2 * cc ;
 offset = parse_padding ( tvb , offset , 4 , pad_tree , "padding_lcid" ) ;
 v -> lcid = tvb_get_letohl ( tvb , offset ) ;
 offset = parse_lcid ( tvb , offset , tree , "lcid" ) ;
 proto_item_set_end ( item , tvb , offset ) ;
 return offset ;
 }


int jpc_mqdec_getbit_func(register jpc_mqdec_t *mqdec)
{
	int bit;
	JAS_DBGLOG(100, ("jpc_mqdec_getbit_func(%p)\n", mqdec));
	MQDEC_CALL(100, jpc_mqdec_dump(mqdec, stderr));
	bit = jpc_mqdec_getbit_macro(mqdec);
	MQDEC_CALL(100, jpc_mqdec_dump(mqdec, stderr));
	JAS_DBGLOG(100, ("ctx = %d, decoded %d\n", mqdec->curctx -
	  mqdec->ctxs, bit));
	return bit;
}


static void sethead ( struct head * head , SplineFont * sf , struct alltabs * at , enum fontformat format , int32 * bsizes ) {
 int i , lr , rl , indic_rearrange , arabic ;
 ASM * sm ;
 struct ttflangname * useng ;
 float vn ;
 if ( at -> gi . xmin == 15000 ) at -> gi . xmin = 0 ;
 if ( at -> gi . ymin == 15000 ) at -> gi . ymin = 0 ;
 if ( bsizes != NULL && format == ff_none ) {
 if ( sf -> ascent > at -> gi . ymax ) at -> gi . ymax = sf -> ascent ;
 if ( - sf -> descent < at -> gi . ymin ) at -> gi . ymin = - sf -> descent ;
 }
 head -> xmin = at -> gi . xmin ;
 head -> ymin = at -> gi . ymin ;
 head -> xmax = at -> gi . xmax ;
 head -> ymax = at -> gi . ymax ;
 lr = rl = arabic = 0 ;
 for ( i = 0 ;
 i < at -> gi . gcnt ;
 ++ i ) if ( at -> gi . bygid [ i ] != - 1 ) {
 SplineChar * sc = sf -> glyphs [ at -> gi . bygid [ i ] ] ;
 int uni = sc -> unicodeenc ;
 if ( SCRightToLeft ( sc ) ) rl = 1 ;
 else if ( ( uni != - 1 && uni < 0x10000 && islefttoright ( uni ) ) || ( uni >= 0x10300 && uni < 0x107ff ) ) lr = 1 ;
 if ( SCScriptFromUnicode ( sc ) == CHR ( 'a' , 'r' , 'a' , 'b' ) ) arabic = 1 ;
 }
 head -> version = 0x00010000 ;
 head -> revision = sf -> sfntRevision ;
 if ( sf -> sfntRevision == sfntRevisionUnset ) {
 head -> revision = 0x00010000 ;
 for ( useng = sf -> names ;
 useng != NULL ;
 useng = useng -> next ) if ( useng -> lang == 0x409 ) break ;
 if ( useng != NULL && useng -> names [ ttf_version ] != NULL && sscanf ( useng -> names [ ttf_version ] , "Version %f" , & vn ) == 1 ) {
 head -> revision = vn * 65536 ;
 }
 else if ( sf -> subfontcnt != 0 ) {
 int val , mant ;
 val = floor ( sf -> cidversion ) ;
 mant = floor ( 65536. * ( ( double ) sf -> cidversion - val ) ) ;
 head -> revision = ( val << 16 ) | mant ;
 }
 else if ( sf -> version != NULL ) {
 char * pt = sf -> version ;
 double dval ;
 int val , mant ;
 while ( * pt && ! isdigit ( * pt ) && * pt != '.' ) ++ pt ;
 if ( * pt ) {
 dval = strtod ( pt , NULL ) ;
 val = floor ( dval ) ;
 mant = floor ( 65536. * ( dval - val ) ) ;
 head -> revision = ( val << 16 ) | mant ;
 }
 }
 }
 head -> checksumAdj = 0 ;
 head -> magicNum = 0x5f0f3cf5 ;
 head -> flags = 8 | 2 | 1 ;
 if ( format >= ff_ttf && format <= ff_ttfdfont ) {
 if ( AnyInstructions ( sf ) ) head -> flags = 0x10 | 8 | 4 | 2 | 1 ;
 else if ( AnyMisleadingBitmapAdvances ( sf , bsizes ) ) head -> flags = 0x10 | 8 | 2 | 1 ;
 }
 if ( sf -> hasvmetrics ) head -> flags |= ( 1 << 5 ) ;
 if ( arabic ) head -> flags |= ( 1 << 7 ) ;
 if ( sf -> sm ) head -> flags |= ( 1 << 8 ) ;
 if ( rl ) head -> flags |= ( 1 << 9 ) ;
 indic_rearrange = 0 ;
 for ( sm = sf -> sm ;
 sm != NULL ;
 sm = sm -> next ) if ( sm -> type == asm_indic ) indic_rearrange = true ;
 if ( indic_rearrange ) head -> flags |= ( 1 << 10 ) ;
 if ( sf -> head_optimized_for_cleartype ) head -> flags |= ( 1 << 13 ) ;
 head -> emunits = sf -> ascent + sf -> descent ;
 head -> macstyle = MacStyleCode ( sf , NULL ) ;
 head -> lowestreadable = 8 ;
 head -> locais32 = 1 ;
 if ( at -> gi . glyph_len < 0x20000 ) head -> locais32 = 0 ;
 if ( lr && rl ) head -> dirhint = 0 ;
 else if ( rl ) head -> dirhint = - 2 ;
 else head -> dirhint = 2 ;
 if ( rl ) head -> flags |= ( 1 << 9 ) ;
 cvt_unix_to_1904 ( sf -> creationtime , head -> createtime ) ;
 cvt_unix_to_1904 ( sf -> modificationtime , head -> modtime ) ;
 }


static int calculate_directory_descriptors ( struct iso9660 * iso9660 , struct vdd * vdd , struct isoent * isoent , int depth ) {
 struct isoent * * enttbl ;
 int bs , block , i ;
 block = 1 ;
 bs = get_dir_rec_size ( iso9660 , isoent , DIR_REC_SELF , vdd -> vdd_type ) ;
 bs += get_dir_rec_size ( iso9660 , isoent , DIR_REC_PARENT , vdd -> vdd_type ) ;
 if ( isoent -> children . cnt <= 0 || ( vdd -> vdd_type != VDD_JOLIET && ! iso9660 -> opt . rr && depth + 1 >= vdd -> max_depth ) ) return ( block ) ;
 enttbl = isoent -> children_sorted ;
 for ( i = 0 ;
 i < isoent -> children . cnt ;
 i ++ ) {
 struct isoent * np = enttbl [ i ] ;
 struct isofile * file ;
 file = np -> file ;
 if ( file -> hardlink_target != NULL ) file = file -> hardlink_target ;
 file -> cur_content = & ( file -> content ) ;
 do {
 int dr_l ;
 dr_l = get_dir_rec_size ( iso9660 , np , DIR_REC_NORMAL , vdd -> vdd_type ) ;
 if ( ( bs + dr_l ) > LOGICAL_BLOCK_SIZE ) {
 block ++ ;
 bs = dr_l ;
 }
 else bs += dr_l ;
 file -> cur_content = file -> cur_content -> next ;
 }
 while ( file -> cur_content != NULL ) ;
 }
 return ( block ) ;
 }


void jas_matrix_clip(jas_matrix_t *matrix, jas_seqent_t minval, jas_seqent_t maxval)
{
	int i;
	int j;
	jas_seqent_t v;
	jas_seqent_t *rowstart;
	jas_seqent_t *data;
	int rowstep;

	if (jas_matrix_numrows(matrix) > 0 && jas_matrix_numcols(matrix) > 0) {
		assert(matrix->rows_);
		rowstep = jas_matrix_rowstep(matrix);
		for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
		  rowstart += rowstep) {
			data = rowstart;
			for (j = matrix->numcols_, data = rowstart; j > 0; --j,
			  ++data) {
				v = *data;
				if (v < minval) {
					*data = minval;
				} else if (v > maxval) {
					*data = maxval;
				}
			}
		}
	}
}


static int jpc_dec_process_qcc(jpc_dec_t *dec, jpc_ms_t *ms)
{
	jpc_qcc_t *qcc = &ms->parms.qcc;
	jpc_dec_tile_t *tile;

	if (JAS_CAST(int, qcc->compno) >= dec->numcomps) {
		jas_eprintf("invalid component number in QCC marker segment\n");
		return -1;
	}
	switch (dec->state) {
	case JPC_MH:
		jpc_dec_cp_setfromqcc(dec->cp, qcc);
		break;
	case JPC_TPH:
		if (!(tile = dec->curtile)) {
			return -1;
		}
		if (tile->partno > 0) {
			return -1;
		}
		jpc_dec_cp_setfromqcc(tile->cp, qcc);
		break;
	}
	return 0;
}


static int selinux_mount ( const char * dev_name , const struct path * path , const char * type , unsigned long flags , void * data ) {
 const struct cred * cred = current_cred ( ) ;
 if ( flags & MS_REMOUNT ) return superblock_has_perm ( cred , path -> dentry -> d_sb , FILESYSTEM__REMOUNT , NULL ) ;
 else return path_has_perm ( cred , path , FILE__MOUNTON ) ;
 }


static int mono(jas_iccprof_t *iccprof, int op, jas_cmpxformseq_t **retpxformseq)
{
	jas_iccattrval_t *graytrc;
	jas_cmshapmat_t *shapmat;
	jas_cmpxform_t *pxform;
	jas_cmpxformseq_t *pxformseq;
	jas_cmshapmatlut_t lut;

	jas_cmshapmatlut_init(&lut);
	if (!(graytrc = jas_iccprof_getattr(iccprof, JAS_ICC_TAG_GRYTRC)) ||
	  graytrc->type != JAS_ICC_TYPE_CURV)
		goto error;
	if (!(pxform = jas_cmpxform_createshapmat()))
		goto error;
	shapmat = &pxform->data.shapmat;
	if (!(pxformseq = jas_cmpxformseq_create()))
		goto error;
	if (jas_cmpxformseq_insertpxform(pxformseq, -1, pxform))
		goto error;

	pxform->numinchans = 1;
	pxform->numoutchans = 3;

	shapmat->mono = 1;
	shapmat->useluts = 1;
	shapmat->usemat = 1;
	if (!op) {
		shapmat->order = 0;
		shapmat->mat[0][0] = 0.9642;
		shapmat->mat[1][0] = 1.0;
		shapmat->mat[2][0] = 0.8249;
		if (jas_cmshapmatlut_set(&shapmat->luts[0], &graytrc->data.curv))
			goto error;
	} else {
		shapmat->order = 1;
		shapmat->mat[0][0] = 1.0 / 0.9642;
		shapmat->mat[1][0] = 1.0;
		shapmat->mat[2][0] = 1.0 / 0.8249;
		jas_cmshapmatlut_init(&lut);
		if (jas_cmshapmatlut_set(&lut, &graytrc->data.curv))
			goto error;
		if (jas_cmshapmatlut_invert(&shapmat->luts[0], &lut, lut.size))
			goto error;
		jas_cmshapmatlut_cleanup(&lut);
	}
	jas_iccattrval_destroy(graytrc);
	jas_cmpxform_destroy(pxform);
	*retpxformseq = pxformseq;
	return 0;
error:
	return -1;
}


static int jpc_dec_cp_prepare(jpc_dec_cp_t *cp)
{
	jpc_dec_ccp_t *ccp;
	int compno;
	int i;
	for (compno = 0, ccp = cp->ccps; compno < cp->numcomps;
	  ++compno, ++ccp) {
		if (!(ccp->csty & JPC_COX_PRT)) {
			for (i = 0; i < JPC_MAXRLVLS; ++i) {
				ccp->prcwidthexpns[i] = 15;
				ccp->prcheightexpns[i] = 15;
			}
		}
		if (ccp->qsty == JPC_QCX_SIQNT) {
			calcstepsizes(ccp->stepsizes[0], ccp->numrlvls, ccp->stepsizes);
		}
	}
	return 0;
}


static int jp2_getcs(jp2_colr_t *colr)
{
	if (colr->method == JP2_COLR_ENUM) {
		switch (colr->csid) {
		case JP2_COLR_SRGB:
			return JAS_CLRSPC_SRGB;
			break;
		case JP2_COLR_SYCC:
			return JAS_CLRSPC_SYCBCR;
			break;
		case JP2_COLR_SGRAY:
			return JAS_CLRSPC_SGRAY;
			break;
		}
	}
	return JAS_CLRSPC_UNKNOWN;
}


void do_wait_for_slave_to_stop ( struct st_command * c __attribute__ ( ( unused ) ) ) {
 static int SLAVE_POLL_INTERVAL = 300000 ;
 MYSQL * mysql = cur_con -> mysql ;
 for ( ;
 ;
 ) {
 MYSQL_RES * UNINIT_VAR ( res ) ;
 MYSQL_ROW row ;
 int done ;
 if ( mysql_query ( mysql , "show status like 'Slave_running'" ) || ! ( res = mysql_store_result ( mysql ) ) ) die ( "Query failed while probing slave for stop: %s" , mysql_error ( mysql ) ) ;
 if ( ! ( row = mysql_fetch_row ( res ) ) || ! row [ 1 ] ) {
 mysql_free_result ( res ) ;
 die ( "Strange result from query while probing slave for stop" ) ;
 }
 done = ! strcmp ( row [ 1 ] , "OFF" ) ;
 mysql_free_result ( res ) ;
 if ( done ) break ;
 my_sleep ( SLAVE_POLL_INTERVAL ) ;
 }
 return ;
 }


static jas_image_cmpt_t *jas_image_cmpt_create0()
{
	jas_image_cmpt_t *cmpt;
	if (!(cmpt = jas_malloc(sizeof(jas_image_cmpt_t)))) {
		return 0;
	}
	memset(cmpt, 0, sizeof(jas_image_cmpt_t));
	cmpt->type_ = JAS_IMAGE_CT_UNKNOWN;
	return cmpt;
}


void jpc_tagtree_copy(jpc_tagtree_t *dsttree, jpc_tagtree_t *srctree)
{
	int n;
	jpc_tagtreenode_t *srcnode;
	jpc_tagtreenode_t *dstnode;

	/* The two tag trees must have similar sizes. */
	assert(srctree->numleafsh_ == dsttree->numleafsh_ &&
	  srctree->numleafsv_ == dsttree->numleafsv_);

	n = srctree->numnodes_;
	srcnode = srctree->nodes_;
	dstnode = dsttree->nodes_;
	while (--n >= 0) {
		dstnode->value_ = srcnode->value_;
		dstnode->low_ = srcnode->low_;
		dstnode->known_ = srcnode->known_;
		++dstnode;
		++srcnode;
	}
}


void *jas_alloc3(size_t num_arrays, size_t array_size, size_t element_size)
{
	size_t size;
	if (!jas_safe_size_mul(array_size, element_size, &size) ||
	  !jas_safe_size_mul(size, num_arrays, &size)) {
		return 0;
	}
	return jas_malloc(size);
}


int jpc_ppxstab_insert(jpc_ppxstab_t *tab, jpc_ppxstabent_t *ent)
{
	int inspt;
	int i;

	for (i = 0; i < tab->numents; ++i) {
		if (tab->ents[i]->ind > ent->ind) {
			break;
		}
	}
	inspt = i;

	if (tab->numents >= tab->maxents) {
		if (jpc_ppxstab_grow(tab, tab->maxents + 128)) {
			return -1;
		}
	}

	for (i = tab->numents; i > inspt; --i) {
		tab->ents[i] = tab->ents[i - 1];
	}
	tab->ents[i] = ent;
	++tab->numents;

	return 0;
}


static void jas_cmpxform_destroy(jas_cmpxform_t *pxform)
{
	if (--pxform->refcnt <= 0) {
		(*pxform->ops->destroy)(pxform);
		jas_free(pxform);
	}
}


int test_compare_files ( const char * tgt , const char * rec ) {
 FILE * orig , * recons ;
 static uint8_t obuf [ TESTBUFSIZE ] , rbuf [ TESTBUFSIZE ] ;
 xoff_t offset = 0 ;
 size_t i ;
 size_t oc , rc ;
 xoff_t diffs = 0 ;
 if ( ( orig = fopen ( tgt , "r" ) ) == NULL ) {
 XPR ( NT "open %s failed\n" , tgt ) ;
 return get_errno ( ) ;
 }
 if ( ( recons = fopen ( rec , "r" ) ) == NULL ) {
 XPR ( NT "open %s failed\n" , rec ) ;
 return get_errno ( ) ;
 }
 for ( ;
 ;
 ) {
 oc = fread ( obuf , 1 , TESTBUFSIZE , orig ) ;
 rc = fread ( rbuf , 1 , TESTBUFSIZE , recons ) ;
 if ( oc != rc ) {
 return XD3_INTERNAL ;
 }
 if ( oc == 0 ) {
 break ;
 }
 for ( i = 0 ;
 i < oc ;
 i += 1 ) {
 if ( obuf [ i ] != rbuf [ i ] ) {
 XPR ( NT "byte %u (read %u @ %" Q "u) %d != %d\n" , ( int ) i , ( int ) oc , offset , obuf [ i ] , rbuf [ i ] ) ;
 diffs ++ ;
 return XD3_INTERNAL ;
 }
 }
 offset += oc ;
 }
 fclose ( orig ) ;
 fclose ( recons ) ;
 if ( diffs != 0 ) {
 return XD3_INTERNAL ;
 }
 return 0 ;
 }


static int jas_icclut8_getsize(jas_iccattrval_t *attrval)
{
	jas_icclut8_t *lut8 = &attrval->data.lut8;
	return 44 + lut8->numinchans * lut8->numintabents +
	  lut8->numoutchans * lut8->numouttabents +
	  jas_iccpowi(lut8->clutlen, lut8->numinchans) * lut8->numoutchans;
}


hb_shape_plan_t * hb_shape_plan_reference ( hb_shape_plan_t * shape_plan ) {
 return hb_object_reference ( shape_plan ) ;
 }


int MDC2_Init ( MDC2_CTX * c ) {
 c -> num = 0 ;
 c -> pad_type = 1 ;
 memset ( & ( c -> h [ 0 ] ) , 0x52 , MDC2_BLOCK ) ;
 memset ( & ( c -> hh [ 0 ] ) , 0x25 , MDC2_BLOCK ) ;
 return 1 ;
 }


int jpc_ft_analyze(jpc_fix_t *a, int xstart, int ystart, int width, int height,
  int stride)
{
	int numrows = height;
	int numcols = width;
	int rowparity = ystart & 1;
	int colparity = xstart & 1;
	int i;
	jpc_fix_t *startptr;
	int maxcols;

	maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
	startptr = &a[0];
	for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
		jpc_qmfb_split_colgrp(startptr, numrows, stride, rowparity);
		jpc_ft_fwdlift_colgrp(startptr, numrows, stride, rowparity);
		startptr += JPC_QMFB_COLGRPSIZE;
	}
	if (maxcols < numcols) {
		jpc_qmfb_split_colres(startptr, numrows, numcols - maxcols, stride,
		  rowparity);
		jpc_ft_fwdlift_colres(startptr, numrows, numcols - maxcols, stride,
		  rowparity);
	}

	startptr = &a[0];
	for (i = 0; i < numrows; ++i) {
		jpc_qmfb_split_row(startptr, numcols, colparity);
		jpc_ft_fwdlift_row(startptr, numcols, colparity);
		startptr += stride;
	}

	return 0;

}


int jas_image_readcmptsample(jas_image_t *image, int cmptno, int x, int y)
{
	jas_image_cmpt_t *cmpt;
	uint_fast32_t v;
	int k;
	int c;

	cmpt = image->cmpts_[cmptno];

	if (jas_stream_seek(cmpt->stream_, (cmpt->width_ * y + x) * cmpt->cps_,
	  SEEK_SET) < 0) {
		return -1;
	}
	v = 0;
	for (k = cmpt->cps_; k > 0; --k) {
		if ((c = jas_stream_getc(cmpt->stream_)) == EOF) {
			return -1;
		}
		v = (v << 8) | (c & 0xff);
	}
	return bitstoint(v, cmpt->prec_, cmpt->sgnd_);
}


void * xcalloc ( size_t num , size_t size ) {
 void * ptr = malloc ( num * size ) ;
 if ( ptr ) {
 memset ( ptr , '\0' , ( num * size ) ) ;
 }
 return ptr ;
 }


static int jas_iccprof_readhdr(jas_stream_t *in, jas_icchdr_t *hdr)
{
	if (jas_iccgetuint32(in, &hdr->size) ||
	  jas_iccgetuint32(in, &hdr->cmmtype) ||
	  jas_iccgetuint32(in, &hdr->version) ||
	  jas_iccgetuint32(in, &hdr->clas) ||
	  jas_iccgetuint32(in, &hdr->colorspc) ||
	  jas_iccgetuint32(in, &hdr->refcolorspc) ||
	  jas_iccgettime(in, &hdr->ctime) ||
	  jas_iccgetuint32(in, &hdr->magic) ||
	  jas_iccgetuint32(in, &hdr->platform) ||
	  jas_iccgetuint32(in, &hdr->flags) ||
	  jas_iccgetuint32(in, &hdr->maker) ||
	  jas_iccgetuint32(in, &hdr->model) ||
	  jas_iccgetuint64(in, &hdr->attr) ||
	  jas_iccgetuint32(in, &hdr->intent) ||
	  jas_iccgetxyz(in, &hdr->illum) ||
	  jas_iccgetuint32(in, &hdr->creator) ||
	  jas_stream_gobble(in, 44) != 44)
		return -1;
	return 0;
}


static int decode_frame ( AVCodecContext * avctx , void * data , int * got_frame , AVPacket * avpkt ) {
 VBDecContext * const c = avctx -> priv_data ;
 AVFrame * frame = data ;
 uint8_t * outptr , * srcptr ;
 int i , j , ret ;
 int flags ;
 uint32_t size ;
 int offset = 0 ;
 bytestream2_init ( & c -> stream , avpkt -> data , avpkt -> size ) ;
 if ( ( ret = ff_get_buffer ( avctx , frame , 0 ) ) < 0 ) {
 av_log ( avctx , AV_LOG_ERROR , "get_buffer() failed\n" ) ;
 return ret ;
 }
 flags = bytestream2_get_le16 ( & c -> stream ) ;
 if ( flags & VB_HAS_GMC ) {
 i = ( int16_t ) bytestream2_get_le16 ( & c -> stream ) ;
 j = ( int16_t ) bytestream2_get_le16 ( & c -> stream ) ;
 offset = i + j * avctx -> width ;
 }
 if ( flags & VB_HAS_VIDEO ) {
 size = bytestream2_get_le32 ( & c -> stream ) ;
 vb_decode_framedata ( c , offset ) ;
 bytestream2_skip ( & c -> stream , size - 4 ) ;
 }
 if ( flags & VB_HAS_PALETTE ) {
 size = bytestream2_get_le32 ( & c -> stream ) ;
 vb_decode_palette ( c , size ) ;
 }
 memcpy ( frame -> data [ 1 ] , c -> pal , AVPALETTE_SIZE ) ;
 frame -> palette_has_changed = flags & VB_HAS_PALETTE ;
 outptr = frame -> data [ 0 ] ;
 srcptr = c -> frame ;
 for ( i = 0 ;
 i < avctx -> height ;
 i ++ ) {
 memcpy ( outptr , srcptr , avctx -> width ) ;
 srcptr += avctx -> width ;
 outptr += frame -> linesize [ 0 ] ;
 }
 FFSWAP ( uint8_t * , c -> frame , c -> prev_frame ) ;
 * got_frame = 1 ;
 return avpkt -> size ;
 }


static int jpc_dec_process_sot(jpc_dec_t *dec, jpc_ms_t *ms)
{
	jpc_dec_tile_t *tile;
	jpc_sot_t *sot = &ms->parms.sot;
	jas_image_cmptparm_t *compinfos;
	jas_image_cmptparm_t *compinfo;
	jpc_dec_cmpt_t *cmpt;
	int cmptno;

	if (dec->state == JPC_MH) {

		compinfos = jas_alloc2(dec->numcomps, sizeof(jas_image_cmptparm_t));
		assert(compinfos);
		for (cmptno = 0, cmpt = dec->cmpts, compinfo = compinfos;
		  cmptno < dec->numcomps; ++cmptno, ++cmpt, ++compinfo) {
			compinfo->tlx = 0;
			compinfo->tly = 0;
			compinfo->prec = cmpt->prec;
			compinfo->sgnd = cmpt->sgnd;
			compinfo->width = cmpt->width;
			compinfo->height = cmpt->height;
			compinfo->hstep = cmpt->hstep;
			compinfo->vstep = cmpt->vstep;
		}

		if (!(dec->image = jas_image_create(dec->numcomps, compinfos,
		  JAS_CLRSPC_UNKNOWN))) {
			return -1;
		}
		jas_free(compinfos);

		/* Is the packet header information stored in PPM marker segments in
		  the main header? */
		if (dec->ppmstab) {
			/* Convert the PPM marker segment data into a collection of streams
			  (one stream per tile-part). */
			if (!(dec->pkthdrstreams = jpc_ppmstabtostreams(dec->ppmstab))) {
				abort();
			}
			jpc_ppxstab_destroy(dec->ppmstab);
			dec->ppmstab = 0;
		}
	}

	if (sot->len > 0) {
		dec->curtileendoff = jas_stream_getrwcount(dec->in) - ms->len -
		  4 + sot->len;
	} else {
		dec->curtileendoff = 0;
	}

	if (JAS_CAST(int, sot->tileno) >= dec->numtiles) {
		jas_eprintf("invalid tile number in SOT marker segment\n");
		return -1;
	}
	/* Set the current tile. */
	dec->curtile = &dec->tiles[sot->tileno];
	tile = dec->curtile;
	/* Ensure that this is the expected part number. */
	if (sot->partno != tile->partno) {
		return -1;
	}
	if (tile->numparts > 0 && sot->partno >= tile->numparts) {
		return -1;
	}
	if (!tile->numparts && sot->numparts > 0) {
		tile->numparts = sot->numparts;
	}

	tile->pptstab = 0;

	switch (tile->state) {
	case JPC_TILE_INIT:
		/* This is the first tile-part for this tile. */
		tile->state = JPC_TILE_ACTIVE;
		assert(!tile->cp);
		if (!(tile->cp = jpc_dec_cp_copy(dec->cp))) {
			return -1;
		}
		jpc_dec_cp_resetflags(dec->cp);
		break;
	default:
		if (sot->numparts == sot->partno - 1) {
			tile->state = JPC_TILE_ACTIVELAST;
		}
		break;
	}

	/* Note: We do not increment the expected tile-part number until
	  all processing for this tile-part is complete. */

	/* We should expect to encounter other tile-part header marker
	  segments next. */
	dec->state = JPC_TPH;

	return 0;
}


static int jas_cmputint(long **bufptr, int sgnd, int prec, long val)
{
	int m;
	if (sgnd) {
		m = (1 << (prec - 1));
		if (val < -m || val >= m)
			return -1;
	} else {
		if (val < 0 || val >= (1 << prec))
			return -1;
	}
	**bufptr = val;
	++(*bufptr);
	return 0;
}


static void jas_icctxt_dump(jas_iccattrval_t *attrval, FILE *out)
{
	jas_icctxt_t *txt = &attrval->data.txt;
	fprintf(out, "string = \"%s\"\n", txt->string);
}


static char * ext_t_0_wv_cspc_13 ( tvbuff_t * tvb _U_ , guint32 value , guint32 str_tbl _U_ ) {
 char * str = wmem_strdup_printf ( wmem_packet_scope ( ) , "Common Value: '%s'" , val_to_str ( value , vals_wv_csp_13_element_value_tokens , "<Unknown WV-CSP 1.3 Common Value token 0x%X>" ) ) ;
 return str ;
 }


static inline void writer_print_section_footer ( WriterContext * wctx ) {
 int section_id = wctx -> section [ wctx -> level ] -> id ;
 int parent_section_id = wctx -> level ? wctx -> section [ wctx -> level - 1 ] -> id : SECTION_ID_NONE ;
 if ( parent_section_id != SECTION_ID_NONE ) wctx -> nb_item [ wctx -> level - 1 ] ++ ;
 if ( parent_section_id == SECTION_ID_PACKETS_AND_FRAMES ) {
 if ( section_id == SECTION_ID_PACKET ) wctx -> nb_section_packet ++ ;
 else wctx -> nb_section_frame ++ ;
 }
 if ( wctx -> writer -> print_section_footer ) wctx -> writer -> print_section_footer ( wctx ) ;
 wctx -> level -- ;
 }


jas_image_t *jpc_decode(jas_stream_t *in, char *optstr)
{
	jpc_dec_importopts_t opts;
	jpc_dec_t *dec;
	jas_image_t *image;

	dec = 0;

	if (jpc_dec_parseopts(optstr, &opts)) {
		goto error;
	}

	jpc_initluts();

	if (!(dec = jpc_dec_create(&opts, in))) {
		goto error;
	}

	/* Do most of the work. */
	if (jpc_dec_decode(dec)) {
		goto error;
	}

	if (jas_image_numcmpts(dec->image) >= 3) {
		jas_image_setclrspc(dec->image, JAS_CLRSPC_SRGB);
		jas_image_setcmpttype(dec->image, 0,
		  JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R));
		jas_image_setcmpttype(dec->image, 1,
		  JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G));
		jas_image_setcmpttype(dec->image, 2,
		  JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B));
	} else {
		jas_image_setclrspc(dec->image, JAS_CLRSPC_SGRAY);
		jas_image_setcmpttype(dec->image, 0,
		  JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y));
	}

	/* Save the return value. */
	image = dec->image;

	/* Stop the image from being discarded. */
	dec->image = 0;

	/* Destroy decoder. */
	jpc_dec_destroy(dec);

	return image;

error:
	if (dec) {
		jpc_dec_destroy(dec);
	}
	return 0;
}


static void ctl_flushpkt ( u_char more ) {
 size_t i ;
 int dlen ;
 int sendlen ;
 int maclen ;
 int totlen ;
 keyid_t keyid ;
 dlen = datapt - rpkt . u . data ;
 if ( ! more && datanotbinflag && dlen + 2 < CTL_MAX_DATA_LEN ) {
 * datapt ++ = '\r' ;
 * datapt ++ = '\n' ;
 dlen += 2 ;
 }
 sendlen = dlen + CTL_HEADER_LEN ;
 while ( sendlen & 0x3 ) {
 * datapt ++ = '\0' ;
 sendlen ++ ;
 }
 rpkt . r_m_e_op = CTL_RESPONSE | more | ( res_opcode & CTL_OP_MASK ) ;
 rpkt . count = htons ( ( u_short ) dlen ) ;
 rpkt . offset = htons ( ( u_short ) res_offset ) ;
 if ( res_async ) {
 for ( i = 0 ;
 i < COUNTOF ( ctl_traps ) ;
 i ++ ) {
 if ( TRAP_INUSE & ctl_traps [ i ] . tr_flags ) {
 rpkt . li_vn_mode = PKT_LI_VN_MODE ( sys_leap , ctl_traps [ i ] . tr_version , MODE_CONTROL ) ;
 rpkt . sequence = htons ( ctl_traps [ i ] . tr_sequence ) ;
 sendpkt ( & ctl_traps [ i ] . tr_addr , ctl_traps [ i ] . tr_localaddr , - 4 , ( struct pkt * ) & rpkt , sendlen ) ;
 if ( ! more ) ctl_traps [ i ] . tr_sequence ++ ;
 numasyncmsgs ++ ;
 }
 }
 }
 else {
 if ( res_authenticate && sys_authenticate ) {
 totlen = sendlen ;
 while ( totlen & 7 ) {
 * datapt ++ = '\0' ;
 totlen ++ ;
 }
 keyid = htonl ( res_keyid ) ;
 memcpy ( datapt , & keyid , sizeof ( keyid ) ) ;
 maclen = authencrypt ( res_keyid , ( u_int32 * ) & rpkt , totlen ) ;
 sendpkt ( rmt_addr , lcl_inter , - 5 , ( struct pkt * ) & rpkt , totlen + maclen ) ;
 }
 else {
 sendpkt ( rmt_addr , lcl_inter , - 6 , ( struct pkt * ) & rpkt , sendlen ) ;
 }
 if ( more ) numctlfrags ++ ;
 else numctlresponses ++ ;
 }
 res_frags ++ ;
 res_offset += dlen ;
 datapt = rpkt . u . data ;
 }


int jas_image_encode(jas_image_t *image, jas_stream_t *out, int fmt, char *optstr)
{
	jas_image_fmtinfo_t *fmtinfo;
	if (!(fmtinfo = jas_image_lookupfmtbyid(fmt))) {
		return -1;
	}
	return (fmtinfo->ops.encode) ? (*fmtinfo->ops.encode)(image, out,
	  optstr) : (-1);
}


mbfl_string * mbfl_buffer_converter_getbuffer ( mbfl_buffer_converter * convd , mbfl_string * result ) {
 if ( convd != NULL && result != NULL && convd -> device . buffer != NULL ) {
 result -> no_encoding = convd -> to -> no_encoding ;
 result -> val = convd -> device . buffer ;
 result -> len = convd -> device . pos ;
 }
 else {
 result = NULL ;
 }
 return result ;
 }


int16 get_typlen ( Oid typid ) {
 HeapTuple tp ;
 tp = SearchSysCache1 ( TYPEOID , ObjectIdGetDatum ( typid ) ) ;
 if ( HeapTupleIsValid ( tp ) ) {
 Form_pg_type typtup = ( Form_pg_type ) GETSTRUCT ( tp ) ;
 int16 result ;
 result = typtup -> typlen ;
 ReleaseSysCache ( tp ) ;
 return result ;
 }
 else return 0 ;
 }


static void jp2_cmap_destroy(jp2_box_t *box)
{
	jp2_cmap_t *cmap = &box->data.cmap;
	if (cmap->ents) {
		jas_free(cmap->ents);
	}
}


MSG_PROCESS_RETURN tls_process_change_cipher_spec ( SSL * s , PACKET * pkt ) {
 int al ;
 long remain ;
 remain = PACKET_remaining ( pkt ) ;
 if ( SSL_IS_DTLS ( s ) ) {
 if ( ( s -> version == DTLS1_BAD_VER && remain != DTLS1_CCS_HEADER_LENGTH + 1 ) || ( s -> version != DTLS1_BAD_VER && remain != DTLS1_CCS_HEADER_LENGTH - 1 ) ) {
 al = SSL_AD_ILLEGAL_PARAMETER ;
 SSLerr ( SSL_F_TLS_PROCESS_CHANGE_CIPHER_SPEC , SSL_R_BAD_CHANGE_CIPHER_SPEC ) ;
 goto f_err ;
 }
 }
 else {
 if ( remain != 0 ) {
 al = SSL_AD_ILLEGAL_PARAMETER ;
 SSLerr ( SSL_F_TLS_PROCESS_CHANGE_CIPHER_SPEC , SSL_R_BAD_CHANGE_CIPHER_SPEC ) ;
 goto f_err ;
 }
 }
 if ( s -> s3 -> tmp . new_cipher == NULL ) {
 al = SSL_AD_UNEXPECTED_MESSAGE ;
 SSLerr ( SSL_F_TLS_PROCESS_CHANGE_CIPHER_SPEC , SSL_R_CCS_RECEIVED_EARLY ) ;
 goto f_err ;
 }
 s -> s3 -> change_cipher_spec = 1 ;
 if ( ! ssl3_do_change_cipher_spec ( s ) ) {
 al = SSL_AD_INTERNAL_ERROR ;
 SSLerr ( SSL_F_TLS_PROCESS_CHANGE_CIPHER_SPEC , ERR_R_INTERNAL_ERROR ) ;
 goto f_err ;
 }
 if ( SSL_IS_DTLS ( s ) ) {
 dtls1_reset_seq_numbers ( s , SSL3_CC_READ ) ;
 if ( s -> version == DTLS1_BAD_VER ) s -> d1 -> handshake_read_seq ++ ;
 # ifndef OPENSSL_NO_SCTP BIO_ctrl ( SSL_get_wbio ( s ) , BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD , 1 , NULL ) ;
 # endif }
 return MSG_PROCESS_CONTINUE_READING ;
 f_err : ssl3_send_alert ( s , SSL3_AL_FATAL , al ) ;
 ossl_statem_set_error ( s ) ;
 return MSG_PROCESS_ERROR ;
 }


int jas_stream_isseekable(jas_stream_t *stream)
{
	if (stream->ops_ == &jas_stream_memops) {
		return 1;
	} else if (stream->ops_ == &jas_stream_fileops) {
		if ((*stream->ops_->seek_)(stream->obj_, 0, SEEK_CUR) < 0) {
			return 0;
		}
		return 1;
	} else {
		return 0;
	}
}


static int dissect_h225_StimulusControl ( tvbuff_t * tvb _U_ , int offset _U_ , asn1_ctx_t * actx _U_ , proto_tree * tree _U_ , int hf_index _U_ ) {
 offset = dissect_per_sequence ( tvb , offset , actx , tree , hf_index , ett_h225_StimulusControl , StimulusControl_sequence ) ;
 return offset ;
 }


static long nfatree ( struct vars * v , struct subre * t , FILE * f ) {
 assert ( t != NULL && t -> begin != NULL ) ;
 if ( t -> left != NULL ) ( DISCARD ) nfatree ( v , t -> left , f ) ;
 if ( t -> right != NULL ) ( DISCARD ) nfatree ( v , t -> right , f ) ;
 return nfanode ( v , t , 0 , f ) ;
 }


static void * jbig2_default_alloc ( Jbig2Allocator * allocator , size_t size ) {
 return malloc ( size ) ;
 }


jas_stream_t *jpc_streamlist_remove(jpc_streamlist_t *streamlist, int streamno)
{
	jas_stream_t *stream;
	int i;
	if (streamno >= streamlist->numstreams) {
		abort();
	}
	stream = streamlist->streams[streamno];
	for (i = streamno + 1; i < streamlist->numstreams; ++i) {
		streamlist->streams[i - 1] = streamlist->streams[i];
	}
	--streamlist->numstreams;
	return stream;
}


static char * sic10_opaque_literal_attr ( tvbuff_t * tvb , guint32 offset , const char * token , guint8 codepage _U_ , guint32 * length ) {
 guint32 data_len = tvb_get_guintvar ( tvb , offset , length ) ;
 char * str = NULL ;
 if ( token && ( ( strcmp ( token , "created" ) == 0 ) || ( strcmp ( token , "si-expires" ) == 0 ) ) ) {
 str = date_time_from_opaque ( tvb , offset + * length , data_len ) ;
 }
 if ( str == NULL ) {
 str = wmem_strdup_printf ( wmem_packet_scope ( ) , "(%d bytes of unparsed opaque data)" , data_len ) ;
 }
 * length += data_len ;
 return str ;
 }


TSFetchSM TSFetchCreate ( TSCont contp , const char * method , const char * url , const char * version , struct sockaddr const * client_addr , int flags ) {
 sdk_assert ( sdk_sanity_check_continuation ( contp ) == TS_SUCCESS ) ;
 sdk_assert ( ats_is_ip ( client_addr ) ) ;
 FetchSM * fetch_sm = FetchSMAllocator . alloc ( ) ;
 fetch_sm -> ext_init ( ( Continuation * ) contp , method , url , version , client_addr , flags ) ;
 return ( TSFetchSM ) fetch_sm ;
 }


static void activation_start_timed_cancel ( ActivateParameters * parameters ) {
 parameters -> timed_wait_active = TRUE ;
 eel_timed_wait_start_with_duration ( DELAY_UNTIL_CANCEL_MSECS , cancel_activate_callback , parameters , parameters -> timed_wait_prompt , parameters -> parent_window ) ;
 }


long jas_stream_length(jas_stream_t *stream)
{
	long oldpos;
	long pos;
	if ((oldpos = jas_stream_tell(stream)) < 0) {
		return -1;
	}
	if (jas_stream_seek(stream, 0, SEEK_END) < 0) {
		return -1;
	}
	if ((pos = jas_stream_tell(stream)) < 0) {
		return -1;
	}
	if (jas_stream_seek(stream, oldpos, SEEK_SET) < 0) {
		return -1;
	}
	return pos;
}


static int bmp_gobble(jas_stream_t *in, long n)
{
	while (--n >= 0) {
		if (jas_stream_getc(in) == EOF) {
			return -1;
		}
	}
	return 0;
}


bool cmp_items ( Item * a , Item * b ) {
 return a -> eq ( b , FALSE ) ;
 }