static const guchar * decode_double (const guchar *data, double *dest) { int i; data = decode_int (data, &i); switch ((GnomeMetaDoubleType)i) { case GNOME_META_DOUBLE_INT: data = decode_int (data, &i); *dest = i; break; case GNOME_META_DOUBLE_INT1000: data = decode_int (data, &i); *dest = i / 1000.0; break; case GNOME_META_DOUBLE_I386: #if G_BYTE_ORDER == G_BIG_ENDIAN g_assert (sizeof (double) == 8); for (i = 0; i < sizeof (double); i++) ((guint8 *)dest)[sizeof (double) - 1 - i] = data[i]; #elif G_BYTE_ORDER == G_LITTLE_ENDIAN g_assert (sizeof (double) == 8); memcpy (dest, data, sizeof (double)); #else #error decode_double_needs_attention #endif data += 8; /* An i386 double is eight bytes. */ break; default: *dest = 0; /* ??? */ } return data; }
void decode_varint(pTHX_ unsigned char *input, STRLEN len, struct cc_type *type, SV *output) { if (UNLIKELY(len <= 0)) { croak("decode_varint: len <= 0"); } else if (len == 1) { decode_tinyint(aTHX_ input, len, type, output); } else if (len == 2) { decode_smallint(aTHX_ input, len, type, output); } else if (len == 3) { unsigned char bytes[4]; memcpy(bytes+1, input, 3); if (input[0] & 0x80) { bytes[0] = 0xff; } else { bytes[0] = 0; } decode_int(aTHX_ bytes, 4, type, output); } else if (len == 4) { decode_int(aTHX_ input, len, type, output); #ifdef CAN_64BIT } else if (len < 8) { unsigned char bytes[8]; memset(bytes, (input[0] & 0x80) ? 0xff : 0, 8); memcpy(bytes+8-len, input, len); decode_bigint(aTHX_ bytes, 8, type, output); } else if (len == 8) { decode_bigint(aTHX_ input, len, type, output); #endif } else { unsigned char *tmp; char *tmpout; struct cc_bignum bn; int i; Newxz(tmpout, (len*4)+2, char); if (!IS_BIG_ENDIAN) { Newxz(tmp, len, unsigned char); for (i = 0; i < len; i++) { tmp[len-i-1] = (unsigned char)input[i]; } } else { tmp = input; } cc_bignum_init_bytes(&bn, tmp, len); cc_bignum_stringify(&bn, tmpout, (len*4)+2); sv_setpv(output, tmpout); cc_bignum_destroy(&bn); if (!IS_BIG_ENDIAN) { Safefree(tmp); } Safefree(tmpout); } }
int decode_ack(char *ack){ //printf("decode_ack:%d\n", strlen(ack)); if(ack != NULL){ printf("expect sequence: %d\n", decode_int(ack)); return decode_int(ack); } return -1; }
void decode_attr(DBusMessageIter *iter, int *err, alarm_attr_t *att) { decode_dstring(iter, err, &att->attr_name); decode_int (iter, err, &att->attr_type); switch( att->attr_type ) { case ALARM_ATTR_NULL: break; case ALARM_ATTR_INT: decode_int (iter, err, &att->attr_data.ival);break; case ALARM_ATTR_TIME: decode_time (iter, err, &att->attr_data.tval);break; case ALARM_ATTR_STRING:decode_dstring(iter, err, &att->attr_data.sval);break; } }
/* * getSize: Get file size of a regular file. * * precondition: length of name is of valid length * * @size Integer Pointer file size * @blockID Integer location of the starting block of a file * * return 0: successful execution * return -1: error retrieving the file control block */ int getSize(int* size, int blockID) { *size = 0; char* block; char next[2]; do { block = malloc(BLOCK_SIZE); if (get_block(blockID, block)) { fprintf(stderr, "Error retrieving the file control block.\n"); return -1; } next[0] = block[NEXT_BLOCK]; next[1] = block[NEXT_BLOCK + 1]; blockID = decode_int(next); } while (blockID != BLOCK_END && (*size += BLOCK_SIZE - 3)); int p = BLOCK_SIZE - 1; while (block[p--] == '\0') { } *size += --p; return 0; }
/* * getStart: Get the starting block of the file path component from the file control block. * * precondition: length of name is of valid length * * @block Integer Pointer starting block id of the file component * @fcBlock Integer the file control block id * @name String the file component * * return 0: successful execution * return -1: error retrieving the file control block * return -2: error finding entry in the file control block */ int getStart(int* blockID, int fcBlockID, const char* name) { if (fcBlockID == ROOT_BLOCKID && !strcmp(name, ROOT)) { *blockID = ROOT_BLOCKID; return 0; } char* fcb = malloc(BLOCK_SIZE); if (get_block(fcBlockID, fcb)) { fprintf(stderr, "Error retrieving the file control block.\n"); return -1; } for (int i = ENTRY_START; i < BLOCK_SIZE; i += ENTRY_LENGTH) { char* line = &fcb[i]; char entryName[MAX_DIRNAME - 1]; strncpy(entryName, &line[NAME_P], MAX_DIRNAME - 1); if (!strcmp(entryName, name)) { char start[2]; start[0] = line[START_P]; start[1] = line[START_P + 1]; *blockID = decode_int(start); return 0; } } return -2; }
void decode_time(DBusMessageIter *iter, int *err, time_t *pval) { int tmp = 0; decode_int(iter, err, &tmp); *pval = tmp; }
void decode_tm(DBusMessageIter *iter, int *err, struct tm *tm) { decode_int(iter, err, &tm->tm_sec); decode_int(iter, err, &tm->tm_min); decode_int(iter, err, &tm->tm_hour); decode_int(iter, err, &tm->tm_mday); decode_int(iter, err, &tm->tm_mon); decode_int(iter, err, &tm->tm_year); decode_int(iter, err, &tm->tm_wday); decode_int(iter, err, &tm->tm_yday); decode_int(iter, err, &tm->tm_isdst); }
static const guchar * gpm_decode_string (const guchar *data, guchar **dest) { gint32 len; data = decode_int (data, &len); *dest = g_malloc (len + 1); memcpy (*dest, data, len); (*dest)[len] = 0; return data + len; }
size_t decode_rev(const char *b,size_t len,const char *keylist) { if( !b ) return 0; switch( *b ){ case 'i': return decode_int(b,len); case 'd': return decode_dict(b,len,keylist); case 'l': return decode_list(b,len,keylist); default: return decode_str(b,len); } }
static int get_mday (const unsigned char *in, unsigned int inlen) { int mday; mday = decode_int (in, inlen); if (mday < 0 || mday > 31) mday = -1; return mday; }
static int get_year (const unsigned char *in, unsigned int inlen) { int year; year = decode_int (in, inlen); if (year == -1) return -1; if (year < 100) year += (year < 70) ? 2000 : 1900; if (year < 1969) return -1; return year; }
static int get_tzone (struct _date_token **token) { const unsigned char *inptr, *inend; unsigned int inlen; int i, t; for (i = 0; *token && i < 2; *token = (*token)->next, i++) { inptr = (*token)->start; inlen = (*token)->len; inend = inptr + inlen; if (*inptr == '+' || *inptr == '-') { t = decode_int (inptr, inlen); if (t < -1200 || t > 1400) return -1; return t; } else { if (*inptr == '(') { inptr++; if (*(inend - 1) == ')') inlen -= 2; else inlen--; } for (t = 0; t < 15; t++) { unsigned int len = strlen (tz_offsets[t].name); if (len != inlen) continue; if (!strncmp ((const char*)inptr, tz_offsets[t].name, len)) return tz_offsets[t].offset; } } } return -1; }
int php_deserialize( rabbit * r, rawbuffer * buf, TValue * tv ) { if(!buf || !tv) { return -1; } setnilvalue(tv); int c = decode_read_byte( buf ); switch( c ) { case PHP_NULL: // kLOG(r, 0,"php decode nil\n"); return decode_null( r, buf, tv ); case PHP_INT: // kLOG(r, 0,"php decode int\n"); return decode_int( r, buf, tv ); case PHP_DOUBLE: // kLOG(r, 0,"php decode double\n"); return decode_double(r, buf, tv); case PHP_STRING: // kLOG(r, 0,"php decode string\n"); return decode_string(r, buf, tv); case PHP_ARRAY: // kLOG(r, 0,"php decode array\n"); return decode_array(r, buf, tv); case PHP_BOOL: return decode_bool(r, buf, tv); default: kLOG(r, 0, "php decode unknow:%c\n",c); break; } return -1; }
void decode_buffer(unsigned char *buffer){ printf("Start decoding the packet!!\n"); unsigned int ans = decode_int(buffer); buffer +=4; //unsigned int langth = decode_int(buffer); unsigned char *str = malloc(sizeof(char) * NAMELENGTH); str = decode_char(buffer); printf("decoded buffer is: %s, %d\n", str, ans); while(send_ack(1, -1) < 0){ printf("failed ack\n"); } connection = 1; return; }
/* Determine the type and pass processing to the next apropriate function * Accepts: buffer, pointer to msg, char of type return, pointer to memory registrar * Returns: a pointer to the decoded msg */ void *decode_next(struct Buffer *buf, char **bi, char *type) { if (*bi < buf->cnt + (buf->size - 2)) { switch (**bi) { case 'd': *type = 'd'; return decode_dict(buf, bi); break; case 'l': *type = 'l'; return decode_list(buf, bi); break; case 'i': *type = 'i'; return decode_int(buf, bi); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': *type = 's'; return decode_str(buf, bi); break; default: fprintf(stderr, "error: decode_next could not determine type encoding %c\n", **bi); exit(1); } } else { return NULL; //fprintf(stderr, "error: decode_next - unexcpected end of buffer\n"); //exit(1); } }
/* * removeEntry: Removes an entry from a fcb. * * @start: Integer Pointer location of the starting block * @fcBlockID: Integer the target fcb id * @name: String name of the entry * * return 0: successful execution * return -1: error retrieving the parent file control block * return -2: error finding entry in the file control block * return -3: error creating file control block */ int removeEntry(int* start, int fcBlockID, const char* name) { char* fcb = malloc(BLOCK_SIZE); if (get_block(fcBlockID, fcb)) { fprintf(stderr, "Error retrieving the parent file control block.\n"); return -1; } for (int i = ENTRY_START; i < BLOCK_SIZE; i += ENTRY_LENGTH) { char* line = &fcb[i]; char entryName[MAX_DIRNAME - 1]; strncpy(entryName, &line[NAME_P], MAX_DIRNAME - 1); if (!strcmp(entryName, name)) { char _start[2]; _start[0] = line[START_P]; _start[1] = line[START_P + 1]; *start = decode_int(_start); fcb[i] = ENTRY_END; for (int j = i + 1; j < i + ENTRY_LENGTH + 1; j++) { fcb[j] = '\0'; } if (put_block(fcBlockID, fcb)) { fprintf(stderr, "Error creating file control block.\n"); return -3; } return 0; } } fprintf(stderr, "Error finding entry in the file control block.\n"); return -2; }
prop_t* decode_prop(CBitRead& entityBitBuffer, FlattenedPropEntry* pFlattenedProp, uint32_t uClass, int nFieldIndex) { const CSVCMsg_SendTable::sendprop_t* pSendProp = pFlattenedProp->m_prop; prop_t* pResult = 0; if(pSendProp->type() != DPT_Array && pSendProp->type() != DPT_DataTable) { pResult = new prop_t((send_prop_type_t)(pSendProp->type())); } switch(pSendProp->type()) { case DPT_Int: pResult->m_value.m_int = decode_int(entityBitBuffer, pSendProp); break; case DPT_Float: pResult->m_value.m_float = decode_float(entityBitBuffer, pSendProp); break; case DPT_Vector: decode_vector_xyz(entityBitBuffer, pSendProp, pResult->m_value.m_vector); break; case DPT_VectorXY: decode_vector_xy(entityBitBuffer, pSendProp, pResult->m_value.m_vector); break; case DPT_String: pResult->m_value.m_pString = decode_string(entityBitBuffer, pSendProp); break; case DPT_Array: pResult = decode_array(entityBitBuffer, pFlattenedProp, pSendProp->num_elements(), uClass, nFieldIndex); break; case DPT_DataTable: break; case DPT_Int64: pResult->m_value.m_int64 = decode_int64(entityBitBuffer, pSendProp); break; } return pResult; }
static void decode_license(license_struct *to, const license_raw *from) { to->license_file = NULL; to->unique_id = decode_int(from->unique_id); to->licensee_name = decode_string(from->licensee_name, sizeof(from->licensee_name)); to->licensee_email = decode_string(from->licensee_email, sizeof(from->licensee_email)); to->licensee_company = decode_string(from->licensee_company, sizeof(from->licensee_company)); to->licensee_department = decode_string(from->licensee_department, sizeof(from->licensee_department)); to->valid_from = decode_int(from->valid_from); to->valid_until = decode_int(from->valid_until); to->host_id = decode_int(from->host_id); to->login_name = decode_string(from->login_name, sizeof(from->login_name)); to->from_major = decode_int(from->from_major); to->from_minor = decode_int(from->from_minor); to->from_patchlevel = decode_int(from->from_patchlevel); to->to_major = decode_int(from->to_major); to->to_minor = decode_int(from->to_minor); to->to_patchlevel = decode_int(from->to_patchlevel); to->feature_list = decode_int(from->feature_list); /* Borrow the PER bit for this year */ /* 1262300400 is Fri Jan 1 00:00:00 2010 */ if((to->feature_list & FEATURE_PER) && (time(NULL) < 1262300400)) { to->feature_list |= FEATURE_XER; } to->limitation_type = decode_int(from->limitation_type); to->max_ptcs = decode_int(from->max_ptcs); }
static VALUE ossl_asn1_decode0(unsigned char **pp, long length, long *offset, long depth, int once, int yield) { unsigned char *start, *p; const unsigned char *p0; long len, off = *offset; int hlen, tag, tc, j; VALUE ary, asn1data, value, tag_class; ary = rb_ary_new(); p = *pp; while(length > 0){ start = p; p0 = p; j = ASN1_get_object(&p0, &len, &tag, &tc, length); p = (unsigned char *)p0; if(j & 0x80) ossl_raise(eASN1Error, NULL); hlen = p - start; if(yield){ VALUE arg = rb_ary_new(); rb_ary_push(arg, LONG2NUM(depth)); rb_ary_push(arg, LONG2NUM(off)); rb_ary_push(arg, LONG2NUM(hlen)); rb_ary_push(arg, LONG2NUM(len)); rb_ary_push(arg, (j & V_ASN1_CONSTRUCTED) ? Qtrue : Qfalse); rb_ary_push(arg, ossl_asn1_class2sym(tc)); rb_ary_push(arg, INT2NUM(tag)); rb_yield(arg); } length -= hlen; off += hlen; if(len > length) ossl_raise(eASN1Error, "value is too short"); if((tc & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) tag_class = sPRIVATE; else if((tc & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) tag_class = sCONTEXT_SPECIFIC; else if((tc & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) tag_class = sAPPLICATION; else tag_class = sUNIVERSAL; if(j & V_ASN1_CONSTRUCTED){ /* TODO: if j == 0x21 it is indefinite length object. */ if((j == 0x21) && (len == 0)){ long lastoff = off; value = ossl_asn1_decode0(&p, length, &off, depth+1, 0, yield); len = off - lastoff; } else value = ossl_asn1_decode0(&p, len, &off, depth+1, 0, yield); } else{ value = rb_str_new((const char *)p, len); p += len; off += len; } if(tag_class == sUNIVERSAL && tag < ossl_asn1_info_size && ossl_asn1_info[tag].klass){ VALUE klass = *ossl_asn1_info[tag].klass; long flag = 0; if(!rb_obj_is_kind_of(value, rb_cArray)){ switch(tag){ case V_ASN1_BOOLEAN: value = decode_bool(start, hlen+len); break; case V_ASN1_INTEGER: value = decode_int(start, hlen+len); break; case V_ASN1_BIT_STRING: value = decode_bstr(start, hlen+len, &flag); break; case V_ASN1_NULL: value = decode_null(start, hlen+len); break; case V_ASN1_ENUMERATED: value = decode_enum(start, hlen+len); break; case V_ASN1_OBJECT: value = decode_obj(start, hlen+len); break; case V_ASN1_UTCTIME: /* FALLTHROUGH */ case V_ASN1_GENERALIZEDTIME: value = decode_time(start, hlen+len); break; default: /* use original value */ break; } } asn1data = rb_funcall(klass, rb_intern("new"), 1, value); if(tag == V_ASN1_BIT_STRING){ rb_iv_set(asn1data, "@unused_bits", LONG2NUM(flag)); } } else{ asn1data = rb_funcall(cASN1Data, rb_intern("new"), 3, value, INT2NUM(tag), ID2SYM(tag_class)); } rb_ary_push(ary, asn1data); length -= len; if(once) break; } *pp = p; *offset = off; return ary; }
static time_t decode_broken_date (struct _date_token *tokens, int *tzone) { gboolean got_wday, got_month, got_tzone; int hour, min, sec, offset, n; struct _date_token *token; struct tm tm; time_t time; memset ((void *) &tm, 0, sizeof (struct tm)); got_wday = got_month = got_tzone = FALSE; offset = 0; token = tokens; while (token) { if (is_weekday (token) && !got_wday) { if ((n = get_wday (token->start, token->len)) != -1) { d(printf ("weekday; ")); got_wday = TRUE; tm.tm_wday = n; goto next_token; } } if (is_month (token) && !got_month) { if ((n = get_month (token->start, token->len)) != -1) { d(printf ("month; ")); got_month = TRUE; tm.tm_mon = n; goto next_token; } } if (is_time (token) && !tm.tm_hour && !tm.tm_min && !tm.tm_sec) { if (get_time (token->start, token->len, &hour, &min, &sec)) { d(printf ("time; ")); tm.tm_hour = hour; tm.tm_min = min; tm.tm_sec = sec; goto next_token; } } if (is_tzone (token) && !got_tzone) { struct _date_token *t = token; if ((n = get_tzone (&t)) != -1) { d(printf ("tzone; ")); got_tzone = TRUE; offset = n; goto next_token; } } if (is_numeric (token)) { if (token->len == 4 && !tm.tm_year) { if ((n = get_year (token->start, token->len)) != -1) { d(printf ("year; ")); tm.tm_year = n - 1900; goto next_token; } } else { if (!got_month && !got_wday && token->next && is_numeric (token->next)) { d(printf ("mon; ")); n = decode_int (token->start, token->len); got_month = TRUE; tm.tm_mon = n - 1; goto next_token; } else if (!tm.tm_mday && (n = get_mday (token->start, token->len)) != -1) { d(printf ("mday; ")); tm.tm_mday = n; goto next_token; } else if (!tm.tm_year) { d(printf ("2-digit year; ")); n = get_year (token->start, token->len); tm.tm_year = n - 1900; goto next_token; } } } d(printf ("???; ")); next_token: token = token->next; } d(printf ("\n")); time = e_mktime_utc (&tm); /* time is now GMT of the time we want, but not offset by the timezone ... */ /* this should convert the time to the GMT equiv time */ time -= ((offset / 100) * 60 * 60) + (offset % 100) * 60; if (tzone) *tzone = offset; return time; }
void decode_event(DBusMessageIter *iter, int *err, alarm_event_t *eve) { size_t action_cnt = 0; size_t recurrence_cnt = 0; alarm_event_del_actions(eve); alarm_event_del_recurrences(eve); decode_cookie (iter, err, &eve->ALARMD_PRIVATE(cookie)); decode_time (iter, err, &eve->ALARMD_PRIVATE(trigger)); decode_dstring (iter, err, &eve->title); decode_dstring (iter, err, &eve->message); decode_dstring (iter, err, &eve->sound); decode_dstring (iter, err, &eve->icon); decode_unsigned (iter, err, &eve->flags); decode_dstring (iter, err, &eve->alarm_appid); decode_time (iter, err, &eve->alarm_time); decode_tm (iter, err, &eve->alarm_tm); decode_dstring (iter, err, &eve->alarm_tz); decode_time (iter, err, &eve->recur_secs); decode_int (iter, err, &eve->recur_count); decode_time (iter, err, &eve->snooze_secs); decode_time (iter, err, &eve->snooze_total); decode_size (iter, err, &action_cnt); decode_int (iter, err, &eve->response); /* - - - - - - - - - - - - - - - - - - - * * action table * - - - - - - - - - - - - - - - - - - - */ alarm_action_t *act = alarm_event_add_actions(eve, action_cnt); for( size_t i = 0; i < action_cnt; ++i ) { decode_action(iter, err, &act[i]); } /* - - - - - - - - - - - - - - - - - - - * * recurrence table * - - - - - - - - - - - - - - - - - - - */ decode_size (iter, err, &recurrence_cnt); alarm_recur_t *rec = alarm_event_add_recurrences(eve, recurrence_cnt); for( size_t i = 0; i < recurrence_cnt; ++i ) { decode_recur(iter, err, &rec[i]); } /* - - - - - - - - - - - - - - - - - - - * * attribute table sent by libalarm >= 1.0.4 * - - - - - - - - - - - - - - - - - - - */ if( !decode_eom_p(iter, err) ) { size_t count = 0; decode_size (iter, err, &count); for( size_t i = 0; i < count; ++i ) { alarm_attr_t *att = alarm_event_add_attr(eve, "\x7f"); decode_attr(iter, err, att); } } }
void show (obj o) { #if 0 printf ("[%d]", o); #endif if (o == OBJ_FALSE) { printf ("#f"); } else if (o == OBJ_TRUE) { printf ("#t"); } else if (o == OBJ_NULL) { printf ("()"); } else if (o <= (MIN_FIXNUM_ENCODING + (MAX_FIXNUM - MIN_FIXNUM))) { printf ("%d", DECODE_FIXNUM(o)); } else { uint8 in_ram; if (IN_RAM(o)) { in_ram = 1; } else { in_ram = 0; } if ((in_ram && RAM_BIGNUM_P(o)) || (!in_ram && ROM_BIGNUM_P(o))) { // TODO fix for new bignums, especially for the sign, a -5 is displayed as 251 printf ("%d", decode_int (o)); } else if ((in_ram && RAM_COMPOSITE_P(o)) || (!in_ram && ROM_COMPOSITE_P(o))) { obj car; obj cdr; if ((in_ram && RAM_PAIR_P(o)) || (!in_ram && ROM_PAIR_P(o))) { if (in_ram) { car = ram_get_car (o); cdr = ram_get_cdr (o); } else { car = rom_get_car (o); cdr = rom_get_cdr (o); } printf ("("); loop: show (car); if (cdr == OBJ_NULL) { printf (")"); } else if ((IN_RAM(cdr) && RAM_PAIR_P(cdr)) || (IN_ROM(cdr) && ROM_PAIR_P(cdr))) { if (IN_RAM(cdr)) { car = ram_get_car (cdr); cdr = ram_get_cdr (cdr); } else { car = rom_get_car (cdr); cdr = rom_get_cdr (cdr); } printf (" "); goto loop; } else { printf (" . "); show (cdr); printf (")"); } } else if ((in_ram && RAM_SYMBOL_P(o)) || (!in_ram && ROM_SYMBOL_P(o))) { printf ("#<symbol>"); } else if ((in_ram && RAM_STRING_P(o)) || (!in_ram && ROM_STRING_P(o))) { printf ("#<string>"); } else if ((in_ram && RAM_VECTOR_P(o)) || (!in_ram && ROM_VECTOR_P(o))) { printf ("#<vector %d>", o); } else { printf ("("); cdr = ram_get_car (o); car = ram_get_cdr (o); // ugly hack, takes advantage of the fact that pairs and // continuations have the same layout goto loop; } } else { // closure obj env; rom_addr pc; env = ram_get_car (o); pc = ram_get_entry (o); printf ("{0x%04x ", pc); show (env); printf ("}"); } } fflush (stdout); }
if(sendto(s, ack, sizeof(char) * 1, 0, &si_other, slen) == -1) return -1; }else if(type == 2){ unsigned char ack[5]; ack[4] = '\0'; for(i = 0;i < 4;i++){ if(i == 3) ack[i] = i3 >> 0; else{ ack[i] = shift >> (24 - 8 * i); i3 -= (int)(ack[i] << (24 - 8 * i)); } } printf("ack is : %d\n", decode_int(ack)); while(sendto(s, ack, sizeof(char) * 4, 0, &si_other, slen) < 0) printf("send data ack error\n"); } printf("ack\n"); return 1; } void decode_fileContent(unsigned char *buffer){ char f**k[2]; f**k[0] = '1'; f**k[1] = '\0'; if(strlen(buffer) == 1){ // send back fin while(sendto(s, f**k, sizeof(char) * 1, 0, &si_other, slen) < 0){}
static gint gpm_render (GnomePrintContext *dest, const guchar *data, gint pos, gint len, gboolean pageops) { const guchar *end; data = data + pos; end = data + len; while (data < end){ gint32 opcode, i; guchar *cval; gint32 ival; gdouble dval; ArtBpath *bpath; data = decode_int (data, &opcode); switch ((GnomeMetaType) opcode) { case GNOME_META_BEGINPAGE: data = gpm_decode_string (data, &cval); if (pageops) gnome_print_beginpage (dest, cval); g_free (cval); break; case GNOME_META_SHOWPAGE: if (pageops) gnome_print_showpage (dest); break; case GNOME_META_GSAVE: gnome_print_gsave (dest); break; case GNOME_META_GRESTORE: gnome_print_grestore (dest); break; case GNOME_META_CLIP: data = gpm_decode_bpath (data, &bpath); data = decode_int (data, &ival); gnome_print_clip_bpath_rule (dest, bpath, ival); g_free (bpath); break; case GNOME_META_FILL: data = gpm_decode_bpath (data, &bpath); data = decode_int (data, &ival); gnome_print_fill_bpath_rule (dest, bpath, ival); g_free (bpath); break; case GNOME_META_STROKE: data = gpm_decode_bpath (data, &bpath); gnome_print_stroke_bpath (dest, bpath); g_free (bpath); break; case GNOME_META_IMAGE: { gdouble affine[6]; gint32 width, height, channels; guchar *buf; data = decode_double (data, &affine[0]); data = decode_double (data, &affine[1]); data = decode_double (data, &affine[2]); data = decode_double (data, &affine[3]); data = decode_double (data, &affine[4]); data = decode_double (data, &affine[5]); data = decode_int (data, &height); data = decode_int (data, &width); data = decode_int (data, &channels); buf = g_new (guchar, height * width * channels); memcpy (buf, data, height * width * channels); data += height * width * channels; gnome_print_image_transform (dest, affine, buf, width, height, channels * width, channels); g_free (buf); break; } case GNOME_META_GLYPHLIST: { GnomeGlyphList *gl; gdouble affine[6]; gint32 len, code, ival, i; gdouble dval; data = decode_double (data, &affine[0]); data = decode_double (data, &affine[1]); data = decode_double (data, &affine[2]); data = decode_double (data, &affine[3]); data = decode_double (data, &affine[4]); data = decode_double (data, &affine[5]); gl = gnome_glyphlist_new (); data = decode_int (data, &len); if (len > 0) { gl->glyphs = g_new (int, len); gl->g_length = len; gl->g_size = len; for (i = 0; i < len; i++) { data = decode_int (data, &ival); gl->glyphs[i] = ival; } } data = decode_int (data, &len); if (len > 0) { gl->rules = g_new (GGLRule, len); gl->r_length = len; gl->r_size = len; for (i = 0; i < len; i++) { data = decode_int (data, &code); gl->rules[i].code = code; switch (code) { case GGL_POSITION: case GGL_ADVANCE: case GGL_COLOR: data = decode_int (data, &ival); gl->rules[i].value.ival = ival; break; case GGL_MOVETOX: case GGL_MOVETOY: case GGL_RMOVETOX: case GGL_RMOVETOY: case GGL_LETTERSPACE: case GGL_KERNING: data = decode_double (data, &dval); gl->rules[i].value.dval = dval; break; case GGL_FONT: { GnomeFont *font; guchar *name; data = decode_double (data, &dval); data = gpm_decode_string (data, &name); font = gnome_font_find (name, dval); if (font == NULL) g_warning ("Cannot find font: %s\n", name); g_free (name); gl->rules[i].value.font = font; break; } default: break; } } } gnome_print_glyphlist_transform (dest, affine, gl); gnome_glyphlist_unref (gl); break; } break; case GNOME_META_COLOR: { gdouble r, g, b, a; data = decode_double (data, &r); data = decode_double (data, &g); data = decode_double (data, &b); gnome_print_setrgbcolor (dest, r, g, b); data = decode_double (data, &a); gnome_print_setopacity (dest, a); break; } case GNOME_META_LINE: data = decode_double (data, &dval); gnome_print_setlinewidth (dest, dval); data = decode_double (data, &dval); gnome_print_setmiterlimit (dest, dval); data = decode_int (data, &ival); gnome_print_setlinejoin (dest, ival); data = decode_int (data, &ival); gnome_print_setlinecap (dest, ival); break; case GNOME_META_DASH: { int n; double *values, offset; data = decode_int (data, &n); values = g_new (double, n); for (i = 0; i < n; i++) { data = decode_double (data, &values [i]); } data = decode_double (data, &offset); gnome_print_setdash (dest, n, values, offset); g_free (values); break; } default: g_warning ("Serious print meta data corruption %d", opcode); break; } }
static int decode_snmp_request(request_t *request, client_t *client) { int type; size_t pos = 0, len = 0; const char *header_msg = "Unexpected SNMP header"; const char *error_msg = "Unexpected SNMP error"; const char *request_msg = "Unexpected SNMP request"; const char *varbind_msg = "Unexpected SNMP varbindings"; const char *commun_msg = "SNMP community"; const char *version_msg = "SNMP version"; /* The SNMP message is enclosed in a sequence */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (type != BER_TYPE_SEQUENCE || len != (client->size - pos)) { lprintf(LOG_DEBUG, "%s type %02X length %zu\n", header_msg, type, len); errno = EINVAL; return -1; } /* The first element of the sequence is the version */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (type != BER_TYPE_INTEGER || len != 1) { lprintf(LOG_DEBUG, "Unexpected %s type %02X length %zu\n", version_msg, type, len); errno = EINVAL; return -1; } if (decode_int(client->packet, client->size, &pos, len, &request->version) == -1) return -1; if (request->version != SNMP_VERSION_1 && request->version != SNMP_VERSION_2C) { lprintf(LOG_DEBUG, "Unsupported %s %d\n", version_msg, request->version); errno = EINVAL; return -1; } /* The second element of the sequence is the community string */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (type != BER_TYPE_OCTET_STRING || len >= sizeof(request->community)) { lprintf(LOG_DEBUG, "Unexpected %s type %02X length %zu\n", commun_msg, type, len); errno = EINVAL; return -1; } if (decode_str(client->packet, client->size, &pos, len, request->community, sizeof(request->community)) == -1) return -1; if (strlen(request->community) < 1) { lprintf(LOG_DEBUG, "unsupported %s '%s'\n", commun_msg, request->community); errno = EINVAL; return -1; } /* The third element of the sequence is the SNMP request */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (len != (client->size - pos)) { lprintf(LOG_DEBUG, "%s type type %02X length %zu\n", request_msg, type, len); errno = EINVAL; return -1; } request->type = type; /* The first element of the SNMP request is the request ID */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (type != BER_TYPE_INTEGER || len < 1) { lprintf(LOG_DEBUG, "%s id type %02X length %zu\n", request_msg, type, len); errno = EINVAL; return -1; } if (decode_int(client->packet, client->size, &pos, len, &request->id) == -1) return -1; /* The second element of the SNMP request is the error state / non repeaters (0..2147483647) */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (type != BER_TYPE_INTEGER || len < 1) { lprintf(LOG_DEBUG, "%s state type %02X length %zu\n", error_msg, type, len); errno = EINVAL; return -1; } if (decode_cnt(client->packet, client->size, &pos, len, &request->non_repeaters) == -1) return -1; /* The third element of the SNMP request is the error index / max repetitions (0..2147483647) */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (type != BER_TYPE_INTEGER || len < 1) { lprintf(LOG_DEBUG, "%s index type %02X length %zu\n", error_msg, type, len); errno = EINVAL; return -1; } if (decode_cnt(client->packet, client->size, &pos, len, &request->max_repetitions) == -1) return -1; /* The fourth element of the SNMP request are the variable bindings */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (type != BER_TYPE_SEQUENCE || len != (client->size - pos)) { lprintf(LOG_DEBUG, "%s type %02X length %zu\n", varbind_msg, type, len); errno = EINVAL; return -1; } /* Loop through the variable bindings */ request->oid_list_length = 0; while (pos < client->size) { /* If there is not enough room in the OID list, bail out now */ if (request->oid_list_length >= MAX_NR_OIDS) { lprintf(LOG_DEBUG, "Overflow in OID list\n"); errno = EFAULT; return -1; } /* Each variable binding is a sequence describing the variable */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (type != BER_TYPE_SEQUENCE || len < 1) { lprintf(LOG_DEBUG, "%s type %02X length %zu\n", varbind_msg, type, len); errno = EINVAL; return -1; } /* The first element of the variable binding is the OID */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if (type != BER_TYPE_OID || len < 1) { lprintf(LOG_DEBUG, "%s OID type %02X length %zu\n", varbind_msg, type, len); errno = EINVAL; return -1; } if (decode_oid(client->packet, client->size, &pos, len, &request->oid_list[request->oid_list_length]) == -1) return -1; /* The second element of the variable binding is the new type and value */ if (decode_len(client->packet, client->size, &pos, &type, &len) == -1) return -1; if ((type == BER_TYPE_NULL && len) || (type != BER_TYPE_NULL && !len)) { lprintf(LOG_DEBUG, "%s value type %02X length %zu\n", varbind_msg, type, len); errno = EINVAL; return -1; } if (decode_ptr(client->packet, client->size, &pos, len) == -1) return -1; /* Now the OID list has one more entry */ request->oid_list_length++; } return 0; }