NITF_BOOL writeImage(nitf_ImageSegment* segment, nitf_IOHandle input_io, nitf_IOHandle output_io) { nitf_Error error; nitf_Off offset; int ret; nitf_ImageIO* ioClone; nitf_Uint8** buffer; nitf_Uint32 nBits, nBands, xBands, nRows, nColumns; nitf_SubWindow *subimage; size_t subimageSize; nitf_Uint32 band; nitf_Uint32 *bandList; NITF_BOOL success; int padded; nitf_ImageSource *imgSrc; /* Image source object */ nitf_BandSource *bandSrc; /* Current band source object */ /* clone the imageIO */ ioClone = nitf_ImageIO_clone(segment->imageIO, &error); if (!ioClone) { nitf_Error_print(&error, stderr, "Clone failed"); goto CATCH_ERROR; } /* get IO offset, and set the offset for the ImageIO */ offset = nitf_IOHandle_tell(output_io, &error); if (!NITF_IO_SUCCESS(offset)) goto CATCH_ERROR; if (!nitf_ImageIO_setFileOffset(segment->imageIO, offset, &error)) { goto CATCH_ERROR; } /* Read image */ GET_UINT32(segment->subheader->numBitsPerPixel, &nBits, &error); GET_UINT32(segment->subheader->numImageBands, &nBands, &error); GET_UINT32(segment->subheader->numMultispectralImageBands, &xBands, &error); nBands += xBands; GET_UINT32(segment->subheader->numRows, &nRows, &error); GET_UINT32(segment->subheader->numCols, &nColumns, &error); subimageSize = nRows * nColumns * NITF_NBPP_TO_BYTES(nBits); /* Allcoate buffers */ buffer = (nitf_Uint8 **)malloc(8 * nBands); assert(buffer); for (band = 0; band < nBands; band++) { buffer[band] = (nitf_Uint8*)malloc(subimageSize); assert(buffer[band]); } /* Set-up band array and subimage */ bandList = (nitf_Uint32 *)malloc(sizeof(nitf_Uint32 *) * nBands); subimage = nitf_SubWindow_construct(&error); assert(subimage); subimage->startCol = 0; subimage->startRow = 0; subimage->numRows = nRows; subimage->numCols = nColumns; for (band = 0; band < nBands; band++) { bandList[band] = band; } subimage->bandList = bandList; subimage->numBands = nBands; /* Read data */ if (!nitf_ImageIO_read(ioClone, input_io, subimage, buffer, &padded, &error) ) { nitf_Error_print(&error, stderr, "Read failed"); return(0); } free(bandList); /* Setup for image source */ imgSrc = nitf_ImageSource_construct(&error); if (imgSrc == NULL) return(0); for (band = 0; band < nBands; band++) { bandSrc = nitf_MemorySource_construct(buffer[band], (size_t) subimageSize, (nitf_Off) 0, NITF_NBPP_TO_BYTES(nBits), 0, &error); if (bandSrc == NULL) return(0); if (!nitf_ImageSource_addBand(imgSrc, bandSrc, &error)) return(0); } /* Do write */ ret = doWrite(segment, imgSrc, output_io, ioClone); if (ioClone) nitf_ImageIO_destruct(&ioClone); nitf_ImageSource_destruct(&imgSrc); /* OK return */ return ret; CATCH_ERROR: if (ioClone) nitf_ImageIO_destruct(&ioClone); printf("ERROR processing\n"); return 0; }
GtkIconData * _gtk_icon_cache_get_icon_data (GtkIconCache *cache, const gchar *icon_name, gint directory_index) { guint32 offset, image_data_offset, meta_data_offset; GtkIconData *data; int i; offset = find_image_offset (cache, icon_name, directory_index); if (!offset) return NULL; image_data_offset = GET_UINT32 (cache->buffer, offset + 4); if (!image_data_offset) return NULL; meta_data_offset = GET_UINT32 (cache->buffer, image_data_offset + 4); if (!meta_data_offset) return NULL; data = g_slice_new0 (GtkIconData); data->ref = 1; offset = GET_UINT32 (cache->buffer, meta_data_offset); if (offset) { data->has_embedded_rect = TRUE; data->x0 = GET_UINT16 (cache->buffer, offset); data->y0 = GET_UINT16 (cache->buffer, offset + 2); data->x1 = GET_UINT16 (cache->buffer, offset + 4); data->y1 = GET_UINT16 (cache->buffer, offset + 6); } offset = GET_UINT32 (cache->buffer, meta_data_offset + 4); if (offset) { data->n_attach_points = GET_UINT32 (cache->buffer, offset); data->attach_points = g_new (GdkPoint, data->n_attach_points); for (i = 0; i < data->n_attach_points; i++) { data->attach_points[i].x = GET_UINT16 (cache->buffer, offset + 4 + 4 * i); data->attach_points[i].y = GET_UINT16 (cache->buffer, offset + 4 + 4 * i + 2); } } offset = GET_UINT32 (cache->buffer, meta_data_offset + 8); if (offset) { gint n_names; gchar *lang, *name; gchar **langs; GHashTable *table = g_hash_table_new (g_str_hash, g_str_equal); n_names = GET_UINT32 (cache->buffer, offset); for (i = 0; i < n_names; i++) { lang = cache->buffer + GET_UINT32 (cache->buffer, offset + 4 + 8 * i); name = cache->buffer + GET_UINT32 (cache->buffer, offset + 4 + 8 * i + 4); g_hash_table_insert (table, lang, name); } langs = (gchar **)g_get_language_names (); for (i = 0; langs[i]; i++) { name = g_hash_table_lookup (table, langs[i]); if (name) { data->display_name = g_strdup (name); break; } } g_hash_table_destroy (table); } return data; }
static gint find_image_offset (GtkIconCache *cache, const gchar *icon_name, gint directory_index) { guint32 hash_offset; guint32 n_buckets; guint32 chain_offset; int hash; guint32 image_list_offset, n_images; int i; if (!icon_name) return 0; chain_offset = cache->last_chain_offset; if (chain_offset) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) goto find_dir; } hash_offset = GET_UINT32 (cache->buffer, 4); n_buckets = GET_UINT32 (cache->buffer, hash_offset); hash = icon_name_hash (icon_name) % n_buckets; chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash); while (chain_offset != 0xffffffff) { guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4); gchar *name = cache->buffer + name_offset; if (strcmp (name, icon_name) == 0) { cache->last_chain_offset = chain_offset; goto find_dir; } chain_offset = GET_UINT32 (cache->buffer, chain_offset); } cache->last_chain_offset = 0; return 0; find_dir: /* We've found an icon list, now check if we have the right icon in it */ image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8); n_images = GET_UINT32 (cache->buffer, image_list_offset); for (i = 0; i < n_images; i++) { if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * i) == directory_index) return image_list_offset + 4 + 8 * i; } return 0; }
UINT32 sbc_GetData( SSHdl *hdl, UINT8 *buf, UINT32 buf_len, UINT32 *sample_cnt ) { UINT8 uSbcHeaderWord[4]; UINT32 headerstream,skip_num=0; sbcHeaderStruct stSbcHeader; UINT32 get_length=0,frame_length,offset =0; UINT8 media_head=0; UINT16 nframe=0; sbc_struct*ihdl = (sbc_struct *)hdl; ass( hdl == NULL ); if( SSHdl_GetDataCount( hdl ) == 0 ) return 0; // MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc_GetData is called,ihdl->current_frame_size=%d",ihdl->current_frame_size); frame_length=ihdl->current_frame_size; nframe = (UINT16) buf_len/frame_length; do { if( SSHdl_GetDataCount( hdl ) >= 4 ) { SSHdl_SniffNBytes( hdl, 0, 4, uSbcHeaderWord ); headerstream = GET_UINT32( uSbcHeaderWord ); memcpy(&stSbcHeader, &headerstream, 4); if((stSbcHeader.Sync==ihdl->config_header.Sync)&& (stSbcHeader.Subbands==ihdl->config_header.Subbands)&& // (stSbcHeader.Sample_rate==ihdl->config_header.Sample_rate)&& (stSbcHeader.ChannelMode==ihdl->config_header.ChannelMode)&& (stSbcHeader.Blocks==ihdl->config_header.Blocks)&& (stSbcHeader.Bitpool==ihdl->config_header.Bitpool)&& (stSbcHeader.Allocation_method==ihdl->config_header.Allocation_method) ) { get_length=nframe*(frame_length); media_head=nframe; if(SSHdl_GetDataCount( hdl ) >(get_length+4)) { offset=get_length; } else { get_length=(nframe-1)*(frame_length); media_head=(nframe-1); if(SSHdl_GetDataCount( hdl ) >(get_length+4)) offset=get_length; else { MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc_GetData rb no enough data"); break; } } break; } else { MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"skip 1 byte"); SSHdl_ShiftReadPointer( hdl, 1 );//skip 1 byte if((++skip_num)>frame_length) { skip_num=0; MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"***skip_num>frame_length"); break; // ass(1); } } } else { MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"rb number <4bytes"); break; } }while(1); skip_num=0; if(offset ) { UINT8 flag=0; do { SSHdl_SniffNBytes( hdl, offset, 4, uSbcHeaderWord ); headerstream = GET_UINT32( uSbcHeaderWord ); memcpy(&stSbcHeader, &headerstream, 4); if((stSbcHeader.Sync==ihdl->config_header.Sync)&& (stSbcHeader.Subbands==ihdl->config_header.Subbands)&& // (stSbcHeader.Sample_rate==ihdl->config_header.Sample_rate)&& (stSbcHeader.ChannelMode==ihdl->config_header.ChannelMode)&& (stSbcHeader.Blocks==ihdl->config_header.Blocks)&& (stSbcHeader.Bitpool==ihdl->config_header.Bitpool)&& (stSbcHeader.Allocation_method==ihdl->config_header.Allocation_method) ) { flag=1; break; } else { offset++; get_length++; MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"skip 1 byte next packet"); if((++skip_num)>frame_length) { skip_num=0; MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"***skip 1 byte next packet>frame_length"); //ass(1); break; } } }while(1); // MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"flag=%d",flag); if(flag) { UINT32 cnt=get_length, cnt2=0; *buf=media_head; buf++; buf_len--; //if(buf_len<cnt) ?????? while( cnt > 0 ) { UINT8 *src; SSHdl_GetReadBuffer( hdl, &src, &cnt2 ); if( cnt2 > cnt ) cnt2 = cnt; memcpy( buf, src, cnt2 ); SSHdl_ShiftReadPointer( hdl, cnt2 ); buf += cnt2; cnt -= cnt2; } // MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc_GetData success ~!~!get_length=%d",get_length); return get_length+1; } else { MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc_GetData flag =0!!"); return 0; } } else { MCI_TRACE ( TSTDOUT | MCI_AUDIO_TRC,0,"sbc rb is null!!"); return 0; } }
/* Cache-inhibited register access */ static __inline__ uint32_t __bm_in(struct bm_addr *bm, uintptr_t offset) { uint32_t *tmp = (uint32_t *)ptr_ADD(bm->addr_ci, offset); return GET_UINT32(*tmp); }
static uint32 disk_set_info(IRP * irp) { FILE_INFO *finfo; uint32 status; uint64 len; char * buf; int size; char * fullpath; struct stat file_stat; struct utimbuf tvs; int mode; uint32 attr; time_t t; LLOGLN(10, ("disk_set_info: class=%d id=%d", irp->infoClass, irp->fileID)); finfo = disk_get_file_info(irp->dev, irp->fileID); if (finfo == NULL) { LLOGLN(0, ("disk_set_info: invalid file id")); return RD_STATUS_INVALID_HANDLE; } status = RD_STATUS_SUCCESS; switch (irp->infoClass) { case FileBasicInformation: if (stat(finfo->fullpath, &file_stat) != 0) return get_error_status(); /* Change file time */ tvs.actime = file_stat.st_atime; tvs.modtime = file_stat.st_mtime; t = get_system_filetime(GET_UINT64(irp->inputBuffer, 8)); /* LastAccessTime */ if (t > 0) tvs.actime = t; t = get_system_filetime(GET_UINT64(irp->inputBuffer, 16)); /* LastWriteTime */ if (t > 0) tvs.modtime = t; utime(finfo->fullpath, &tvs); /* Change read-only flag */ attr = GET_UINT32(irp->inputBuffer, 32); if (attr == 0) break; mode = file_stat.st_mode; if (attr & FILE_ATTRIBUTE_READONLY) mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); else mode |= S_IWUSR; mode &= 0777; chmod(finfo->fullpath, mode); break; case FileEndOfFileInformation: case FileAllocationInformation: len = GET_UINT64(irp->inputBuffer, 0); set_file_size(finfo->file, len); break; case FileDispositionInformation: /* Delete on close */ finfo->delete_pending = 1; break; case FileRenameInformation: //replaceIfExists = GET_UINT8(irp->inputBuffer, 0); /* ReplaceIfExists */ //rootDirectory = GET_UINT8(irp->inputBuffer, 1); /* RootDirectory */ len = GET_UINT32(irp->inputBuffer, 2); size = len * 2; buf = malloc(size); memset(buf, 0, size); freerdp_get_wstr(buf, size, irp->inputBuffer + 6, len); fullpath = disk_get_fullpath(irp->dev, buf); free(buf); LLOGLN(10, ("disk_set_info: rename %s to %s", finfo->fullpath, fullpath)); if (rename(finfo->fullpath, fullpath) == 0) { free(finfo->fullpath); finfo->fullpath = fullpath; } else { free(fullpath); return get_error_status(); } break; default: LLOGLN(0, ("disk_set_info: invalid info class")); status = RD_STATUS_NOT_SUPPORTED; break; } return status; }
int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) { const unsigned char *p = message->options; const unsigned char *end = p; /* Add size later for gcc-3 issue */ unsigned char option; unsigned char length; unsigned int len = 0; int i; int retval = -1; struct timeval tv; route_t *routers = NULL; route_t *routersp = NULL; route_t *static_routes = NULL; route_t *static_routesp = NULL; route_t *csr = NULL; bool in_overload = false; bool parse_sname = false; bool parse_file = false; end += sizeof (message->options); if (gettimeofday (&tv, NULL) == -1) { logger (LOG_ERR, "gettimeofday: %s", strerror (errno)); return (-1); } dhcp->address.s_addr = message->yiaddr; dhcp->leasedfrom = tv.tv_sec; dhcp->frominfo = false; dhcp->address.s_addr = message->yiaddr; strlcpy (dhcp->servername, (char *) message->servername, sizeof (dhcp->servername)); #define LEN_ERR \ { \ logger (LOG_ERR, "invalid length %d for option %d", length, option); \ p += length; \ continue; \ } parse_start: while (p < end) { option = *p++; if (! option) continue; if (option == DHCP_END) goto eexit; length = *p++; if (option != DHCP_PAD && length == 0) { logger (LOG_ERR, "option %d has zero length", option); retval = -1; goto eexit; } if (p + length >= end) { logger (LOG_ERR, "dhcp option exceeds message length"); retval = -1; goto eexit; } switch (option) { case DHCP_MESSAGETYPE: retval = (int) *p; p += length; continue; default: if (length == 0) { logger (LOG_DEBUG, "option %d has zero length, skipping", option); continue; } } #define LENGTH(_length) \ if (length != _length) \ LEN_ERR; #define MIN_LENGTH(_length) \ if (length < _length) \ LEN_ERR; #define MULT_LENGTH(_mult) \ if (length % _mult != 0) \ LEN_ERR; #define GET_UINT8(_val) \ LENGTH (sizeof (uint8_t)); \ memcpy (&_val, p, sizeof (uint8_t)); #define GET_UINT16(_val) \ LENGTH (sizeof (uint16_t)); \ memcpy (&_val, p, sizeof (uint16_t)); #define GET_UINT32(_val) \ LENGTH (sizeof (uint32_t)); \ memcpy (&_val, p, sizeof (uint32_t)); #define GET_UINT16_H(_val) \ GET_UINT16 (_val); \ _val = ntohs (_val); #define GET_UINT32_H(_val) \ GET_UINT32 (_val); \ _val = ntohl (_val); switch (option) { case DHCP_ADDRESS: GET_UINT32 (dhcp->address.s_addr); break; case DHCP_NETMASK: GET_UINT32 (dhcp->netmask.s_addr); break; case DHCP_BROADCAST: GET_UINT32 (dhcp->broadcast.s_addr); break; case DHCP_SERVERIDENTIFIER: GET_UINT32 (dhcp->serveraddress.s_addr); break; case DHCP_LEASETIME: GET_UINT32_H (dhcp->leasetime); break; case DHCP_RENEWALTIME: GET_UINT32_H (dhcp->renewaltime); break; case DHCP_REBINDTIME: GET_UINT32_H (dhcp->rebindtime); break; case DHCP_MTU: GET_UINT16_H (dhcp->mtu); /* Minimum legal mtu is 68 accoridng to RFC 2132. In practise it's 576 (minimum maximum message size) */ if (dhcp->mtu < MTU_MIN) { logger (LOG_DEBUG, "MTU %d is too low, minimum is %d; ignoring", dhcp->mtu, MTU_MIN); dhcp->mtu = 0; } break; #undef GET_UINT32_H #undef GET_UINT32 #undef GET_UINT16_H #undef GET_UINT16 #undef GET_UINT8 #define GETSTR(_var) \ MIN_LENGTH (sizeof (char)); \ if (_var) free (_var); \ _var = xmalloc (length + 1); \ memcpy (_var, p, length); \ memset (_var + length, 0, 1); case DHCP_HOSTNAME: GETSTR (dhcp->hostname); break; case DHCP_DNSDOMAIN: GETSTR (dhcp->dnsdomain); break; case DHCP_MESSAGE: GETSTR (dhcp->message); break; case DHCP_ROOTPATH: GETSTR (dhcp->rootpath); break; case DHCP_NISDOMAIN: GETSTR (dhcp->nisdomain); break; #undef GETSTR #define GETADDR(_var) \ MULT_LENGTH (4); \ if (! dhcp_add_address (&_var, p, length)) \ { \ retval = -1; \ goto eexit; \ } case DHCP_DNSSERVER: GETADDR (dhcp->dnsservers); break; case DHCP_NTPSERVER: GETADDR (dhcp->ntpservers); break; case DHCP_NISSERVER: GETADDR (dhcp->nisservers); break; #undef GETADDR case DHCP_DNSSEARCH: MIN_LENGTH (1); free (dhcp->dnssearch); if ((len = decode_search (p, length, NULL)) > 0) { dhcp->dnssearch = xmalloc (len); decode_search (p, length, dhcp->dnssearch); } break; case DHCP_CSR: MIN_LENGTH (5); free_route (csr); csr = decode_CSR (p, length); break; case DHCP_SIPSERVER: free (dhcp->sipservers); dhcp->sipservers = decode_sipservers (p, length); break; case DHCP_STATICROUTE: MULT_LENGTH (8); for (i = 0; i < length; i += 8) { if (static_routesp) { static_routesp->next = xmalloc (sizeof (route_t)); static_routesp = static_routesp->next; } else static_routesp = static_routes = xmalloc (sizeof (route_t)); memset (static_routesp, 0, sizeof (route_t)); memcpy (&static_routesp->destination.s_addr, p + i, 4); memcpy (&static_routesp->gateway.s_addr, p + i + 4, 4); static_routesp->netmask.s_addr = route_netmask (static_routesp->destination.s_addr); } break; case DHCP_ROUTERS: MULT_LENGTH (4); for (i = 0; i < length; i += 4) { if (routersp) { routersp->next = xmalloc (sizeof (route_t)); routersp = routersp->next; } else routersp = routers = xmalloc (sizeof (route_t)); memset (routersp, 0, sizeof (route_t)); memcpy (&routersp->gateway.s_addr, p + i, 4); } break; case DHCP_OPTIONSOVERLOADED: LENGTH (1); /* The overloaded option in an overloaded option * should be ignored, overwise we may get an infinite loop */ if (! in_overload) { if (*p & 1) parse_file = true; if (*p & 2) parse_sname = true; } break; #undef LENGTH #undef MIN_LENGTH #undef MULT_LENGTH default: logger (LOG_DEBUG, "no facility to parse DHCP code %u", option); break; } p += length; } eexit: /* We may have options overloaded, so go back and grab them */ if (parse_file) { parse_file = false; p = message->bootfile; end = p + sizeof (message->bootfile); in_overload = true; goto parse_start; } else if (parse_sname) { parse_sname = false; p = message->servername; end = p + sizeof (message->servername); memset (dhcp->servername, 0, sizeof (dhcp->servername)); in_overload = true; goto parse_start; } /* Fill in any missing fields */ if (! dhcp->netmask.s_addr) dhcp->netmask.s_addr = get_netmask (dhcp->address.s_addr); if (! dhcp->broadcast.s_addr) dhcp->broadcast.s_addr = dhcp->address.s_addr | ~dhcp->netmask.s_addr; /* If we have classess static routes then we discard static routes and routers according to RFC 3442 */ if (csr) { dhcp->routes = csr; free_route (routers); free_route (static_routes); } else { /* Ensure that we apply static routes before routers */ if (static_routes) { dhcp->routes = static_routes; static_routesp->next = routers; } else dhcp->routes = routers; } return retval; }
int _xdg_mime_cache_mime_type_subclass (const char *mime, const char *base) { const char *umime, *ubase; int i, j, min, max, med, cmp; umime = _xdg_mime_cache_unalias_mime_type (mime); ubase = _xdg_mime_cache_unalias_mime_type (base); if (strcmp (umime, ubase) == 0) return 1; /* We really want to handle text/ * in GtkFileFilter, so we just * turn on the supertype matching */ #if 1 /* Handle supertypes */ if (is_super_type (ubase) && xdg_mime_media_type_equal (umime, ubase)) return 1; #endif /* Handle special cases text/plain and application/octet-stream */ if (strcmp (ubase, "text/plain") == 0 && strncmp (umime, "text/", 5) == 0) return 1; if (strcmp (ubase, "application/octet-stream") == 0) return 1; for (i = 0; _caches[i]; i++) { XdgMimeCache *cache = _caches[i]; xdg_uint32_t list_offset = GET_UINT32 (cache->buffer, 8); xdg_uint32_t n_entries = GET_UINT32 (cache->buffer, list_offset); xdg_uint32_t offset, n_parents, parent_offset; min = 0; max = n_entries - 1; while (max >= min) { med = (min + max)/2; offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * med); cmp = strcmp (cache->buffer + offset, umime); if (cmp < 0) min = med + 1; else if (cmp > 0) max = med - 1; else { offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * med + 4); n_parents = GET_UINT32 (cache->buffer, offset); for (j = 0; j < n_parents; j++) { parent_offset = GET_UINT32 (cache->buffer, offset + 4 + 4 * j); if (_xdg_mime_cache_mime_type_subclass (cache->buffer + parent_offset, ubase)) return 1; } break; } } } return 0; }
PCSC_API LONG SCardTransmit(SCARDHANDLE hCard, const SCARD_IO_REQUEST *pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, SCARD_IO_REQUEST *pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength) { char *msg; int bytes; int code; int offset; int status; int extra_len; int got_recv_pci; LLOGLN(10, ("SCardTransmit:")); if (g_sck == -1) { LLOGLN(0, ("SCardTransmit: error, not connected")); return SCARD_F_INTERNAL_ERROR; } LLOGLN(10, (" hCard 0x%8.8x", (int)hCard)); LLOGLN(10, (" cbSendLength %d", (int)cbSendLength)); LLOGLN(10, (" cbRecvLength %d", (int)*pcbRecvLength)); LLOGLN(10, (" pioSendPci->dwProtocol %d", (int)(pioSendPci->dwProtocol))); LLOGLN(10, (" pioSendPci->cbPciLength %d", (int)(pioSendPci->cbPciLength))); LLOGLN(10, (" pioRecvPci %p", pioRecvPci)); if (pioRecvPci != 0) { LLOGLN(10, (" pioRecvPci->dwProtocol %d", (int)(pioRecvPci->dwProtocol))); LLOGLN(10, (" pioRecvPci->cbPciLength %d", (int)(pioRecvPci->cbPciLength))); } msg = (char *) malloc(8192); offset = 0; SET_UINT32(msg, offset, hCard); offset += 4; SET_UINT32(msg, offset, pioSendPci->dwProtocol); offset += 4; /* SET_UINT32(msg, offset, pioSendPci->cbPciLength); */ SET_UINT32(msg, offset, 8); offset += 4; /* extra_len = pioSendPci->cbPciLength - 8; */ extra_len = 0; SET_UINT32(msg, offset, extra_len); offset += 4; memcpy(msg + offset, pioSendPci + 1, extra_len); offset += extra_len; SET_UINT32(msg, offset, cbSendLength); offset += 4; memcpy(msg + offset, pbSendBuffer, cbSendLength); offset += cbSendLength; // TODO figure out why recv pci does not work if (1 || (pioRecvPci == 0) || (pioRecvPci->cbPciLength < 8)) { got_recv_pci = 0; SET_UINT32(msg, offset, 0); /* dwProtocol */ offset += 4; SET_UINT32(msg, offset, 0); /* cbPciLength */ offset += 4; SET_UINT32(msg, offset, 0); /* extra_len */ offset += 4; } else { got_recv_pci = 1; SET_UINT32(msg, offset, pioRecvPci->dwProtocol); offset += 4; SET_UINT32(msg, offset, pioRecvPci->cbPciLength); offset += 4; extra_len = pioRecvPci->cbPciLength - 8; SET_UINT32(msg, offset, extra_len); offset += 4; memcpy(msg + offset, pioRecvPci + 1, extra_len); offset += extra_len; } SET_UINT32(msg, offset, *pcbRecvLength); offset += 4; if (send_message(SCARD_TRANSMIT, msg, offset) != 0) { LLOGLN(0, ("SCardTransmit: error, send_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } bytes = 8192; code = SCARD_TRANSMIT; if (get_message(&code, msg, &bytes) != 0) { LLOGLN(0, ("SCardTransmit: error, get_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } if (code != SCARD_TRANSMIT) { LLOGLN(0, ("SCardTransmit: error, bad code")); free(msg); return SCARD_F_INTERNAL_ERROR; } offset = 0; if (got_recv_pci == 0) { offset += 8; extra_len = GET_UINT32(msg, offset); offset += 4; offset += extra_len; } else { pioRecvPci->dwProtocol = GET_UINT32(msg, offset); offset += 4; pioRecvPci->cbPciLength = GET_UINT32(msg, offset); offset += 4; extra_len = GET_UINT32(msg, offset); offset += 4; offset += extra_len; } *pcbRecvLength = GET_UINT32(msg, offset); offset += 4; LLOGLN(10, (" cbRecvLength %d", (int)*pcbRecvLength)); memcpy(pbRecvBuffer, msg + offset, *pcbRecvLength); LHEXDUMP(10, (pbRecvBuffer, *pcbRecvLength)); offset += *pcbRecvLength; status = GET_UINT32(msg, offset); free(msg); return status; }
static int rdpsnd_pulse_set_format(rdpsndDevicePlugin * devplugin, char * snd_format, int size) { struct pulse_device_data * pulse_data; pa_sample_spec sample_spec = { 0 }; int nChannels; int wBitsPerSample; int nSamplesPerSec; int wFormatTag; int nBlockAlign; pulse_data = (struct pulse_device_data *) devplugin->device_data; if (!pulse_data->context) return 1; wFormatTag = GET_UINT16(snd_format, 0); nChannels = GET_UINT16(snd_format, 2); nSamplesPerSec = GET_UINT32(snd_format, 4); nBlockAlign = GET_UINT16(snd_format, 12); wBitsPerSample = GET_UINT16(snd_format, 14); LLOGLN(0, ("rdpsnd_pulse_set_format: wFormatTag=%d nChannels=%d " "nSamplesPerSec=%d wBitsPerSample=%d nBlockAlign=%d", wFormatTag, nChannels, nSamplesPerSec, wBitsPerSample, nBlockAlign)); sample_spec.rate = nSamplesPerSec; sample_spec.channels = nChannels; switch (wFormatTag) { case 1: /* PCM */ switch (wBitsPerSample) { case 8: sample_spec.format = PA_SAMPLE_U8; break; case 16: sample_spec.format = PA_SAMPLE_S16LE; break; } break; case 6: /* A-LAW */ sample_spec.format = PA_SAMPLE_ALAW; break; case 7: /* U-LAW */ sample_spec.format = PA_SAMPLE_ULAW; break; case 0x11: /* IMA ADPCM */ sample_spec.format = PA_SAMPLE_S16LE; break; } pulse_data->sample_spec = sample_spec; pulse_data->format = wFormatTag; pulse_data->block_size = nBlockAlign; if (pulse_data->stream) { pa_threaded_mainloop_lock(pulse_data->mainloop); pa_stream_disconnect(pulse_data->stream); pa_stream_unref(pulse_data->stream); pulse_data->stream = NULL; pa_threaded_mainloop_unlock(pulse_data->mainloop); } rdpsnd_pulse_open(devplugin); return 0; }
static int cache_glob_node_lookup_suffix (XdgMimeCache *cache, xdg_uint32_t n_entries, xdg_uint32_t offset, const char *file_name, int len, int case_sensitive_check, MimeWeight mime_types[], int n_mime_types) { xdg_unichar_t character; xdg_unichar_t match_char; xdg_uint32_t mimetype_offset; xdg_uint32_t n_children; xdg_uint32_t child_offset; int weight; int case_sensitive; int min, max, mid, n, i; character = file_name[len - 1]; assert (character != 0); min = 0; max = n_entries - 1; while (max >= min) { mid = (min + max) / 2; match_char = GET_UINT32 (cache->buffer, offset + 12 * mid); if (match_char < character) min = mid + 1; else if (match_char > character) max = mid - 1; else { len--; n = 0; n_children = GET_UINT32 (cache->buffer, offset + 12 * mid + 4); child_offset = GET_UINT32 (cache->buffer, offset + 12 * mid + 8); if (len > 0) { n = cache_glob_node_lookup_suffix (cache, n_children, child_offset, file_name, len, case_sensitive_check, mime_types, n_mime_types); } if (n == 0) { i = 0; while (n < n_mime_types && i < n_children) { match_char = GET_UINT32 (cache->buffer, child_offset + 12 * i); if (match_char != 0) break; mimetype_offset = GET_UINT32 (cache->buffer, child_offset + 12 * i + 4); weight = GET_UINT32 (cache->buffer, child_offset + 12 * i + 8); case_sensitive = weight & 0x100; weight = weight & 0xff; if (case_sensitive_check || !case_sensitive) { mime_types[n].mime = cache->buffer + mimetype_offset; mime_types[n].weight = weight; n++; } i++; } } return n; } } return 0; }
static int audin_process_formats(IWTSVirtualChannelCallback * pChannelCallback, char * data, uint32 data_size) { AUDIN_CHANNEL_CALLBACK * callback = (AUDIN_CHANNEL_CALLBACK *) pChannelCallback; uint32 NumFormats; uint32 i; int size; int out_size; char * ldata; char * out_data; char * lout_formats; int out_format_count; int error; NumFormats = GET_UINT32(data, 0); if ((NumFormats < 1) || (NumFormats > 1000)) { LLOGLN(0, ("audin_process_formats: bad NumFormats %d", NumFormats)); return 1; } /* Ignore cbSizeFormatsPacket */ size = sizeof(char *) * (NumFormats + 1); callback->formats_data = (char **) malloc(size); memset(callback->formats_data, 0, size); out_size = data_size + 1; out_data = (char *) malloc(out_size); memset(out_data, 0, out_size); lout_formats = out_data + 9; /* remainder is sndFormats (variable) */ ldata = data + 8; out_format_count = 0; for (i = 0; i < NumFormats; i++) { size = 18 + GET_UINT16(ldata, 16); if (wave_in_format_supported(callback->device_data, ldata, size)) { /* Store the agreed format in the corresponding index */ callback->formats_data[out_format_count] = (char *) malloc(size); memcpy(callback->formats_data[out_format_count], ldata, size); /* Put the format to output buffer */ memcpy(lout_formats, ldata, size); lout_formats += size; out_format_count++; } ldata += size; } callback->formats_count = out_format_count; audin_send_incoming_data_pdu(pChannelCallback); /* cbSizeFormatsPacket: the size of the entire PDU minus the size of ExtraData */ size = lout_formats - out_data; SET_UINT8(out_data, 0, MSG_SNDIN_FORMATS); SET_UINT32(out_data, 1, out_format_count); SET_UINT32(out_data, 5, size); error = callback->channel->Write(callback->channel, size, out_data, NULL); free(out_data); return error; }
static int cache_glob_node_lookup_suffix (XdgMimeCache *cache, xdg_uint32_t n_entries, xdg_uint32_t offset, const char *suffix, int ignore_case, const char *mime_types[], int n_mime_types) { xdg_unichar_t character; xdg_unichar_t match_char; xdg_uint32_t mimetype_offset; xdg_uint32_t n_children; xdg_uint32_t child_offset; int min, max, mid, n, i; character = _xdg_utf8_to_ucs4 (suffix); if (ignore_case) character = _xdg_ucs4_to_lower (character); min = 0; max = n_entries - 1; while (max >= min) { mid = (min + max) / 2; match_char = GET_UINT32 (cache->buffer, offset + 16 * mid); if (match_char < character) min = mid + 1; else if (match_char > character) max = mid - 1; else { suffix = _xdg_utf8_next_char (suffix); if (*suffix == '\0') { mimetype_offset = GET_UINT32 (cache->buffer, offset + 16 * mid + 4); n = 0; if (cache->buffer[mimetype_offset]) mime_types[n++] = cache->buffer + mimetype_offset; n_children = GET_UINT32 (cache->buffer, offset + 16 * mid + 8); child_offset = GET_UINT32 (cache->buffer, offset + 16 * mid + 12); i = 0; while (n < n_mime_types && i < n_children) { match_char = GET_UINT32 (cache->buffer, child_offset + 16 * i); mimetype_offset = GET_UINT32 (cache->buffer, offset + 16 * i + 4); if (match_char != 0) break; mime_types[n++] = cache->buffer + mimetype_offset; i++; } return n; } else { n_children = GET_UINT32 (cache->buffer, offset + 16 * mid + 8); child_offset = GET_UINT32 (cache->buffer, offset + 16 * mid + 12); return cache_glob_node_lookup_suffix (cache, n_children, child_offset, suffix, ignore_case, mime_types, n_mime_types); } } } return 0; }
int doWrite(nitf_ImageSegment* segment, nitf_ImageSource *imgSrc, nitf_IOHandle output_io, nitf_ImageIO* ioClone) { nitf_Error error; nitf_Uint8** user; nitf_Uint32 nBits, nBands, xBands, nRows, nColumns, row; size_t rowSize; int band; NITF_BOOL success; /* Used in GET macros */ nitf_BandSource *bandSrc; /* Current band source object */ nitf_ImageSource *imgSrcTmp; GET_UINT32(segment->subheader->numBitsPerPixel, &nBits, &error); GET_UINT32(segment->subheader->numImageBands, &nBands, &error); GET_UINT32(segment->subheader->numMultispectralImageBands, &xBands, &error); nBands += xBands; GET_UINT32(segment->subheader->numRows, &nRows, &error); GET_UINT32(segment->subheader->numCols, &nColumns, &error); rowSize = nColumns * NITF_NBPP_TO_BYTES(nBits); /* Allocate buffers */ user = (nitf_Uint8 **)malloc(8 * nBands); assert(user); for (band = 0; band < nBands; band++) { user[band] = (nitf_Uint8*)malloc(rowSize); assert(user[band]); } /* setup for write */ nitf_ImageIO_writeSequential(segment->imageIO, output_io, &error); /* loop over the rows */ for (row = 0; row < nRows; ++row) { imgSrcTmp = imgSrc; /* set the band pointer */ for (band = 0; band < nBands; ++band) { bandSrc = nitf_ImageSource_getBand(imgSrcTmp, band, &error); if (bandSrc == NULL) return(0); (*(bandSrc->iface->read))(bandSrc->data, (char*)user[band], (size_t) rowSize, &error); } /* write the row */ if (!nitf_ImageIO_writeRows(segment->imageIO, output_io, 1, user, &error)) { return(0); } } /* done writing */ if (!nitf_ImageIO_writeDone(segment->imageIO, output_io, &error)) { return(0); } free(user); return(1); CATCH_ERROR: return(0); /* Needed for the GET macros */ }
void sha1_handle(unsigned int *state, const unsigned char data[64]) { unsigned int temp, W[16], A, B, C, D, E; GET_UINT32(W[ 0], data, 0); GET_UINT32(W[ 1], data, 4); GET_UINT32(W[ 2], data, 8); GET_UINT32(W[ 3], data, 12); GET_UINT32(W[ 4], data, 16); GET_UINT32(W[ 5], data, 20); GET_UINT32(W[ 6], data, 24); GET_UINT32(W[ 7], data, 28); GET_UINT32(W[ 8], data, 32); GET_UINT32(W[ 9], data, 36); GET_UINT32(W[10], data, 40); GET_UINT32(W[11], data, 44); GET_UINT32(W[12], data, 48); GET_UINT32(W[13], data, 52); GET_UINT32(W[14], data, 56); GET_UINT32(W[15], data, 60); #define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) #define R(t) \ ( \ temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \ W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \ ( W[t & 0x0F] = S(temp,1) ) \ ) #define P(a, b, c, d, e, x) \ { \ e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \ } A = state[0]; B = state[1]; C = state[2]; D = state[3]; E = state[4]; #define F(x, y, z) (z ^ (x & (y ^ z))) #define K 0x5A827999 P(A, B, C, D, E, W[ 0]); P(E, A, B, C, D, W[ 1]); P(D, E, A, B, C, W[ 2]); P(C, D, E, A, B, W[ 3]); P(B, C, D, E, A, W[ 4]); P(A, B, C, D, E, W[ 5]); P(E, A, B, C, D, W[ 6]); P(D, E, A, B, C, W[ 7]); P(C, D, E, A, B, W[ 8]); P(B, C, D, E, A, W[ 9]); P(A, B, C, D, E, W[10]); P(E, A, B, C, D, W[11]); P(D, E, A, B, C, W[12]); P(C, D, E, A, B, W[13]); P(B, C, D, E, A, W[14]); P(A, B, C, D, E, W[15]); P(E, A, B, C, D, R(16)); P(D, E, A, B, C, R(17)); P(C, D, E, A, B, R(18)); P(B, C, D, E, A, R(19)); #undef K #undef F #define F(x, y, z) (x ^ y ^ z) #define K 0x6ED9EBA1 P(A, B, C, D, E, R(20)); P(E, A, B, C, D, R(21)); P(D, E, A, B, C, R(22)); P(C, D, E, A, B, R(23)); P(B, C, D, E, A, R(24)); P(A, B, C, D, E, R(25)); P(E, A, B, C, D, R(26)); P(D, E, A, B, C, R(27)); P(C, D, E, A, B, R(28)); P(B, C, D, E, A, R(29)); P(A, B, C, D, E, R(30)); P(E, A, B, C, D, R(31)); P(D, E, A, B, C, R(32)); P(C, D, E, A, B, R(33)); P(B, C, D, E, A, R(34)); P(A, B, C, D, E, R(35)); P(E, A, B, C, D, R(36)); P(D, E, A, B, C, R(37)); P(C, D, E, A, B, R(38)); P(B, C, D, E, A, R(39)); #undef K #undef F #define F(x,y,z) ((x & y) | (z & (x | y))) #define K 0x8F1BBCDC P(A, B, C, D, E, R(40)); P(E, A, B, C, D, R(41)); P(D, E, A, B, C, R(42)); P(C, D, E, A, B, R(43)); P(B, C, D, E, A, R(44)); P(A, B, C, D, E, R(45)); P(E, A, B, C, D, R(46)); P(D, E, A, B, C, R(47)); P(C, D, E, A, B, R(48)); P(B, C, D, E, A, R(49)); P(A, B, C, D, E, R(50)); P(E, A, B, C, D, R(51)); P(D, E, A, B, C, R(52)); P(C, D, E, A, B, R(53)); P(B, C, D, E, A, R(54)); P(A, B, C, D, E, R(55)); P(E, A, B, C, D, R(56)); P(D, E, A, B, C, R(57)); P(C, D, E, A, B, R(58)); P(B, C, D, E, A, R(59)); #undef K #undef F #define F(x, y, z) (x ^ y ^ z) #define K 0xCA62C1D6 P(A, B, C, D, E, R(60)); P(E, A, B, C, D, R(61)); P(D, E, A, B, C, R(62)); P(C, D, E, A, B, R(63)); P(B, C, D, E, A, R(64)); P(A, B, C, D, E, R(65)); P(E, A, B, C, D, R(66)); P(D, E, A, B, C, R(67)); P(C, D, E, A, B, R(68)); P(B, C, D, E, A, R(69)); P(A, B, C, D, E, R(70)); P(E, A, B, C, D, R(71)); P(D, E, A, B, C, R(72)); P(C, D, E, A, B, R(73)); P(B, C, D, E, A, R(74)); P(A, B, C, D, E, R(75)); P(E, A, B, C, D, R(76)); P(D, E, A, B, C, R(77)); P(C, D, E, A, B, R(78)); P(B, C, D, E, A, R(79)); #undef K #undef F state[0] += A; state[1] += B; state[2] += C; state[3] += D; state[4] += E; }
PCSC_API LONG SCardListReaders(SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders) { char* msg; char* reader_names; int reader_names_index; int code; int bytes; int num_readers; int status; int offset; int index; int bytes_groups; int val; int llen; char reader[100]; LLOGLN(10, ("SCardListReaders:")); LLOGLN(10, ("SCardListReaders: mszGroups %s", mszGroups)); LLOGLN(10, ("SCardListReaders: *pcchReaders %d", (int)*pcchReaders)); if (g_sck == -1) { LLOGLN(0, ("SCardListReaders: error, not connected")); return SCARD_F_INTERNAL_ERROR; } if ((mszGroups == NULL) && (mszReaders == NULL)) { *pcchReaders = 0; } msg = (char *) malloc(8192); offset = 0; SET_UINT32(msg, offset, hContext); offset += 4; bytes_groups = 0; if (mszGroups != 0) { bytes_groups = strlen(mszGroups); } SET_UINT32(msg, offset, bytes_groups); offset += 4; memcpy(msg + offset, mszGroups, bytes_groups); offset += bytes_groups; val = *pcchReaders; SET_UINT32(msg, offset, val); offset += 4; if (send_message(SCARD_LIST_READERS, msg, offset) != 0) { LLOGLN(0, ("SCardListReaders: error, send_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } bytes = 8192; code = SCARD_LIST_READERS; if (get_message(&code, msg, &bytes) != 0) { LLOGLN(0, ("SCardListReaders: error, get_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } if (code != SCARD_LIST_READERS) { LLOGLN(0, ("SCardListReaders: error, bad code")); free(msg); return SCARD_F_INTERNAL_ERROR; } offset = 0; llen = GET_UINT32(msg, offset); offset += 4; num_readers = GET_UINT32(msg, offset); offset += 4; LLOGLN(10, ("SCardListReaders: mszReaders %p pcchReaders %p num_readers %d", mszReaders, pcchReaders, num_readers)); reader_names = (char *) malloc(8192); reader_names_index = 0; for (index = 0; index < num_readers; index++) { memcpy(reader, msg + offset, 100); bytes = strlen(reader); memcpy(reader_names + reader_names_index, reader, bytes); reader_names_index += bytes; reader_names[reader_names_index] = 0; reader_names_index++; offset += 100; LLOGLN(10, ("SCardListReaders: readername %s", reader)); } reader_names[reader_names_index] = 0; reader_names_index++; status = GET_UINT32(msg, offset); LLOGLN(10, ("SCardListReaders: status 0x%8.8x", status)); offset += 4; if (mszReaders == 0) { reader_names_index = llen / 2; } if (pcchReaders != 0) { *pcchReaders = reader_names_index; } if (mszReaders != 0) { memcpy(mszReaders, reader_names, reader_names_index); } free(msg); free(reader_names); return status; }
/* called by worker thread receives a list of server supported formats and returns a list of client supported formats */ static int thread_process_message_formats(rdpsndPlugin * plugin, char * data, int data_size) { int index; int format_count; int out_format_count; int out_format_size; int size; int flags; int version; char * ldata; char * out_data; char * out_formats; char * lout_formats; uint32 error; /* skip: dwFlags (4 bytes), dwVolume (4 bytes), dwPitch (4 bytes), wDGramPort (2 bytes) */ format_count = GET_UINT16(data, 14); /* wNumberOfFormats */ if ((format_count < 1) || (format_count > 1000)) { LLOGLN(0, ("thread_process_message_formats: bad format_count %d", format_count)); return 1; } plugin->cBlockNo = GET_UINT8(data, 16); /* cLastBlockConfirmed */ version = GET_UINT16(data, 17); /* wVersion */ if (version < 2) { LLOGLN(0, ("thread_process_message_formats: warning, old server")); } LLOGLN(0, ("thread_process_message_formats: version %d", version)); /* skip: bPad (1 byte) */ /* setup output buffer */ size = 32 + data_size; out_data = (char *) malloc(size); out_formats = out_data + 24; lout_formats = out_formats; /* remainder is sndFormats (variable) */ ldata = data + 20; out_format_count = 0; for (index = 0; index < format_count; index++, ldata += size) { size = 18 + GET_UINT16(ldata, 16); if (plugin->fixed_format > 0 && plugin->fixed_format != GET_UINT16(ldata, 0)) continue; if (plugin->fixed_channel > 0 && plugin->fixed_channel != GET_UINT16(ldata, 2)) continue; if (plugin->fixed_rate > 0 && plugin->fixed_rate != GET_UINT32(ldata, 4)) continue; if (plugin->device_plugin && plugin->device_plugin->format_supported(plugin->device_plugin, ldata, size)) { memcpy(lout_formats, ldata, size); lout_formats += size; out_format_count++; } } out_format_size = (int) (lout_formats - out_formats); if ((out_format_size > 0) && (out_format_count > 0)) { plugin->supported_formats = (char *) malloc(out_format_size); memcpy(plugin->supported_formats, out_formats, out_format_size); plugin->supported_formats_size = out_format_size; } else { LLOGLN(0, ("thread_process_message_formats: error, " "no formats supported")); } size = 24 + out_format_size; SET_UINT8(out_data, 0, SNDC_FORMATS); /* Header (4 bytes) */ SET_UINT8(out_data, 1, 0); SET_UINT16(out_data, 2, size - 4); flags = TSSNDCAPS_ALIVE | TSSNDCAPS_VOLUME; SET_UINT32(out_data, 4, flags); /* dwFlags */ SET_UINT32(out_data, 8, 0xffffffff); /* dwVolume */ SET_UINT32(out_data, 12, 0); /* dwPitch */ SET_UINT16(out_data, 16, 0); /* wDGramPort */ SET_UINT16(out_data, 18, out_format_count); /* wNumberOfFormats */ SET_UINT8(out_data, 20, 0); /* cLastBlockConfirmed */ SET_UINT16(out_data, 21, 6); /* wVersion */ SET_UINT8(out_data, 23, 0); /* bPad */ error = plugin->ep.pVirtualChannelWrite(plugin->open_handle, out_data, size, out_data); if (error != CHANNEL_RC_OK) { LLOGLN(0, ("thread_process_message_formats: " "VirtualChannelWrite " "failed %d", error)); return 1; } if (version >= 6) { size = 8; out_data = (char *) malloc(size); SET_UINT8(out_data, 0, SNDC_QUALITYMODE); /* Header (4 bytes) */ SET_UINT8(out_data, 1, 0); SET_UINT16(out_data, 2, size - 4); SET_UINT16(out_data, 4, 2); /* HIGH_QUALITY */ SET_UINT16(out_data, 6, 0); /* Reserved (2 bytes) */ error = plugin->ep.pVirtualChannelWrite(plugin->open_handle, out_data, size, out_data); if (error != CHANNEL_RC_OK) { LLOGLN(0, ("thread_process_message_formats: " "VirtualChannelWrite " "failed %d", error)); return 1; } } return 0; }
static int get_message(int *code, char *data, int *bytes) { char header[8]; int max_bytes; int error; int recv_rv; int max; int lcode; struct timeval time; fd_set rd_set; LLOGLN(10, ("get_message:")); max = g_sck + 1; while (1) { LLOGLN(10, ("get_message: loop")); time.tv_sec = 1; time.tv_usec = 0; FD_ZERO(&rd_set); FD_SET(((unsigned int)g_sck), &rd_set); error = select(max, &rd_set, 0, 0, &time); if (error == 1) { pthread_mutex_lock(&g_mutex); time.tv_sec = 0; time.tv_usec = 0; FD_ZERO(&rd_set); FD_SET(((unsigned int)g_sck), &rd_set); error = select(max, &rd_set, 0, 0, &time); if (error == 1) { /* just take a look at the next message */ recv_rv = recv(g_sck, header, 8, MSG_PEEK); if (recv_rv == 8) { lcode = GET_UINT32(header, 4); if (lcode == *code) { /* still have mutex lock */ break; } else { LLOGLN(10, ("get_message: lcode %d *code %d", lcode, *code)); } } else if (recv_rv == 0) { pthread_mutex_unlock(&g_mutex); LLOGLN(0, ("get_message: recv_rv 0, disconnect")); return 1; } else { LLOGLN(10, ("get_message: recv_rv %d", recv_rv)); } } else { LLOGLN(10, ("get_message: select return %d", error)); } pthread_mutex_unlock(&g_mutex); usleep(1000); } } if (recv(g_sck, header, 8, 0) != 8) { pthread_mutex_unlock(&g_mutex); return 1; } max_bytes = *bytes; *bytes = GET_UINT32(header, 0); *code = GET_UINT32(header, 4); if (*bytes > max_bytes) { pthread_mutex_unlock(&g_mutex); return 1; } if (recv(g_sck, data, *bytes, 0) != *bytes) { pthread_mutex_unlock(&g_mutex); return 1; } pthread_mutex_unlock(&g_mutex); return 0; }
int s3g_command_read_ext(s3g_context_t *ctx, s3g_command_t *cmd, unsigned char *buf, size_t maxbuf, size_t *buflen) { unsigned char *buf0 = buf; ssize_t bytes_expected, bytes_read; s3g_command_info_t *ct; s3g_command_t dummy; foo_16_t f16; foo_32_t f32; int iret; uint8_t ui8arg; iret = -1; if (buflen) *buflen = 0; // We have to have a read context // We don't need a command context to return the command in if (!ctx || !buf || maxbuf == 0) { fprintf(stderr, "s3g_command_get(%d): Invalid call; ctx=%p, buf=%p, " "maxbuf=%lu\n", __LINE__, (void *)ctx, (void *)buf, maxbuf); errno = EINVAL; return(-1); } else if (!ctx->read) { fprintf(stderr, "s3g_command_get(%d): Invalid context; " "ctx->read=NULL\n", __LINE__); errno = EINVAL; return(-1); } else if (!buf || maxbuf == 0) { fprintf(stderr, "s3g_command_get(%d): Invalid context; " "ctx->read=NULL\n", __LINE__); errno = EINVAL; return(-1); } // Initialize command table s3g_init(); if (1 != (bytes_expected = (*ctx->read)(ctx->r_ctx, buf0, maxbuf, 1))) { // End of file condition? if (bytes_expected == 0) return(1); // EOF fprintf(stderr, "s3g_command_get(%d): Error while reading from the s3g file; " "%s (%d)\n", __LINE__, strerror(errno), errno); return(-1); } ct = command_table + buf0[0]; // &command_table[buf0[0]] buf += 1; maxbuf -= 1; if (!cmd) cmd = &dummy; cmd->cmd_id = ct->cmd_id; cmd->cmd_desc = ct->cmd_desc; cmd->cmd_len = ct->cmd_len; cmd->cmd_raw_len = 0; if (ct->cmd_desc == NULL) { fprintf(stderr, "s3g_command_get(%d): Unrecognized command, %d\n", __LINE__, buf0[0]); goto done; } #define GET_INT32(v) \ if (maxbuf < 4) goto trunc; \ if (4 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 4))) \ goto io_error; \ memcpy(&f32.u.c, buf, 4); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f32.u.i #define GET_UINT32(v) \ if (maxbuf < 4) goto trunc; \ if (4 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 4))) \ goto io_error; \ memcpy(&f32.u.c, buf, 4); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f32.u.u #define GET_FLOAT32(v) \ if (maxbuf < 4) goto trunc; \ if (4 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 4))) \ goto io_error; \ memcpy(&f32.u.c, buf, 4); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f32.u.f; #define GET_UINT8(v) \ if (maxbuf < 1) goto trunc; \ if (1 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 1))) \ goto io_error; \ ui8arg = buf[0]; \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = ui8arg #define GET_INT16(v) \ if (maxbuf < 2) goto trunc; \ if (2 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 2))) \ goto io_error; \ memcpy(&f16.u.c, buf, 2); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f16.u.i #define GET_UINT16(v) \ if (maxbuf < 2) goto trunc; \ if (2 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 2))) \ goto io_error; \ memcpy(&f16.u.c, buf, 2); \ buf += bytes_read; \ maxbuf -= bytes_read; \ cmd->t.v = f16.u.u #define ZERO(v,c) cmd->t.v = (c)0 switch(cmd->cmd_id) { case HOST_CMD_DELAY : GET_UINT32(delay.millis); break; case HOST_CMD_FIND_AXES_MINIMUM : case HOST_CMD_FIND_AXES_MAXIMUM : GET_UINT8(find_axes_minmax.flags); GET_UINT32(find_axes_minmax.feedrate); GET_UINT16(find_axes_minmax.timeout); break; case HOST_CMD_WAIT_FOR_TOOL : GET_UINT8(wait_for_tool.index); GET_UINT16(wait_for_tool.ping_delay); GET_UINT16(wait_for_tool.timeout); break; case HOST_CMD_WAIT_FOR_PLATFORM : GET_UINT8(wait_for_platform.index); GET_UINT16(wait_for_platform.ping_delay); GET_UINT16(wait_for_platform.timeout); break; case HOST_CMD_STORE_HOME_POSITION : GET_UINT8(store_home_position.axes); break; case HOST_CMD_RECALL_HOME_POSITION : GET_UINT8(recall_home_position.axes); break; default : // Just read the data bytes_expected = (ssize_t)(ct->cmd_len & 0x7fffffff); if ((bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, ct->cmd_len)) != bytes_expected) goto io_error; buf += bytes_read; maxbuf -= bytes_read; break; case HOST_CMD_TOOL_COMMAND : // This command is VERY MBI specific if ((ssize_t)3 != (*ctx->read)(ctx->r_ctx, buf, maxbuf, 3)) goto io_error; if (cmd) cmd->cmd_len = (size_t)buf[2]; cmd->t.tool.subcmd_id = buf[1]; cmd->t.tool.index = buf[0]; cmd->t.tool.subcmd_len = bytes_expected = (ssize_t)buf[2]; if ((bytes_read = (*ctx->read)(ctx->r_ctx, buf + 3, maxbuf - 3, (size_t)buf[2])) != bytes_expected) goto io_error; if (cmd->t.tool.subcmd_len == 1) cmd->t.tool.subcmd_value = (uint16_t)buf[3]; else if (cmd->t.tool.subcmd_len > 1) memcpy((void *)&cmd->t.tool.subcmd_value, buf + 3, sizeof(uint16_t)); else cmd->t.tool.subcmd_value = 0; maxbuf -= 3 + bytes_read; buf += 3 + bytes_read; cmd->t.tool.subcmd_desc = tool_command_table[cmd->t.tool.subcmd_id].cmd_desc; if (cmd->t.tool.subcmd_desc == NULL) cmd->t.tool.subcmd_desc = "unknown tool subcommand"; break; case HOST_CMD_SET_POSITION_EXT : // x4, y4, z4, a4, b4 = 20 bytes GET_INT32(set_position_ext.x); GET_INT32(set_position_ext.y); GET_INT32(set_position_ext.z); GET_INT32(set_position_ext.a); GET_INT32(set_position_ext.b); break; case HOST_CMD_QUEUE_POINT_EXT : // x4, y4, z4, a4, b4, dda4 = 24 bytes GET_INT32(queue_point_ext.x); GET_INT32(queue_point_ext.y); GET_INT32(queue_point_ext.z); GET_INT32(queue_point_ext.a); GET_INT32(queue_point_ext.b); GET_INT32(queue_point_ext.dda); ZERO(queue_point_ext.dummy_rel, uint8_t); ZERO(queue_point_ext.dummy_distance, float); ZERO(queue_point_ext.dummy_feedrate_mult_64, uint16_t); break; case HOST_CMD_QUEUE_POINT_NEW : // x4, y4, z4, a4, b4, us4, relative = 25 bytes GET_INT32(queue_point_new.x); GET_INT32(queue_point_new.y); GET_INT32(queue_point_new.z); GET_INT32(queue_point_new.a); GET_INT32(queue_point_new.b); GET_INT32(queue_point_new.us); GET_UINT8(queue_point_new.rel); ZERO(queue_point_ext.dummy_distance, float); ZERO(queue_point_ext.dummy_feedrate_mult_64, uint16_t); break; case HOST_CMD_QUEUE_POINT_NEW_EXT : // x4, y4, z4, a4, b4, dda_rate4, relative, distance 4, feedrate_mult64 2 = 31 bytes GET_INT32(queue_point_new_ext.x); GET_INT32(queue_point_new_ext.y); GET_INT32(queue_point_new_ext.z); GET_INT32(queue_point_new_ext.a); GET_INT32(queue_point_new_ext.b); GET_INT32(queue_point_new_ext.dda_rate); GET_UINT8(queue_point_new_ext.rel); GET_FLOAT32(queue_point_new_ext.distance); GET_INT16(queue_point_new_ext.feedrate_mult_64); break; case HOST_CMD_SET_POT_VALUE : GET_UINT8(digi_pot.axis); GET_UINT8(digi_pot.value); break; case HOST_CMD_SET_RGB_LED : GET_UINT8(rgb_led.red); GET_UINT8(rgb_led.green); GET_UINT8(rgb_led.blue); GET_UINT8(rgb_led.blink_rate); GET_UINT8(rgb_led.effect); break; case HOST_CMD_SET_BEEP : GET_UINT16(beep.frequency); GET_UINT16(beep.duration); GET_UINT8(beep.effect); break; case HOST_CMD_PAUSE_FOR_BUTTON : GET_UINT8(button_pause.mask); GET_UINT16(button_pause.timeout); GET_UINT8(button_pause.timeout_behavior); break; case HOST_CMD_DISPLAY_MESSAGE : GET_UINT8(display_message.options); GET_UINT8(display_message.x); GET_UINT8(display_message.y); GET_UINT8(display_message.timeout); cmd->t.display_message.message_len = 0; if (maxbuf < 1) goto trunc; for (;;) { unsigned char uc; if (1 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 1))) goto io_error; uc = buf[0]; ++buf; --maxbuf; if (uc == '\0') break; if (cmd->t.display_message.message_len < (sizeof(cmd->t.display_message.message) - 1)) cmd->t.display_message.message[cmd->t.display_message.message_len++] = uc; if (maxbuf < 1) goto trunc; } cmd->t.display_message.message[cmd->t.display_message.message_len] = '\0'; break; case HOST_CMD_SET_BUILD_PERCENT : GET_UINT8(build_percentage.percentage); GET_UINT8(build_percentage.reserved); break; case HOST_CMD_QUEUE_SONG : GET_UINT8(queue_song.song_id); break; case HOST_CMD_RESET_TO_FACTORY : GET_UINT8(factory_reset.options); break; case HOST_CMD_BUILD_START_NOTIFICATION : GET_INT32(build_start.steps); cmd->t.build_start.message_len = 0; if (maxbuf < 1) goto trunc; for (;;) { unsigned char uc; if (1 != (bytes_read = (*ctx->read)(ctx->r_ctx, buf, maxbuf, 1))) goto io_error; uc = buf[0]; ++buf; --maxbuf; if (uc == '\0') break; if (cmd->t.build_start.message_len < (sizeof(cmd->t.build_start.message) - 1)) cmd->t.build_start.message[cmd->t.build_start.message_len++] = uc; } cmd->t.build_start.message[cmd->t.build_start.message_len] = '\0'; break; case HOST_CMD_BUILD_END_NOTIFICATION : GET_UINT8(build_end.flags); break; case HOST_CMD_CHANGE_TOOL : GET_UINT8(change_tool.index); break; case HOST_CMD_ENABLE_AXES : GET_UINT8(enable_axes.axes); break; case HOST_CMD_SET_ACCELERATION_TOGGLE: GET_UINT8(set_segment_acceleration.s); break; case HOST_CMD_STREAM_VERSION: GET_UINT8(x3g_version.version_high); GET_UINT8(x3g_version.version_low); GET_UINT8(x3g_version.reserved1); GET_UINT32(x3g_version.reserved2); GET_UINT16(x3g_version.bot_type); GET_UINT16(x3g_version.reserved3); GET_UINT32(x3g_version.reserved4); GET_UINT32(x3g_version.reserved5); GET_UINT8(x3g_version.reserved6); break; } #undef ZERO #undef GET_UINT8 #undef GET_INT32 iret = 0; goto done; io_error: fprintf(stderr, "s3g_command_get(%d): Error while reading from the s3g file; " "%s (%d)\n", __LINE__, strerror(errno), errno); iret = -1; goto done; trunc: fprintf(stderr, "s3g_command_get(%d): Caller supplied read buffer is too small", __LINE__); iret = -1; done: cmd->cmd_raw_len = (size_t)(buf - buf0); if (buflen) *buflen = cmd->cmd_raw_len; return(iret); }
PCSC_API LONG SCardConnect(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol) { char msg[256]; int code; int bytes; int status; int offset; LLOGLN(10, ("SCardConnect:")); LLOGLN(10, ("SCardConnect: hContext 0x%8.8x szReader %s dwShareMode %d " "dwPreferredProtocols %d", (int)hContext, szReader, (int)dwShareMode, (int)dwPreferredProtocols)); if (g_sck == -1) { LLOGLN(0, ("SCardConnect: error, not connected")); return SCARD_F_INTERNAL_ERROR; } offset = 0; SET_UINT32(msg, offset, hContext); offset += 4; bytes = strlen(szReader); if (bytes > 99) { LLOGLN(0, ("SCardConnect: error, name too long")); return SCARD_F_INTERNAL_ERROR; } memcpy(msg + offset, szReader, bytes); memset(msg + offset + bytes, 0, 100 - bytes); offset += 100; SET_UINT32(msg, offset, dwShareMode); offset += 4; SET_UINT32(msg, offset, dwPreferredProtocols); offset += 4; if (send_message(SCARD_CONNECT, msg, offset) != 0) { LLOGLN(0, ("SCardConnect: error, send_message")); return SCARD_F_INTERNAL_ERROR; } bytes = 256; code = SCARD_CONNECT; if (get_message(&code, msg, &bytes) != 0) { LLOGLN(0, ("SCardConnect: error, get_message")); return SCARD_F_INTERNAL_ERROR; } if (code != SCARD_CONNECT) { LLOGLN(0, ("SCardConnect: error, bad code")); return SCARD_F_INTERNAL_ERROR; } *phCard = GET_UINT32(msg, 0); *pdwActiveProtocol = GET_UINT32(msg, 4); status = GET_UINT32(msg, 8); LLOGLN(10, ("SCardConnect: got status 0x%8.8x hCard 0x%8.8x " "dwActiveProtocol %d", status, (int)*phCard, (int)*pdwActiveProtocol)); return status; }
void BigInt_ModExp ( uint8 *pu8X, uint16 u16XSize, uint8 *pu8E, uint16 u16ESize, uint8 *pu8M, uint16 u16MSize, uint8 *pu8R, uint16 u16RSize ) { uint32 u32Reg; uint8 au8Tmp[780] = {0}; uint32 u32XAddr = SHARED_MEM_BASE; uint32 u32MAddr; uint32 u32EAddr; uint32 u32RAddr; uint8 u8EMswBits = 32; uint32 u32Mprime = 0x7F; uint16 u16XSizeWords,u16ESizeWords; uint32 u32Exponent; u16XSizeWords = (u16XSize + 3) / 4; u16ESizeWords = (u16ESize + 3) / 4; u32MAddr = u32XAddr + (u16XSizeWords * 4); u32EAddr = u32MAddr + (u16XSizeWords * 4); u32RAddr = u32EAddr + (u16ESizeWords * 4); /* Reset the core. */ u32Reg = 0; u32Reg |= BIGINT_MISC_CTRL_CTL_RESET; u32Reg = nm_read_reg(BIGINT_MISC_CTRL); u32Reg &= ~BIGINT_MISC_CTRL_CTL_RESET; u32Reg = nm_read_reg(BIGINT_MISC_CTRL); nm_write_block(u32RAddr,au8Tmp, u16RSize); /* Write Input Operands to Chip Memory. */ /*------- X -------*/ FlipBuffer(pu8X,au8Tmp,u16XSize); nm_write_block(u32XAddr,au8Tmp,u16XSizeWords * 4); /*------- E -------*/ m2m_memset(au8Tmp, 0, sizeof(au8Tmp)); FlipBuffer(pu8E, au8Tmp, u16ESize); nm_write_block(u32EAddr, au8Tmp, u16ESizeWords * 4); u32Exponent = GET_UINT32(au8Tmp, (u16ESizeWords * 4) - 4); while((u32Exponent & NBIT31)== 0) { u32Exponent <<= 1; u8EMswBits --; } /*------- M -------*/ m2m_memset(au8Tmp, 0, sizeof(au8Tmp)); FlipBuffer(pu8M, au8Tmp, u16XSize); nm_write_block(u32MAddr, au8Tmp, u16XSizeWords * 4); /* Program the addresses of the input operands. */ nm_write_reg(BIGINT_ADDR_X, u32XAddr); nm_write_reg(BIGINT_ADDR_E, u32EAddr); nm_write_reg(BIGINT_ADDR_M, u32MAddr); nm_write_reg(BIGINT_ADDR_R, u32RAddr); /* Mprime. */ nm_write_reg(BIGINT_M_PRIME,u32Mprime); /* Length. */ u32Reg = (u16XSizeWords & 0xFF); u32Reg += ((u16ESizeWords & 0xFF) << 8); u32Reg += (u8EMswBits << 16); nm_write_reg(BIGINT_LENGTH,u32Reg); /* CTRL Register. */ u32Reg = nm_read_reg(BIGINT_MISC_CTRL); u32Reg ^= BIGINT_MISC_CTRL_CTL_START; u32Reg |= BIGINT_MISC_CTRL_CTL_FORCE_BARRETT; //u32Reg |= BIGINT_MISC_CTRL_CTL_M_PRIME_VALID; #if ENABLE_FLIPPING == 0 u32Reg |= BIGINT_MISC_CTRL_CTL_MSW_FIRST; #endif nm_write_reg(BIGINT_MISC_CTRL,u32Reg); /* Wait for computation to complete. */ while(1) { u32Reg = nm_read_reg(BIGINT_IRQ_STS); if(u32Reg & BIGINT_IRQ_STS_DONE) { break; } } nm_write_reg(BIGINT_IRQ_STS,0); m2m_memset(au8Tmp, 0, sizeof(au8Tmp)); nm_read_block(u32RAddr, au8Tmp, u16RSize); FlipBuffer(au8Tmp, pu8R, u16RSize); }
PCSC_API LONG SCardStatus(SCARDHANDLE hCard, LPSTR mszReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen) { char *msg; int code; int bytes; int status; int offset; int cchReaderLen; int to_copy; LLOGLN(10, ("SCardStatus:")); if (hCard == 0) { LLOGLN(10, ("SCardStatus: error, bad hCard")); return SCARD_F_INTERNAL_ERROR; } if (g_sck == -1) { LLOGLN(0, ("SCardStatus: error, not connected")); return SCARD_F_INTERNAL_ERROR; } LLOGLN(10, (" hCard 0x%8.8x", (int)hCard)); LLOGLN(10, (" cchReaderLen %d", (int)*pcchReaderLen)); LLOGLN(10, (" cbAtrLen %d", (int)*pcbAtrLen)); cchReaderLen = *pcchReaderLen; msg = (char *) malloc(8192); SET_UINT32(msg, 0, hCard); SET_UINT32(msg, 4, cchReaderLen); SET_UINT32(msg, 8, *pcbAtrLen); if (send_message(SCARD_STATUS, msg, 12) != 0) { LLOGLN(0, ("SCardStatus: error, send_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } bytes = 8192; code = SCARD_STATUS; if (get_message(&code, msg, &bytes) != 0) { LLOGLN(0, ("SCardStatus: error, get_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } if (code != SCARD_STATUS) { LLOGLN(0, ("SCardStatus: error, bad code")); free(msg); return SCARD_F_INTERNAL_ERROR; } LLOGLN(10, ("SCardStatus: cchReaderLen in %d", (int)*pcchReaderLen)); offset = 0; *pcchReaderLen = GET_UINT32(msg, offset); LLOGLN(10, ("SCardStatus: cchReaderLen out %d", (int)*pcchReaderLen)); offset += 4; if (cchReaderLen > 0) { to_copy = cchReaderLen - 1; if (*pcchReaderLen < to_copy) { to_copy = *pcchReaderLen; } memcpy(mszReaderName, msg + offset, to_copy); mszReaderName[to_copy] = 0; } LLOGLN(10, ("SCardStatus: mszReaderName out %s", mszReaderName)); offset += *pcchReaderLen; *pdwState = GET_UINT32(msg, offset); if (*pdwState == 1) { *pdwState = 0x34; } LLOGLN(10, ("SCardStatus: dwState %d", (int)*pdwState)); offset += 4; *pdwProtocol = GET_UINT32(msg, offset); LLOGLN(10, ("SCardStatus: dwProtocol %d", (int)*pdwProtocol)); offset += 4; *pcbAtrLen = GET_UINT32(msg, offset); offset += 4; LLOGLN(10, ("SCardStatus: cbAtrLen %d", (int)*pcbAtrLen)); memcpy(pbAtr, msg + offset, *pcbAtrLen); offset += *pcbAtrLen; status = GET_UINT32(msg, offset); LLOGLN(10, ("SCardStatus: status %d", status)); offset += 4; free(msg); return status; }
void showFileHeader(nitf_FileHeader * header) { unsigned int i; nitf_Uint32 num; nitf_Error error; nitf_Uint32 len; nitf_Uint64 dataLen; NITF_BOOL success; SHOW_VAL(header->fileHeader); SHOW_VAL(header->fileVersion); SHOW_VAL(header->complianceLevel); SHOW_VAL(header->systemType); SHOW_VAL(header->originStationID); SHOW_VAL(header->fileDateTime); SHOW_VAL(header->fileTitle); SHOW_VAL(header->classification); SHOW_VAL(header->messageCopyNum); SHOW_VAL(header->messageNumCopies); SHOW_VAL(header->encrypted); SHOW_VAL(header->backgroundColor); SHOW_VAL(header->originatorName); SHOW_VAL(header->originatorPhone); SHOW_VAL(header->fileLength); SHOW_VAL(header->headerLength); /* Attention: If the classification is U, the security group */ /* section should be empty! For that reason, we wont print */ /* The security group for now */ SHOW_VAL(header->securityGroup->classificationSystem); SHOW_VAL(header->securityGroup->codewords); SHOW_VAL(header->securityGroup->controlAndHandling); SHOW_VAL(header->securityGroup->releasingInstructions); SHOW_VAL(header->securityGroup->declassificationType); SHOW_VAL(header->securityGroup->declassificationDate); SHOW_VAL(header->securityGroup->declassificationExemption); SHOW_VAL(header->securityGroup->downgrade); SHOW_VAL(header->securityGroup->downgradeDateTime); SHOW_VAL(header->securityGroup->classificationText); SHOW_VAL(header->securityGroup->classificationAuthorityType); SHOW_VAL(header->securityGroup->classificationAuthority); SHOW_VAL(header->securityGroup->classificationReason); SHOW_VAL(header->securityGroup->securitySourceDate); SHOW_VAL(header->securityGroup->securityControlNumber); GET_UINT32(header->numImages, &num, &error); printf("The number of IMAGES contained in this file [%ld]\n", (long)num); for (i = 0; i < num; i++) { GET_UINT32(header->imageInfo[i]->lengthSubheader, &len, &error); GET_UINT64(header->imageInfo[i]->lengthData, &dataLen, &error); printf("\tThe length of IMAGE subheader [%d]: %ld bytes\n", i, (long)len); printf("\tThe length of the IMAGE data: %llu bytes\n\n", dataLen); } return; CATCH_ERROR: printf("Error processing\n"); }
PCSC_API LONG SCardGetStatusChange(SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATE rgReaderStates, DWORD cReaders) { char *msg; const char *rname; int bytes; int code; int index; int offset; int str_len; int status; int dwCurrentState; int dwEventState; int cbAtr; char atr[36]; LLOGLN(10, ("SCardGetStatusChange:")); LLOGLN(10, (" dwTimeout %d cReaders %d", (int)dwTimeout, (int)cReaders)); if (g_sck == -1) { LLOGLN(0, ("SCardGetStatusChange: error, not connected")); return SCARD_F_INTERNAL_ERROR; } msg = (char *) malloc(8192); SET_UINT32(msg, 0, hContext); SET_UINT32(msg, 4, dwTimeout); SET_UINT32(msg, 8, cReaders); offset = 12; for (index = 0; index < cReaders; index++) { rgReaderStates[index].dwCurrentState &= ~2; rgReaderStates[index].dwEventState &= ~2; rname = rgReaderStates[index].szReader; if (strcmp(rname, "\\\\?PnP?\\Notification") == 0) { LLOGLN(10, (" \\\\?PnP?\\Notification present")); dwCurrentState = 0; dwEventState = 0; cbAtr = 0; memset(atr, 0, 36); } else { dwCurrentState = rgReaderStates[index].dwCurrentState; dwEventState = rgReaderStates[index].dwEventState; cbAtr = rgReaderStates[index].cbAtr; memset(atr, 0, 36); memcpy(atr, rgReaderStates[index].rgbAtr, 33); } str_len = strlen(rname); str_len = LMIN(str_len, 99); memset(msg + offset, 0, 100); memcpy(msg + offset, rname, str_len); LLOGLN(10, (" in szReader %s", rname)); offset += 100; LLOGLN(10, (" in dwCurrentState 0x%8.8x", dwCurrentState)); SET_UINT32(msg, offset, dwCurrentState); offset += 4; LLOGLN(10, (" in dwEventState 0x%8.8x", dwEventState)); SET_UINT32(msg, offset, dwEventState); offset += 4; LLOGLN(10, (" in cbAtr %d", cbAtr)); SET_UINT32(msg, offset, cbAtr); offset += 4; memcpy(msg + offset, atr, 36); offset += 36; } if (send_message(SCARD_GET_STATUS_CHANGE, msg, offset) != 0) { LLOGLN(0, ("SCardGetStatusChange: error, send_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } bytes = 8192; code = SCARD_GET_STATUS_CHANGE; if (get_message(&code, msg, &bytes) != 0) { LLOGLN(0, ("SCardGetStatusChange: error, get_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } if (code != SCARD_GET_STATUS_CHANGE) { LLOGLN(0, ("SCardGetStatusChange: error, bad code")); free(msg); return SCARD_F_INTERNAL_ERROR; } cReaders = GET_UINT32(msg, 0); offset = 4; LLOGLN(10, ("SCardGetStatusChange: got back cReaders %d", (int)cReaders)); for (index = 0; index < cReaders; index++) { rname = rgReaderStates[index].szReader; #if 1 if (strcmp(rname, "\\\\?PnP?\\Notification") == 0) { LLOGLN(10, (" out szReader %s", rgReaderStates[index].szReader)); dwCurrentState = GET_UINT32(msg, offset); rgReaderStates[index].dwCurrentState = dwCurrentState; offset += 4; LLOGLN(10, (" out dwCurrentState 0x%8.8x", dwCurrentState)); // disable PnP for now dwEventState = 4; // GET_UINT32(msg, offset); rgReaderStates[index].dwEventState = dwEventState; offset += 4; LLOGLN(10, (" out dwEventState 0x%8.8x", dwEventState)); cbAtr = GET_UINT32(msg, offset); rgReaderStates[index].cbAtr = cbAtr; offset += 4; LLOGLN(10, (" out cbAtr %d", cbAtr)); memcpy(rgReaderStates[index].rgbAtr, msg + offset, 33); offset += 36; } else #endif { LLOGLN(10, (" out szReader %s", rgReaderStates[index].szReader)); dwCurrentState = GET_UINT32(msg, offset); rgReaderStates[index].dwCurrentState = dwCurrentState; offset += 4; LLOGLN(10, (" out dwCurrentState 0x%8.8x", dwCurrentState)); dwEventState = GET_UINT32(msg, offset); rgReaderStates[index].dwEventState = dwEventState; offset += 4; LLOGLN(10, (" out dwEventState 0x%8.8x", dwEventState)); cbAtr = GET_UINT32(msg, offset); rgReaderStates[index].cbAtr = cbAtr; offset += 4; LLOGLN(10, (" out cbAtr %d", cbAtr)); memcpy(rgReaderStates[index].rgbAtr, msg + offset, 33); offset += 36; } } status = GET_UINT32(msg, offset); offset += 4; free(msg); return status; }
static uint32 serial_control(IRP * irp) { int flush_mask, purge_mask; uint32 result, modemstate; uint8 immediate; int size = 0, ret = RD_STATUS_SUCCESS; SERIAL_DEVICE_INFO *info = (SERIAL_DEVICE_INFO *) irp->dev->info; char *inbuf = irp->inputBuffer; char *outbuf = NULL; /* the server commands, we obbey */ switch (irp->ioControlCode) { case IOCTL_SERIAL_SET_BAUD_RATE: info->baud_rate = GET_UINT32(inbuf, 0); set_termios(info); LLOGLN(10, ("serial_ioctl -> SERIAL_SET_BAUD_RATE %d", info->baud_rate)); break; case IOCTL_SERIAL_GET_BAUD_RATE: size = 4; outbuf = malloc(size); SET_UINT32(outbuf, 0, info->baud_rate); LLOGLN(10, ("serial_ioctl -> SERIAL_GET_BAUD_RATE %d", info->baud_rate)); break; case IOCTL_SERIAL_SET_QUEUE_SIZE: info->queue_in_size = GET_UINT32(inbuf, 0); info->queue_out_size = GET_UINT32(inbuf, 4); LLOGLN(10, ("serial_ioctl -> SERIAL_SET_QUEUE_SIZE in %d out %d", info->queue_in_size, info->queue_out_size)); break; case IOCTL_SERIAL_SET_LINE_CONTROL: info->stop_bits = GET_UINT8(inbuf, 0); info->parity = GET_UINT8(inbuf, 1); info->word_length = GET_UINT8(inbuf, 2); set_termios(info); LLOGLN(10, ("serial_ioctl -> SERIAL_SET_LINE_CONTROL stop %d parity %d word %d", info->stop_bits, info->parity, info->word_length)); break; case IOCTL_SERIAL_GET_LINE_CONTROL: LLOGLN(10, ("serial_ioctl -> SERIAL_GET_LINE_CONTROL")); size = 3; outbuf = malloc(size); SET_UINT8(outbuf, 0, info->stop_bits); SET_UINT8(outbuf, 1, info->parity); SET_UINT8(outbuf, 2, info->word_length); break; case IOCTL_SERIAL_IMMEDIATE_CHAR: LLOGLN(10, ("serial_ioctl -> SERIAL_IMMEDIATE_CHAR")); immediate = GET_UINT8(inbuf, 0); serial_write_data(irp, &immediate, 1); break; case IOCTL_SERIAL_CONFIG_SIZE: LLOGLN(10, ("serial_ioctl -> SERIAL_CONFIG_SIZE")); size = 4; outbuf = malloc(size); SET_UINT32(outbuf, 0, 0); break; case IOCTL_SERIAL_GET_CHARS: LLOGLN(10, ("serial_ioctl -> SERIAL_GET_CHARS")); size = 6; outbuf = malloc(size); memcpy(outbuf, info->chars, size); break; case IOCTL_SERIAL_SET_CHARS: LLOGLN(10, ("serial_ioctl -> SERIAL_SET_CHARS")); memcpy(info->chars, inbuf, 6); set_termios(info); break; case IOCTL_SERIAL_GET_HANDFLOW: LLOGLN(10, ("serial_ioctl -> IOCTL_SERIAL_GET_HANDFLOW")); size = 16; outbuf = malloc(size); get_termios(info); SET_UINT32(outbuf, 0, info->control); SET_UINT32(outbuf, 4, info->xonoff); SET_UINT32(outbuf, 8, info->onlimit); SET_UINT32(outbuf, 12, info->offlimit); break; case IOCTL_SERIAL_SET_HANDFLOW: info->control = GET_UINT32(inbuf, 0); info->xonoff = GET_UINT32(inbuf, 4); info->onlimit = GET_UINT32(inbuf, 8); info->offlimit = GET_UINT32(inbuf, 12); LLOGLN(10, ("serial_ioctl -> IOCTL_SERIAL_SET_HANDFLOW %x %x %x %x", info->control, info->xonoff, info->onlimit, info->onlimit)); set_termios(info); break; case IOCTL_SERIAL_SET_TIMEOUTS: info->read_interval_timeout = GET_UINT32(inbuf, 0); info->read_total_timeout_multiplier = GET_UINT32(inbuf, 4); info->read_total_timeout_constant = GET_UINT32(inbuf, 8); info->write_total_timeout_multiplier = GET_UINT32(inbuf, 12); info->write_total_timeout_constant = GET_UINT32(inbuf, 16); /* http://www.codeproject.com/KB/system/chaiyasit_t.aspx, see 'ReadIntervalTimeout' section http://msdn.microsoft.com/en-us/library/ms885171.aspx */ if (info->read_interval_timeout == SERIAL_TIMEOUT_MAX) { info->read_interval_timeout = 0; info->read_total_timeout_multiplier = 0; } LLOGLN(10, ("serial_ioctl -> SERIAL_SET_TIMEOUTS read timeout %d %d %d", info->read_interval_timeout, info->read_total_timeout_multiplier, info->read_total_timeout_constant)); break; case IOCTL_SERIAL_GET_TIMEOUTS: LLOGLN(10, ("serial_ioctl -> SERIAL_GET_TIMEOUTS read timeout %d %d %d", info->read_interval_timeout, info->read_total_timeout_multiplier, info->read_total_timeout_constant)); size = 20; outbuf = malloc(size); SET_UINT32(outbuf, 0, info->read_interval_timeout); SET_UINT32(outbuf, 4, info->read_total_timeout_multiplier); SET_UINT32(outbuf, 8, info->read_total_timeout_constant); SET_UINT32(outbuf, 12, info->write_total_timeout_multiplier); SET_UINT32(outbuf, 16, info->write_total_timeout_constant); break; case IOCTL_SERIAL_GET_WAIT_MASK: LLOGLN(10, ("serial_ioctl -> SERIAL_GET_WAIT_MASK %X", info->wait_mask)); size = 4; outbuf = malloc(size); SET_UINT32(outbuf, 0, info->wait_mask); break; case IOCTL_SERIAL_SET_WAIT_MASK: info->wait_mask = GET_UINT32(inbuf, 0); LLOGLN(10, ("serial_ioctl -> SERIAL_SET_WAIT_MASK %X", info->wait_mask)); break; case IOCTL_SERIAL_SET_DTR: LLOGLN(10, ("serial_ioctl -> SERIAL_SET_DTR")); ioctl(info->file, TIOCMGET, &result); result |= TIOCM_DTR; ioctl(info->file, TIOCMSET, &result); info->dtr = 1; break; case IOCTL_SERIAL_CLR_DTR: LLOGLN(10, ("serial_ioctl -> SERIAL_CLR_DTR")); ioctl(info->file, TIOCMGET, &result); result &= ~TIOCM_DTR; ioctl(info->file, TIOCMSET, &result); info->dtr = 0; break; case IOCTL_SERIAL_SET_RTS: LLOGLN(10, ("serial_ioctl -> SERIAL_SET_RTS")); ioctl(info->file, TIOCMGET, &result); result |= TIOCM_RTS; ioctl(info->file, TIOCMSET, &result); info->rts = 1; break; case IOCTL_SERIAL_CLR_RTS: LLOGLN(10, ("serial_ioctl -> SERIAL_CLR_RTS")); ioctl(info->file, TIOCMGET, &result); result &= ~TIOCM_RTS; ioctl(info->file, TIOCMSET, &result); info->rts = 0; break; case IOCTL_SERIAL_GET_MODEMSTATUS: modemstate = 0; #ifdef TIOCMGET ioctl(info->file, TIOCMGET, &result); if (result & TIOCM_CTS) modemstate |= SERIAL_MS_CTS; if (result & TIOCM_DSR) modemstate |= SERIAL_MS_DSR; if (result & TIOCM_RNG) modemstate |= SERIAL_MS_RNG; if (result & TIOCM_CAR) modemstate |= SERIAL_MS_CAR; if (result & TIOCM_DTR) modemstate |= SERIAL_MS_DTR; if (result & TIOCM_RTS) modemstate |= SERIAL_MS_RTS; #endif LLOGLN(10, ("serial_ioctl -> SERIAL_GET_MODEMSTATUS %X", modemstate)); size = 4; outbuf = malloc(size); SET_UINT32(outbuf, 0, modemstate); break; case IOCTL_SERIAL_GET_COMMSTATUS: size = 18; outbuf = malloc(size); SET_UINT32(outbuf, 0, 0); /* Errors */ SET_UINT32(outbuf, 4, 0); /* Hold reasons */ result = 0; #ifdef TIOCINQ ioctl(info->file, TIOCINQ, &result); #endif SET_UINT32(outbuf, 8, result); /* Amount in in queue */ if (result) LLOGLN(10, ("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d", result)); result = 0; #ifdef TIOCOUTQ ioctl(info->file, TIOCOUTQ, &result); #endif SET_UINT32(outbuf, 12, result); /* Amount in out queue */ LLOGLN(10, ("serial_ioctl -> SERIAL_GET_COMMSTATUS out queue %d", result)); SET_UINT8(outbuf, 16, 0); /* EofReceived */ SET_UINT8(outbuf, 17, 0); /* WaitForImmediate */ break; case IOCTL_SERIAL_PURGE: purge_mask = GET_UINT32(inbuf, 0); LLOGLN(10, ("serial_ioctl -> SERIAL_PURGE purge_mask %X", purge_mask)); flush_mask = 0; if (purge_mask & SERIAL_PURGE_TXCLEAR) flush_mask |= TCOFLUSH; if (purge_mask & SERIAL_PURGE_RXCLEAR) flush_mask |= TCIFLUSH; if (flush_mask != 0) tcflush(info->file, flush_mask); if (purge_mask & SERIAL_PURGE_TXABORT) irp->abortIO |= RDPDR_ABORT_IO_WRITE; if(purge_mask & SERIAL_PURGE_RXABORT) irp->abortIO |= RDPDR_ABORT_IO_READ; break; case IOCTL_SERIAL_WAIT_ON_MASK: LLOGLN(10, ("serial_ioctl -> SERIAL_WAIT_ON_MASK %X", info->wait_mask)); info->event_pending = 1; size = 4; if (serial_get_event(irp, &result)) { outbuf = malloc(size); LLOGLN(10, ("WAIT end event = %x", result)); SET_UINT32(outbuf, 0, result); break; } ret = RD_STATUS_PENDING; break; case IOCTL_SERIAL_SET_BREAK_ON: LLOGLN(10, ("serial_ioctl -> SERIAL_SET_BREAK_ON")); tcsendbreak(info->file, 0); break; case IOCTL_SERIAL_RESET_DEVICE: LLOGLN(10, ("serial_ioctl -> SERIAL_RESET_DEVICE")); break; case IOCTL_SERIAL_SET_BREAK_OFF: LLOGLN(10, ("serial_ioctl -> SERIAL_SET_BREAK_OFF")); break; case IOCTL_SERIAL_SET_XOFF: LLOGLN(10, ("serial_ioctl -> SERIAL_SET_XOFF")); break; case IOCTL_SERIAL_SET_XON: LLOGLN(10, ("serial_ioctl -> SERIAL_SET_XON")); tcflow(info->file, TCION); break; default: LLOGLN(10, ("NOT FOUND IoControlCode SERIAL IOCTL %d", irp->ioControlCode)); return RD_STATUS_INVALID_PARAMETER; } irp->outputBuffer = outbuf; irp->outputBufferLength = size; return ret; }
PCSC_API LONG SCardControl(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned) { char *msg; int bytes; int code; int offset; int status = 0; LLOGLN(10, ("SCardControl:")); if (g_sck == -1) { LLOGLN(0, ("SCardControl: error, not connected")); return SCARD_F_INTERNAL_ERROR; } LLOGLN(10, (" hCard 0x%8.8x", (int)hCard)); LLOGLN(10, (" dwControlCode 0x%8.8x", (int)dwControlCode)); LLOGLN(10, (" cbSendLength %d", (int)cbSendLength)); LLOGLN(10, (" cbRecvLength %d", (int)cbRecvLength)); /* #define SCARD_CTL_CODE(code) (0x42000000 + (code)) control_code = (control_code & 0x3ffc) >> 2; control_code = SCARD_CTL_CODE(control_code); */ /* PCSC to Windows control code conversion */ dwControlCode = dwControlCode - 0x42000000; dwControlCode = dwControlCode << 2; dwControlCode = dwControlCode | (49 << 16); LLOGLN(10, (" MS dwControlCode 0x%8.8d", (int)dwControlCode)); msg = (char *) malloc(8192); offset = 0; SET_UINT32(msg, offset, hCard); offset += 4; SET_UINT32(msg, offset, dwControlCode); offset += 4; SET_UINT32(msg, offset, cbSendLength); offset += 4; memcpy(msg + offset, pbSendBuffer, cbSendLength); offset += cbSendLength; SET_UINT32(msg, offset, cbRecvLength); offset += 4; if (send_message(SCARD_CONTROL, msg, offset) != 0) { LLOGLN(0, ("SCardControl: error, send_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } bytes = 8192; code = SCARD_CONTROL; if (get_message(&code, msg, &bytes) != 0) { LLOGLN(0, ("SCardControl: error, get_message")); free(msg); return SCARD_F_INTERNAL_ERROR; } if (code != SCARD_CONTROL) { LLOGLN(0, ("SCardControl: error, bad code")); free(msg); return SCARD_F_INTERNAL_ERROR; } offset = 0; *lpBytesReturned = GET_UINT32(msg, offset); LLOGLN(10, (" cbRecvLength %d", (int)*lpBytesReturned)); offset += 4; memcpy(pbRecvBuffer, msg + offset, *lpBytesReturned); offset += *lpBytesReturned; status = GET_UINT32(msg, offset); free(msg); return status; }
int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) { unsigned char *p = message->options; unsigned char *end = message->options; /* Add size later for gcc-3 issue */ unsigned char option; unsigned char length; unsigned int len = 0; int i; int retval = -1; route_t *first_route = xmalloc (sizeof (route_t)); route_t *route = first_route; route_t *last_route = NULL; route_t *csr = NULL; end += sizeof (message->options); memset (first_route, 0, sizeof (route_t)); dhcp->address.s_addr = message->yiaddr; strcpy (dhcp->servername, message->servername); while (p < end) { option = *p++; if (!option) continue; length = *p++; if (p + length >= end) { retval = -1; goto eexit; } switch (option) { case DHCP_END: goto eexit; case DHCP_MESSAGETYPE: retval = (int) *p; break; #define GET_UINT32(_val) \ memcpy (&_val, p, sizeof (uint32_t)); #define GET_UINT32_H(_val) \ GET_UINT32 (_val); \ _val = ntohl (_val); case DHCP_ADDRESS: GET_UINT32 (dhcp->address.s_addr); break; case DHCP_NETMASK: GET_UINT32 (dhcp->netmask.s_addr); break; case DHCP_BROADCAST: GET_UINT32 (dhcp->broadcast.s_addr); break; case DHCP_SERVERIDENTIFIER: GET_UINT32 (dhcp->serveraddress.s_addr); break; case DHCP_LEASETIME: GET_UINT32_H (dhcp->leasetime); break; case DHCP_RENEWALTIME: GET_UINT32_H (dhcp->renewaltime); break; case DHCP_REBINDTIME: GET_UINT32_H (dhcp->rebindtime); break; case DHCP_MTU: GET_UINT32_H (dhcp->mtu); /* Minimum legal mtu is 68 */ if (dhcp->mtu > 0 && dhcp->mtu < 68) dhcp->mtu = 68; break; #undef GET_UINT32_H #undef GET_UINT32 #define GETSTR(_var) \ if (_var) free (_var); \ _var = xmalloc (length + 1); \ memcpy (_var, p, length); \ memset (_var + length, 0, 1); case DHCP_HOSTNAME: GETSTR (dhcp->hostname); break; case DHCP_DNSDOMAIN: GETSTR (dhcp->dnsdomain); break; case DHCP_MESSAGE: GETSTR (dhcp->message); break; case DHCP_ROOTPATH: GETSTR (dhcp->rootpath); break; case DHCP_NISDOMAIN: GETSTR (dhcp->nisdomain); break; #undef GETSTR #define GETADDR(_var) \ if (_var) free (_var); \ _var = xmalloc (sizeof (address_t)); \ dhcp_add_address (_var, p, length); case DHCP_DNSSERVER: GETADDR (dhcp->dnsservers); break; case DHCP_NTPSERVER: GETADDR (dhcp->ntpservers); break; case DHCP_NISSERVER: GETADDR (dhcp->nisservers); break; #undef GETADDR case DHCP_DNSSEARCH: if (dhcp->dnssearch) free (dhcp->dnssearch); if ((len = decode_search (p, length, NULL))) { dhcp->dnssearch = xmalloc (len); decode_search (p, length, dhcp->dnssearch); } break; case DHCP_CSR: csr = decodeCSR (p, length); break; case DHCP_STATICROUTE: for (i = 0; i < length; i += 8) { memcpy (&route->destination.s_addr, p + i, 4); memcpy (&route->gateway.s_addr, p + i + 4, 4); route->netmask.s_addr = getnetmask (route->destination.s_addr); last_route = route; route->next = xmalloc (sizeof (route_t)); route = route->next; memset (route, 0, sizeof (route_t)); } break; case DHCP_ROUTERS: for (i = 0; i < length; i += 4) { memcpy (&route->gateway.s_addr, p + i, 4); last_route = route; route->next = xmalloc (sizeof (route_t)); route = route->next; memset (route, 0, sizeof (route_t)); } break; default: logger (LOG_DEBUG, "no facility to parse DHCP code %u", option); break; } p += length; } eexit: /* Fill in any missing fields */ if (! dhcp->netmask.s_addr) dhcp->netmask.s_addr = getnetmask (dhcp->address.s_addr); if (! dhcp->broadcast.s_addr) dhcp->broadcast.s_addr = dhcp->address.s_addr | ~dhcp->netmask.s_addr; /* If we have classess static routes then we discard static routes and routers according to RFC 3442 */ if (csr) { dhcp->routes = csr; free_route (first_route); } else { dhcp->routes = first_route; if (last_route) { free (last_route->next); last_route->next = NULL; } else { free_route (dhcp->routes); dhcp->routes = NULL; } } return retval; }
uint32_t BmGetCounter(t_Handle h_Bm, e_BmInterModuleCounters counter, uint8_t bpid) { t_Bm *p_Bm = (t_Bm*)h_Bm; SANITY_CHECK_RETURN_VALUE(p_Bm, E_INVALID_HANDLE, 0); SANITY_CHECK_RETURN_VALUE(bpid < BM_MAX_NUM_OF_POOLS, E_INVALID_VALUE, 0); SANITY_CHECK_RETURN_VALUE((((p_Bm->guestId == NCSW_MASTER_ID) && p_Bm->p_BmRegs) || (p_Bm->guestId != NCSW_MASTER_ID)), E_INVALID_STATE, 0); if ((p_Bm->guestId == NCSW_MASTER_ID) || (!p_Bm->h_Session && p_Bm->p_BmRegs)) { switch(counter) { case(e_BM_IM_COUNTERS_POOL_CONTENT): return GET_UINT32(p_Bm->p_BmRegs->content[bpid]); case(e_BM_IM_COUNTERS_POOL_SW_DEPLETION): return GET_UINT32(p_Bm->p_BmRegs->sdcnt[bpid]); case(e_BM_IM_COUNTERS_POOL_HW_DEPLETION): return GET_UINT32(p_Bm->p_BmRegs->hdcnt[bpid]); case(e_BM_IM_COUNTERS_FBPR): return GET_UINT32(p_Bm->p_BmRegs->fbpr_fpc); default: break; } /* should never get here */ ASSERT_COND(FALSE); } else if (p_Bm->h_Session) { t_BmIpcMsg msg; t_BmIpcReply reply; t_BmIpcGetCounter ipcCounter; uint32_t replyLength; uint32_t count; t_Error errCode = E_OK; memset(&msg, 0, sizeof(t_BmIpcMsg)); memset(&reply, 0, sizeof(t_BmIpcReply)); ipcCounter.bpid = bpid; ipcCounter.enumId = (uint32_t)counter; msg.msgId = BM_GET_COUNTER; memcpy(msg.msgBody, &ipcCounter, sizeof(t_BmIpcGetCounter)); replyLength = sizeof(uint32_t) + sizeof(uint32_t); if ((errCode = XX_IpcSendMessage(p_Bm->h_Session, (uint8_t*)&msg, sizeof(msg.msgId) + sizeof(t_BmIpcGetCounter), (uint8_t*)&reply, &replyLength, NULL, NULL)) != E_OK) REPORT_ERROR(MAJOR, errCode, NO_MSG); if (replyLength != (sizeof(uint32_t) + sizeof(uint32_t))) { REPORT_ERROR(MAJOR, E_INVALID_VALUE, ("IPC reply length mismatch")); errCode = E_INVALID_VALUE; } if (errCode == E_OK) { memcpy((uint8_t*)&count, reply.replyBody, sizeof(uint32_t)); return count; } } else REPORT_ERROR(WARNING, E_NOT_SUPPORTED, ("In 'guest', either IPC or 'baseAddress' is required!")); return 0; }
GdkPixbuf * gtk_icon_cache_get_icon (GtkIconCache *cache, const gchar *icon_name, gint directory_index) { guint32 offset, image_data_offset, pixel_data_offset; guint32 length, type; GdkPixbuf *pixbuf; GdkPixdata pixdata; GError *error = NULL; offset = find_image_offset (cache, icon_name, directory_index); if (!offset) return NULL; image_data_offset = GET_UINT32 (cache->buffer, offset + 4); if (!image_data_offset) return NULL; pixel_data_offset = GET_UINT32 (cache->buffer, image_data_offset); type = GET_UINT32 (cache->buffer, pixel_data_offset); if (type != 0) { GTK_NOTE (ICONTHEME, g_message ("invalid pixel data type %u", type)); return NULL; } length = GET_UINT32 (cache->buffer, pixel_data_offset + 4); G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (!gdk_pixdata_deserialize (&pixdata, length, (guchar *)(cache->buffer + pixel_data_offset + 8), &error)) { GTK_NOTE (ICONTHEME, g_message ("could not deserialize data: %s", error->message)); g_error_free (error); return NULL; } G_GNUC_END_IGNORE_DEPRECATIONS pixbuf = gdk_pixbuf_new_from_data (pixdata.pixel_data, GDK_COLORSPACE_RGB, (pixdata.pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA, 8, pixdata.width, pixdata.height, pixdata.rowstride, (GdkPixbufDestroyNotify)pixbuf_destroy_cb, cache); if (!pixbuf) { GTK_NOTE (ICONTHEME, g_message ("could not convert pixdata to pixbuf: %s", error->message)); g_error_free (error); return NULL; } gtk_icon_cache_ref (cache); return pixbuf; }
void md5_process( md5_context *ctx, uint8_t data[64] ) { uint32_t X[16], A, B, C, D; GET_UINT32( X[0], data, 0 ); GET_UINT32( X[1], data, 4 ); GET_UINT32( X[2], data, 8 ); GET_UINT32( X[3], data, 12 ); GET_UINT32( X[4], data, 16 ); GET_UINT32( X[5], data, 20 ); GET_UINT32( X[6], data, 24 ); GET_UINT32( X[7], data, 28 ); GET_UINT32( X[8], data, 32 ); GET_UINT32( X[9], data, 36 ); GET_UINT32( X[10], data, 40 ); GET_UINT32( X[11], data, 44 ); GET_UINT32( X[12], data, 48 ); GET_UINT32( X[13], data, 52 ); GET_UINT32( X[14], data, 56 ); GET_UINT32( X[15], data, 60 ); #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) #define P(a,b,c,d,k,s,t) \ { \ a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \ } A = ctx->state[0]; B = ctx->state[1]; C = ctx->state[2]; D = ctx->state[3]; #define F(x,y,z) (z ^ (x & (y ^ z))) P( A, B, C, D, 0, 7, 0xD76AA478 ); P( D, A, B, C, 1, 12, 0xE8C7B756 ); P( C, D, A, B, 2, 17, 0x242070DB ); P( B, C, D, A, 3, 22, 0xC1BDCEEE ); P( A, B, C, D, 4, 7, 0xF57C0FAF ); P( D, A, B, C, 5, 12, 0x4787C62A ); P( C, D, A, B, 6, 17, 0xA8304613 ); P( B, C, D, A, 7, 22, 0xFD469501 ); P( A, B, C, D, 8, 7, 0x698098D8 ); P( D, A, B, C, 9, 12, 0x8B44F7AF ); P( C, D, A, B, 10, 17, 0xFFFF5BB1 ); P( B, C, D, A, 11, 22, 0x895CD7BE ); P( A, B, C, D, 12, 7, 0x6B901122 ); P( D, A, B, C, 13, 12, 0xFD987193 ); P( C, D, A, B, 14, 17, 0xA679438E ); P( B, C, D, A, 15, 22, 0x49B40821 ); #undef F #define F(x,y,z) (y ^ (z & (x ^ y))) P( A, B, C, D, 1, 5, 0xF61E2562 ); P( D, A, B, C, 6, 9, 0xC040B340 ); P( C, D, A, B, 11, 14, 0x265E5A51 ); P( B, C, D, A, 0, 20, 0xE9B6C7AA ); P( A, B, C, D, 5, 5, 0xD62F105D ); P( D, A, B, C, 10, 9, 0x02441453 ); P( C, D, A, B, 15, 14, 0xD8A1E681 ); P( B, C, D, A, 4, 20, 0xE7D3FBC8 ); P( A, B, C, D, 9, 5, 0x21E1CDE6 ); P( D, A, B, C, 14, 9, 0xC33707D6 ); P( C, D, A, B, 3, 14, 0xF4D50D87 ); P( B, C, D, A, 8, 20, 0x455A14ED ); P( A, B, C, D, 13, 5, 0xA9E3E905 ); P( D, A, B, C, 2, 9, 0xFCEFA3F8 ); P( C, D, A, B, 7, 14, 0x676F02D9 ); P( B, C, D, A, 12, 20, 0x8D2A4C8A ); #undef F #define F(x,y,z) (x ^ y ^ z) P( A, B, C, D, 5, 4, 0xFFFA3942 ); P( D, A, B, C, 8, 11, 0x8771F681 ); P( C, D, A, B, 11, 16, 0x6D9D6122 ); P( B, C, D, A, 14, 23, 0xFDE5380C ); P( A, B, C, D, 1, 4, 0xA4BEEA44 ); P( D, A, B, C, 4, 11, 0x4BDECFA9 ); P( C, D, A, B, 7, 16, 0xF6BB4B60 ); P( B, C, D, A, 10, 23, 0xBEBFBC70 ); P( A, B, C, D, 13, 4, 0x289B7EC6 ); P( D, A, B, C, 0, 11, 0xEAA127FA ); P( C, D, A, B, 3, 16, 0xD4EF3085 ); P( B, C, D, A, 6, 23, 0x04881D05 ); P( A, B, C, D, 9, 4, 0xD9D4D039 ); P( D, A, B, C, 12, 11, 0xE6DB99E5 ); P( C, D, A, B, 15, 16, 0x1FA27CF8 ); P( B, C, D, A, 2, 23, 0xC4AC5665 ); #undef F #define F(x,y,z) (y ^ (x | ~z)) P( A, B, C, D, 0, 6, 0xF4292244 ); P( D, A, B, C, 7, 10, 0x432AFF97 ); P( C, D, A, B, 14, 15, 0xAB9423A7 ); P( B, C, D, A, 5, 21, 0xFC93A039 ); P( A, B, C, D, 12, 6, 0x655B59C3 ); P( D, A, B, C, 3, 10, 0x8F0CCC92 ); P( C, D, A, B, 10, 15, 0xFFEFF47D ); P( B, C, D, A, 1, 21, 0x85845DD1 ); P( A, B, C, D, 8, 6, 0x6FA87E4F ); P( D, A, B, C, 15, 10, 0xFE2CE6E0 ); P( C, D, A, B, 6, 15, 0xA3014314 ); P( B, C, D, A, 13, 21, 0x4E0811A1 ); P( A, B, C, D, 4, 6, 0xF7537E82 ); P( D, A, B, C, 11, 10, 0xBD3AF235 ); P( C, D, A, B, 2, 15, 0x2AD7D2BB ); P( B, C, D, A, 9, 21, 0xEB86D391 ); #undef F ctx->state[0] += A; ctx->state[1] += B; ctx->state[2] += C; ctx->state[3] += D; }