PaceOutput ExternalReader::establishPACEChannelNative(const PaceInput &input) { PaceOutput paceoutput; if (m_hDoPACE) { enum PinID pinid = PI_UNDEF; switch (input.get_pin_id()) { case PaceInput::pin: pinid = PI_PIN; break; case PaceInput::can: pinid = PI_CAN; break; case PaceInput::mrz: pinid = PI_MRZ; break; case PaceInput::puk: pinid = PI_PUK; break; default: eCardCore_warn(DEBUG_LEVEL_CARD, "Unknown type of secret"); break; } const nPADataBuffer_t pin = { (unsigned char *) DATA(input.get_pin()), input.get_pin().size()}; const nPADataBuffer_t chat = { (unsigned char *) DATA(input.get_chat()), input.get_chat().size()}; const nPADataBuffer_t chat_required = { (unsigned char *) DATA(input.get_chat_required()), input.get_chat_required().size()}; const nPADataBuffer_t chat_optional = { (unsigned char *) DATA(input.get_chat_optional()), input.get_chat_optional().size()}; const nPADataBuffer_t certificate_description = { (unsigned char *) DATA(input.get_certificate_description()), input.get_certificate_description().size()}; const nPADataBuffer_t transaction_info_hidden = { (unsigned char *) DATA(input.get_transaction_info_hidden()), input.get_transaction_info_hidden().size()}; unsigned int result; unsigned short status_mse_set_at; nPADataBuffer_t ef_cardaccess = {NULL, 0}; nPADataBuffer_t car_curr = {NULL, 0}; nPADataBuffer_t car_prev = {NULL, 0}; nPADataBuffer_t id_icc = {NULL, 0}; nPADataBuffer_t chat_used = {NULL, 0}; if (ECARD_SUCCESS == m_hDoPACE(m_hCardReader, pinid, &pin, &chat, &chat_required, &chat_optional, &certificate_description, &transaction_info_hidden, &result, &status_mse_set_at, &ef_cardaccess, &car_curr, &car_prev, &id_icc, &chat_used)) { paceoutput.set_result(result); paceoutput.set_status_mse_set_at(status_mse_set_at); paceoutput.set_ef_cardaccess(buffer2vector(&ef_cardaccess)); paceoutput.set_car_curr(buffer2vector(&car_curr)); paceoutput.set_car_prev(buffer2vector(&car_prev)); paceoutput.set_id_icc(buffer2vector(&id_icc)); paceoutput.set_chat(buffer2vector(&chat_used)); free(car_curr.pDataBuffer); free(car_prev.pDataBuffer); free(ef_cardaccess.pDataBuffer); free(id_icc.pDataBuffer); free(chat_used.pDataBuffer); } else eCardCore_warn(DEBUG_LEVEL_CARD, "external PACE failed"); } return paceoutput; }
EXPORT_PROC PluginInfo* GetPluginInfo() { return &info; } /* typedef struct LoggerData { unsigned LogLevel; char *LogPackets; } LoggerData; */ static DataDef loggerData[] = { { "LogLevel", DATA_ULONG, 1, DATA(3) }, { "LogPackets", DATA_STRING, 1, 0 }, { "File", DATA_STRING, 1, 0 }, { NULL, 0, 0, 0 } }; LoggerPlugin::LoggerPlugin(unsigned base, Buffer *add_info) : Plugin(base) { m_file = NULL; load_data(loggerData, &data, add_info); string value; CmdParam p = { "-d:", I18N_NOOP("Set debug level"), &value }; Event e(EventArg, &p); if (e.process()) setLogLevel(atol(value.c_str()));
IoSecureServer *IoSecureServer_proto(void *state) { initSSL(); IoObject *self = IoObject_new(state); IoObject_tag_(self, IoSecureServer_newTag(state)); IoObject_setDataPointer_(self, (SecureServerData *)calloc(1, sizeof(SecureServerData))); SSL_CTX *ctx = SSL_CTX_new(TLSv1_server_method()); DATA(self)->ssl_ctx = ctx; SSL_CTX_set_default_passwd_cb(ctx, IoSecureSockets_Password_Callback); SSL_CTX_set_default_passwd_cb_userdata(ctx, self); SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, IoSecureSockets_Verify_Callback); #ifdef DTLS_IMPLEMENTED IoObject_setSlot_to_(self, IOSYMBOL("supportsDTLS"), IOTRUE(self)); #else IoObject_setSlot_to_(self, IOSYMBOL("supportsDTLS"), IOFALSE(self)); #endif //doc SecureServer supportsDTLS Returns true if server supports DTLS, false otherwise. IoState_registerProtoWithFunc_((IoState *)state, self, IoSecureServer_proto); { IoMethodTable methodTable[] = { {"setKeyFile", IoSecureServer_setKeyFile}, //doc SecureServer setKeyFile(path) Sets the key file. Returns self. {"setCertFile", IoSecureServer_setCertFile}, //doc SecureServer setCertFile(path) Sets the certificate file. Returns self. {"setCAFile", IoSecureServer_setCAFile}, //doc SecureServer setCAFile(path) Sets the CA file. Returns self. {"setCRLFile", IoSecureServer_setCRLFile}, //doc SecureServer setCRLFile(path) Sets the CRL file. Returns self. {"useTLS", IoSecureServer_useTLS}, //doc SecureServer useTLS Returns useTLS value. {"useDTLS", IoSecureServer_useDTLS}, //doc SecureServer useDTLS Returns useDTLS value. {"setRequiresClientCertificate", IoSecureServer_setRequiresClientCertificate}, //doc SecureServer setRequiresClientCertificate(aBool) Sets the requires client certificate attribute. Returns self. {"tlsWrap", IoSecureServer_tlsWrap}, //doc SecureServer tlsWrap Returns tlsWrap value. #ifdef DTLS_IMPLEMENTED {"dtlsWrap", IoSecureServer_dtlsWrap}, //doc SecureServer dtlsWrap Returns dtlsWrap value. {"udpRecvIP", IoSecureServer_udpRecvIP}, //doc SecureServer udpRecvIP Returns udpRecvIP value. {"dispatchUdp", IoSecureServer_dispatchUDP}, //doc SecureServer dispatchUdp Returns dispatchUdp value. #endif {NULL, NULL} }; IoObject_addMethodTable_(self, methodTable); } return self; }
float IoNumber_asFloat(IoNumber *self) { return (float)DATA(self); }
IoNumber *IoNumber_numberForDouble_canUse_(IoNumber *self, double n, IoNumber *other) { if (DATA(self) == n) return self; if (DATA(other) == n) return other; return IONUMBER(n); }
IoNumber *IoNumber_newCopyOf_(IoNumber *self) { return IONUMBER(DATA(self)); }
int IoNumber_asInt(IoNumber *self) { return (int)(DATA(self)); }
// does not check that the element is already there static int tree23_delete (tree23_root_t *R, int x) { int *P = 0, *PP = 0; tree23_t *st[40]; int sp, *y_Data = 0; tree23_t *cur = R->root, *up, *succ; int extra_words = R->extra_words; for (sp = 0; sp < R->depth; sp++) { st[sp] = cur; if (x > cur->x2) { cur = cur->right; } else if (x < cur->x1) { cur = cur->left; } else if (x == cur->x1) { P = &cur->x1; y_Data = DATA(cur->x1); if (cur->x2 == cur->x1) { PP = &cur->x2; } x++; break; } else if (x < cur->x2) { cur = cur->middle; } else { P = &cur->x2; y_Data = DATA(cur->x2); x++; break; } } // if x belongs to an inner node: // - P points to the key equal to (original) x in node cur // - PP points to cur->x2 if cur->x2 = cur->x1 = (original) x // - x equals original x+1 for some reason // if x is in a leaf, cur is this leaf, and P=PP=0 while (sp < R->depth) { st[sp++] = cur; if (x < cur->x1) { cur = cur->left; // actually will go left at all steps except the first one } else if (x > cur->x2) { cur = cur->right; } else { cur = cur->middle; } } // now cur is the leaf containing next value after (original) x, if x was in a inner node // otherwise, cur is the leaf containing x if (P) { // case 1: x was found in some inner node, ancestor of leaf cur // then x':=cur->x1 is the next value in tree after x // and we replace references to x with references to x' *P = cur->x1; if (PP) { *PP = cur->x1; } DCPY (y, cur->x1); // copy extra data words as well // after that, we just need to remove x' from leaf node cur if (cur->x1 < cur->x2) { // case 1a: cur: [ x' y ] , replace with [ y ] LET (cur->x1, cur->x2); return 1; } } else if (x == cur->x1) { if (x < cur->x2) { // case 0a: x was found in leaf cur: [ x y ], x < y // replace with [ y ] LET (cur->x1, cur->x2); return 1; } } else if (x == cur->x2) { // case 0b: x was found in leaf cur: [ u x ], u < x // simply replace it with [ u ] cur->x2 = cur->x1; return 1; } else { // x NOT FOUND in tree (?) return 0; } // here we have to remove x' from leaf node cur: [ x' ] //oh, no... //printf ("%d\n", sp); if (sp == 0) { // we are deleting the root! free_leaf (cur, Extra_words); R->root = 0; return 1; } up = st[--sp]; // up is the parent of leaf cur: [ x' ] ( we are deleting x': "cur --> []") if (up->right == cur) { if (IS_2N(up)) { // up: [ (left) x1 cur:[ x' ] ] if (IS_2N(up->left)) { // up: [ [ u ] x1 cur:[ x' ] ] // --> [ [ u ] x1 [] ] // --> [ succ:[ u x1 ] ] LET (up->left->x2, up->x1); free_leaf (cur, Extra_words); succ = up->left; //continue to the top } else { // up: [ [ u v ] x1 cur:[ x' ] ] // --> [ [ u v ] x1 [] ] // --> [ [ u ] v [ x1 ] ] cur->x1 = cur->x2 = up->x1; DCPY (cur->x1, up->x1); LET (up->x1, up->left->x2); up->left->x2 = up->left->x1; up->x2 = up->x1; return 1; } } else { // up: [ (left) x1 (middle) x2 cur:[ x' ] ] if (IS_2N(up->middle)) { // ! ELIMINATED CASE: if (up->left->x2 == up->left->x1) // up: [ (left) x1 [ u ] x2 cur:[ x' ] ] // --> [ (left) x1 [ u ] x2 [] ] // --> [ (left) x1 [ u x2 ] ] LET (up->middle->x2, up->x2); up->x2 = up->x1; up->right = up->middle; free_leaf (cur, Extra_words); return 1; } else { // up: [ (left) x1 [ u v ] x2 cur:[ x' ] ] // --> [ (left) x1 [ u v ] x2 [] ] // --> [ (left) x1 [ u ] v [ x2 ] ] LET (cur->x1, up->x2); cur->x2 = cur->x1; LET (up->x2, up->middle->x2); up->middle->x2 = up->middle->x1; return 1; } } } else if (up->left == cur) { if (IS_2N(up)) { // up: [ cur:[ x' ] x1 (right) ] if (IS_2N(up->right)) { // up: [ cur:[ x' ] x1 succ:[ y ] ] // --> [ ? ? succ: [ x1 y ] ] DCPY (up->right->x2, up->right->x1) LET (up->right->x1, up->x1); free_leaf (cur, Extra_words); succ = up->right; //continue to the top } else { // up: [ cur:[ x' ] x1 [ y z ] ] // --> [ [] x1 [ y z ] ] // --> [ [ x1 ] y [ z ] ] LET (cur->x1, up->x1); cur->x2 = cur->x1; LET (up->x1, up->right->x1); up->x2 = up->x1; LET (up->right->x1, up->right->x2); return 1; } } else { // up: [ cur:[ x' ] x1 (middle) x2 (right) ] if (IS_2N(up->middle)) { // ! ELIMINATED CASE: if (up->right->x2 & 1) { // up: [ cur:[ x' ] x1 [ y ] x2 (right) ] // --> [ [] x1 [ y ] x2 (right) ] // --> [ [ x1 y ] x2 (right) ] DCPY (up->middle->x2, up->middle->x1); LET (up->middle->x1, up->x1); up->left = up->middle; LET (up->x1, up->x2); free_leaf (cur, Extra_words); return 1; } else { // up: [ cur:[ x' ] x1 [ y z ] x2 (right) ] // --> [ [] x1 [ y z ] x2 (right) ] // --> [ [ x1 ] y [ z ] x2 (right) ] LET (cur->x1, up->x1); cur->x2 = cur->x1; LET (up->x1, up->middle->x1); LET (up->middle->x1, up->middle->x2); return 1; } } } else { // here cur == up->middle // up: [ (left) x1 cur:[ x' ] x2 (right) ] if (IS_2N(up->left)) { // up: [ [ v ] x1 cur:[ x' ] x2 (right) ] if (IS_2N(up->right)) { // up: [ [ v ] x1 cur:[ x' ] x2 [ y ] ] // --> [ [ v ] x1 [] x2 [ y ] ] // --> [ [ v ] x1 [ x2 y ] ] DCPY (up->right->x2, up->right->x1); LET (up->right->x1, up->x2); up->x2 = up->x1; free_leaf (cur, Extra_words); return 1; } else { // up: [ [ v ] x1 cur:[ x' ] x2 [ y z ] ] // --> [ [ v ] x1 [] x2 [ y z ] ] // --> [ [ v x1 ] x2 [ y z ] ] // ! WAS: --> [ [ v ] x1 [ x2 ] y [ z ] ] LET (up->left->x2, up->x1); LET (up->x1, up->x2); free_leaf (cur, Extra_words); return 1; } } else { // up: [ [ u v ] x1 cur:[ x' ] x2 (right) ] // --> [ [ u v ] x1 [] x2 (right) ] // up: [ [ u ] v cur:[ x1 ] x2 (right) ] LET (cur->x1, up->x1); cur->x2 = cur->x1; LET (up->x1, up->left->x2); up->left->x2 = up->left->x1; return 1; } } // we come here exactly in two of the above cases: // namely, if `cur`, its parent `up` and sibling `succ` are 2-nodes // then the subtree at `up` contains only 3 elements, and after removal of x' // it must contain only two entries, which is impossible // here: succ: [.u.v.] is the new replacement for the tree at `up` // informally: "current" value of `up` is assumed to be [ succ:[.u.v.] ] // but actually `up` cannot be a "1-node", so we want to correct this while (sp) { cur = up; up = st[--sp]; // now `cur` is the root of the subtree to be replaced with `succ` // `up` is the parent of `cur` if (up->right == cur) { // up: [ ... cur:(right) ] if (IS_2N(up)) { // up: [ (left) x1 cur:(right) ] if (IS_2N(up->left)) { // up: [ [.t.] x1 cur:(right) ] // --> [ [.t.] x1 cur:[ (succ) ] ] , succ has incorrect depth! // --> [ new_succ:[.t.x1 (succ) ] ] // after that: succ is at a good place, but up is to be replaced with [ new_succ ] LET (up->left->x2, up->x1); up->left->middle = up->left->right; up->left->right = succ; free_node (cur, Extra_words); succ = up->left; } else { // up: [ [.s.t.] x1 cur:(right) ] // --> [ [.s.t.] x1 cur:[ (succ) ] ] // --> [ [.s.] t cur:[.x1 (succ) ] ] LET (cur->x1, up->x2); cur->x2 = cur->x1; cur->right = succ; cur->left = up->left->right; LET (up->x1, up->left->x2); up->x2 = up->x1; up->left->x2 = up->left->x1; up->left->right = up->left->middle; return 1; } } else { // up: [ (left) x1 (middle) x2 cur:(right) ] if (IS_2N(up->middle)) { // up: [ (left) x1 [.t.] x2 cur:[ (succ) ] ] // --> [ (left) x1 [.t.x2.(succ)] ] up->right = up->middle; LET (up->right->x2, up->x2); up->x2 = up->x1; up->right->middle = up->right->right; up->right->right = succ; free_node (cur, Extra_words); return 1; } else { // up: [ (left) x1 [.s.t.] x2 cur:[ (succ) ] ] // --> [ (left) x1 [.s.] t cur:[.x2 (succ)] ] LET (cur->x1, up->x2); cur->x2 = cur->x1; cur->right = succ; cur->left = up->middle->right; LET (up->x2, up->middle->x2); up->middle->x2 = up->middle->x1; up->middle->right = up->middle->middle; return 1; } } } else if (up->left == cur) { // up: [ cur:(left) ... ] if (IS_2N(up)) { // up: [ cur:(left) x1 (right) ] if (IS_2N(up->right)) { // up: [ cur:[ (succ) ] x1 [.y.] ] // --> [ new_succ:[ (succ) x1.y.] ] DCPY (up->right->x2, up->right->x1); LET (up->right->x1, up->x1); up->right->middle = up->right->left; up->right->left = succ; succ = up->right; free_node (cur, Extra_words); //continue to the top } else { // up: [ cur:[ (succ) ] x1 [.y.z.] ] // --> [ cur:[ (succ) x1. ] y [.z.] ] LET (cur->x1, up->x1); cur->x2 = cur->x1; cur->left = succ; cur->right = up->right->left; up->right->left = up->right->middle; LET (up->x1, up->right->x1); up->x2 = up->x1; LET (up->right->x1, up->right->x2); return 1; } } else { // up: [ cur:(left) x1 (middle) x2 (right) ] if (IS_2N(up->middle)) { // up: [ cur:[(succ)] x1 [.y.] x2 (right) ] // --> [ [(succ) x1.y.] x2 (right) ] DCPY (up->middle->x2, up->middle->x1); LET (up->middle->x1, up->x1); up->middle->middle = up->middle->left; up->middle->left = succ; up->left = up->middle; LET (up->x1, up->x2); free_node (cur, Extra_words); return 1; } else { // up: [ cur:[(succ)] x1 [.y.z.] x2 (right) ] // --> [ [(succ) x1.] y [.z.] x2 (right) ] cur->left = succ; cur->right = up->middle->left; LET (cur->x1, up->x1); cur->x2 = cur->x1; up->middle->left = up->middle->middle; LET (up->x1, up->middle->x1); LET (up->middle->x1, up->middle->x2); return 1; } } } else { // now up->middle == cur // up: [ (left) x1 cur:[(succ)] x2 (right) ] if (IS_2N(up->left)) { // up: [ [.s.] x1 cur:[(succ)] x2 (right) ] // --> [ [.s.x1 (succ)] x2 (right) ] LET (up->left->x2, up->x1); up->left->middle = up->left->right; up->left->right = succ; LET (up->x1, up->x2); free_node (cur, Extra_words); return 1; } else { // up: [ [.s.t.] x1 cur:[(succ)] x2 (right) ] // --> [ [.s.] t [.x1 (succ)] x2 (right) ] LET (cur->x1, up->x1); cur->x2 = cur->x1; cur->right = succ; cur->left = up->left->right; up->left->right = up->left->middle; LET (up->x1, up->left->x2); up->left->x2 = up->left->x1; return 1; } } } // If we come here, this means that `up` is the root // and we want to replace it with "1-node" [ (succ) ] // Instead, we decrease the depth by one, and make `succ` the new root free_node (up, Extra_words); R->root = succ; R->depth--; return 1; }
IoObject *IoYajlGen_closeMap(IoYajlGen *self, IoObject *locals, IoMessage *m) { yajl_gen_map_close(DATA(self)); return self; }
int main(int argc, char **argv) { int c = 0; llist_t* list = 0; node_t* aux = 0; list = ll_create(); ll_initialize(list, free, compare_int_data); /* 0...9 */ for(; c < 10; c++) ll_add_last(list, create_node( create_int_data(c) ) ); /* 10 0...9 */ ll_add_first(list, create_node( create_int_data(c) ) ); /* 11 10 0...9 */ ll_add_first(list, create_node( create_int_data(++c) ) ); /* 11 10 12 0...9 */ ll_add_before(list, list->first->next->next, create_node( create_int_data(++c) ) ); /* 11 10 12 0...8 13 9 */ ll_add_after(list, list->last->prev, create_node( create_int_data(++c) )); /* 11 10 12 0...8 13 14 9 */ ll_add_after(list, list->last->prev, create_node( create_int_data(++c) )); /* 11 12 0...8 13 14 9 */ ll_remove(list, list->first->next, DESTROYNODE ); /* 11 12 0...8 13 14 */ ll_remove(list, list->last, DESTROYNODE); /* 12 0...8 13 14 */ ll_remove(list, list->first, DESTROYNODE); /* to test "NOTDESTROY" option*/ aux = list->last->prev; /* 12 0...8 14 */ ll_remove(list, list->last->prev, NOTDESTROY); printf("\n"); /* Forward: 12 0...8 14 */ ll_traverse(list, print_int_data, FORWARDTRAVERSE); printf("\n"); /* Backward: 14 8...0 12 */ ll_traverse(list, print_int_data, BACKWARDTRAVERSE); printf("\n\n"); /* Destroy node "13"*/ free_node(aux, list->free_data); printf("\n"); /* Deleted node, is not found*/ int a = 10; aux = ll_search_node(list, &a); if(aux != NULL) printf("NODE: %p DATA: %d\n", aux ,*(int*)DATA(aux)); a = 4; aux = ll_search_node(list, &a); if(aux != NULL) printf("NODE: %p DATA: %d\n", aux ,*(int*)DATA(aux)); ll_free(list); list = 0; return EXIT_SUCCESS; }
// does not check whether the element is already there static void tree23_insert (tree23_root_t *R, int x, int *Data) { tree23_t *st[40]; int x_Data[8]; tree23_t *cur, *s, *l; int sp, extra_words = R->extra_words; #define Extra_words extra_words #define x1_Data extra-Extra_words #define x2_Data extra-Extra_words*2 #define DATA(__x) (__x##_Data) #define CPY(__x,__y) {if(Extra_words>0) {memcpy(__x,__y,Extra_words*4);}} #define DCPY(__x,__y) CPY(DATA(__x),DATA(__y)) #define LET(__x,__y) {__x = __y; DCPY(__x,__y);} #define IS_2N(__t) ((__t)->x1 == (__t)->x2) #define IS_3N(__t) (!IS_2N(__t)) #define LEAF(__t) ((tree23_leaf_t *)(__t)) //empty tree case if (!R->root) { R->root = new_leaf (x, extra_words); CPY(DATA(R->root->x1), Data); R->depth = 0; return; } sp = 0; cur = R->root; while (sp < R->depth) { st[sp++] = cur; if (x < cur->x1) { cur = cur->left; } else if (x > cur->x2) { cur = cur->right; } else { cur = cur->middle; } } //leaf split if (IS_3N(cur)) { //case 1. two-element leaf: have cur:[ B D ] if (x < cur->x1) { // cur:[ B D ] + x:A --> [ A B D ] --> (new)s:[ A ] new_x:B (cur)l:[ D ] s = new_leaf (x, Extra_words); CPY (DATA(s->x1), Data) LET (x, cur->x1); LET (cur->x1, cur->x2); l = cur; } else if (x > cur->x2) { // cur:[ B D ] + x:E --> [ A D E ] --> (cur)s:[ B ] new_x:D (new)l:[ E ] l = new_leaf (x, Extra_words); CPY (DATA(l->x1), Data) LET (x, cur->x2) cur->x2 = cur->x1; s = cur; } else { // cur:[ B D ] + x:C --> [ A C E ] --> (cur)s:[ B ] new_x:C (new)l:[ D ] l = new_leaf (cur->x2, Extra_words); CPY (DATA(l->x1), DATA(cur->x2)) CPY (DATA(x), Data); cur->x2 = cur->x1; s = cur; } } else { //case 2. single-element leaf: have cur:[ B ] if (x < cur->x1) { // cur:[ B ] + x:A --> cur:[ A B ] LET (cur->x2, cur->x1); cur->x1 = x; CPY (DATA(cur->x1), Data); } else { // cur:[ B ] + x:C --> cur:[ B C ] cur->x2 = x; CPY (DATA(cur->x2), Data); } return; } while (sp) { cur = st[--sp]; // here cur is a parent node cur: [ ... old_cur:[.E.G.] ... ] // we are replacing its subtree [.E.G.] with two: s:[.E.] x:F l:[.G.] if (IS_3N(cur)) { //case 1. two-element internal node // cur: [ (left) x1 (middle) x2 (right) ] if (x < cur->x1) { // s l middle right // cur: [ old_cur:[.E.G.] x1:H [.I.] x2:J [.K.] ] // --> [ s:[.E.] x:F l:[.G.] x1:H [.I.] J [.K.] ] // --> (new)new_s:[ s:[.E.] x:F l:[.G.] ] new_x:H (cur)new_l:[ [.I.] J [.K.] ] s = new_node2 (x, s, l, Extra_words); DCPY(s->x1, x); LET (x, cur->x1); LET (cur->x1, cur->x2); cur->left = cur->middle; l = cur; } else if (x > cur->x2) { // left middle s l // cur: [ [.A.] B [.C.] D old_cur:[.E.G.] ] // --> [ [.A.] x1:B [.C.] x2:D s:[.E.] x:F l:[.G.] ] // --> (cur)new_s:[ [.A.] x1:B [.C.] ] new_x:D (new)new_l:[ s:[.E.] x:F l:[.G.] ] l = new_node2 (x, s, l, Extra_words); DCPY(l->x1, x); LET (x, cur->x2); cur->right = cur->middle; cur->x2 = cur->x1; s = cur; } else { //left s l right // cur: [ [.C.] x1:D old_cur:[.E.G.] x2:H [.I.] ] // --> [ [.C.] x1:D s:[.E.] x:F l:[.G.] x2:H [.I.] ] // --> (cur)new_s:[ [.C.] x1:D s:[.E.] ] new_x:F (new)new_l:[l:[.G.] x2:H [.I.] ] l = new_node2 (cur->x2, l, cur->right, Extra_words); DCPY(l->x1, cur->x2); cur->right = s; cur->x2 = cur->x1; s = cur; } } else { //case 2. single-element internal node // cur: [ (left) x1=x2 (right) ] if (x < cur->x1) { // s l right // cur: [ old_cur:[.E.G.] x1:H [.I.] ] // --> [ s:[.E.] x:F l:[.G.] x1:H [.I.] ] cur->left = s; cur->middle = l; cur->x1 = x; DCPY(cur->x2, cur->x1); DCPY(cur->x1, x); } else { //left s l // cur: [ [.C.] x1:D old_cur:[.E.G.] ] // --> [ [.C.] x1:D s:[.E.] x:F l:[.G.] ] cur->middle = s; cur->right = l; LET(cur->x2, x); } return; } } //root split // here s:[.E.] x:F l:[.G.] comes to the top // create new root [ [.E.] F [.G.] ] R->root = new_node2 (x, s, l, Extra_words); R->depth++; CPY (DATA(R->root->x1), Data); }
****************************************************************************/ /*************************************************************************** * Module m_request_name * * Routines to handle external names of menu requests * ***************************************************************************/ #include "menu.priv.h" MODULE_ID("$Id: m_req_name.c,v 1.23 2015/04/04 18:00:23 tom Exp $") #define DATA(s) { s } static const char request_names[MAX_MENU_COMMAND - MIN_MENU_COMMAND + 1][14] = { DATA("LEFT_ITEM"), DATA("RIGHT_ITEM"), DATA("UP_ITEM"), DATA("DOWN_ITEM"), DATA("SCR_ULINE"), DATA("SCR_DLINE"), DATA("SCR_DPAGE"), DATA("SCR_UPAGE"), DATA("FIRST_ITEM"), DATA("LAST_ITEM"), DATA("NEXT_ITEM"), DATA("PREV_ITEM"), DATA("TOGGLE_ITEM"), DATA("CLEAR_PATTERN"), DATA("BACK_PATTERN"), DATA("NEXT_MATCH"),
IoCFFIArray *IoCFFIArray_rawClone(IoCFFIArray *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, io_calloc(1, sizeof(IoCFFIArrayData))); memset(DATA(self), 0, sizeof(IoCFFIArrayData)); IoObject* arrayType = IoObject_getSlot_(proto, IOSYMBOL("arrayType")); if ( !ISNIL(arrayType) ) { DATA(self)->ffiType = DATA(proto)->ffiType; DATA(self)->itemSize = DATA(proto)->itemSize; DATA(self)->arraySize = DATA(proto)->arraySize; DATA(self)->buffer = io_calloc(DATA(self)->arraySize, DATA(self)->itemSize); DATA(self)->needToFreeBuffer = 1; } return self; }
IoNumber *IoCFFIArray_size(IoCFFIArray *self, IoObject *locals, IoMessage *m) { return IONUMBER(DATA(self)->arraySize); }
/* Gets the number of dropped packets */ static uint64_t dag_get_dropped_packets(libtrace_t *trace) { if (!trace->format_data) return (uint64_t)-1; return DATA(trace)->drops; }
IoObject *IoYajlGen_closeArray(IoYajlGen *self, IoObject *locals, IoMessage *m) { yajl_gen_array_close(DATA(self)); return self; }
IoNumber *IoNumber_rawClone(IoNumber *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); DATA(self) = DATA(proto); return self; }
void IoYajlGen_free(IoYajlGen *self) { yajl_gen_free(DATA(self)); }
void IoNumber_copyFrom_(IoNumber *self, IoNumber *number) { DATA(self) = DATA(number); }
IoObject *IoYajlGen_pushNull(IoYajlGen *self, IoObject *locals, IoMessage *m) { yajl_gen_null(DATA(self)); return self; }
long IoNumber_asLong(IoNumber *self) { return (long)(DATA(self)); }
IoObject *IoYajlGen_pushInteger(IoYajlGen *self, IoObject *locals, IoMessage *m) { int i = IoMessage_locals_intArgAt_(m, locals, 0); yajl_gen_integer(DATA(self), i); return self; }
double IoNumber_asDouble(IoNumber *self) { return (double)DATA(self); }
IoObject *IoYajlGen_pushDouble(IoYajlGen *self, IoObject *locals, IoMessage *m) { double d = IoMessage_locals_doubleArgAt_(m, locals, 0); yajl_gen_double(DATA(self), d); return self; }
IoNumber *IoNumber_proto(void *state) { IoMethodTable methodTable[] = { {"asNumber", IoNumber_asNumber}, {"+", IoNumber_add_}, {"-", IoNumber_subtract}, {"*", IoNumber_multiply}, {"/", IoNumber_divide}, //{"print", IoNumber_printNumber}, {"asString", IoNumber_asString}, {"asBuffer", IoNumber_asBuffer}, {"asCharacter", IoNumber_asCharacter}, {"asUint32Buffer", IoNumber_asUint32Buffer}, //{"asDate", IoNumber_asDate}, {"abs", IoNumber_abs}, {"acos", IoNumber_acos}, {"asin", IoNumber_asin}, {"atan", IoNumber_atan}, {"atan2", IoNumber_atan2}, {"ceil", IoNumber_ceil}, {"cos", IoNumber_cos}, // {"deg", IoNumber_deg} {"exp", IoNumber_exp}, {"factorial", IoNumber_factorial}, {"floor", IoNumber_floor}, {"log", IoNumber_log}, {"log2", IoNumber_log2}, {"log10", IoNumber_log10}, {"max", IoNumber_max}, {"min", IoNumber_min}, {"%", IoNumber_mod}, {"mod", IoNumber_mod}, {"**", IoNumber_pow}, {"pow", IoNumber_pow}, {"round", IoNumber_round}, {"roundDown", IoNumber_roundDown}, {"sin", IoNumber_sin}, {"sqrt", IoNumber_sqrt}, {"squared", IoNumber_squared}, {"cubed", IoNumber_cubed}, {"tan", IoNumber_tan}, {"toggle", IoNumber_toggle}, // logic operations {"&", IoNumber_bitwiseAnd}, {"|", IoNumber_bitwiseOr}, {"^", IoNumber_bitwiseXor}, {"<<", IoNumber_bitShiftLeft}, {">>", IoNumber_bitShiftRight}, {"bitwiseAnd", IoNumber_bitwiseAnd}, {"bitwiseOr", IoNumber_bitwiseOr}, {"bitwiseXor", IoNumber_bitwiseXor}, {"bitwiseComplement", IoNumber_bitwiseComplement}, {"shiftLeft", IoNumber_bitShiftLeft}, {"shiftRight", IoNumber_bitShiftRight}, // even and odd {"isEven", IoNumber_isEven}, {"isOdd", IoNumber_isOdd}, // character operations {"isAlphaNumeric", IoNumber_isAlphaNumeric}, {"isLetter", IoNumber_isLetter}, {"isControlCharacter", IoNumber_isControlCharacter}, {"isDigit", IoNumber_isDigit}, {"isGraph", IoNumber_isGraph}, {"isLowercase", IoNumber_isLowercase}, {"isUppercase", IoNumber_isUppercase}, {"isPrint", IoNumber_isPrint}, {"isPunctuation", IoNumber_isPunctuation}, {"isSpace", IoNumber_isSpace}, {"isHexDigit", IoNumber_isHexDigit}, {"asLowercase", IoNumber_asLowercase}, {"asUppercase", IoNumber_asUppercase}, {"between", IoNumber_between}, {"clip", IoNumber_clip}, {"negate", IoNumber_negate}, {"at", IoNumber_at}, {"integerMax", IoNumber_integerMax}, {"integerMin", IoNumber_integerMin}, {"longMax", IoNumber_longMax}, {"longMin", IoNumber_longMin}, {"shortMax", IoNumber_shortMax}, {"shortMin", IoNumber_shortMin}, {"unsignedLongMax", IoNumber_unsignedLongMax}, {"unsignedIntMax", IoNumber_unsignedIntMax}, {"floatMax", IoNumber_floatMax}, {"floatMin", IoNumber_floatMin}, {"isNan", IoNumber_isNan}, {"repeat", IoNumber_repeat}, {NULL, NULL}, }; IoObject *self = IoObject_new(state); IoObject_tag_(self, IoNumber_newTag(state)); DATA(self) = 0; IoState_registerProtoWithFunc_((IoState *)state, self, IoNumber_proto); IoObject_addMethodTable_(self, methodTable); return self; }
IoObject *IoYajlGen_pushBool(IoYajlGen *self, IoObject *locals, IoMessage *m) { int b = IoMessage_locals_boolArgAt_(m, locals, 0); yajl_gen_bool(DATA(self), b); return self; }
void IoSecureServer_free(IoSecureServer *self) { SSL_CTX_free(OCTX(self)); free(DATA(self)); }
/*** Verifica se a copia pode executar normalmente. Parametros: nenhum Retorno: PE_INSTALA - Copia nao personalizada PE_DATA - Copia Out of date (estouro de data) PE_OK - Pode executar numa boa. ***/ int CheckForRun() { int iIsTimeBomb = FALSE; int check = 0; int chk_check; char data[MAXDATA+1]; char szBufAux[MAXDATA+1]; struct tm *dma; struct tm data_aux; time_t t1; time_t t2; int num_dias; long tloc; if( !iIsDecrypt ){ check = Decriptografa( DATAINST(str_pers), CHECKSUM( str_pers ) ); iIsDecrypt = TRUE; chk_check = ((CHECKSUM( str_pers )[0]&0xFF)<<8) | (CHECKSUM( str_pers )[1] & 0xFF); chk_check &= 0xFFFF; if( check != chk_check ) { return( PE_INSTALA ); } } if( PERS( str_pers ) != PE_PERS ){ return( PE_INSTALA ); // Copia nao personalizada } // Calcula os deslocamentos para DATA, NUMTTY, SERIE, ETC. if( CalculaDeslocamentos( SERIE( str_pers ) ) != PE_OK ){ return( PE_INSTALA ); // algum pau no numero de serie } /* Verificando Time Bomb */ if( DATA( str_pers )[0] == '0' ){ iIsTimeBomb = TRUE; } if( iIsTimeBomb ){ /* Tem time bomb */ t1 = time( &t1 ); /* Dia de hoje em segundos */ memset( &data_aux, 0, sizeof(data_aux) ); // Pego o dia da instalacao do produto e somo o numero de dias // do time bomb. Tudo em segundos. data_aux.tm_year = (1000*(DATAINST(str_pers)[0]-'0')) + (100*(DATAINST(str_pers)[1]-'0')) + (10*(DATAINST(str_pers)[2]-'0')) + DATAINST(str_pers)[3] - '0' - 1900; data_aux.tm_mon = (10* (DATAINST(str_pers)[4]-'0') ) + DATAINST(str_pers)[5] - '0' - 1 ; data_aux.tm_mday = (10* (DATAINST(str_pers)[6]-'0') ) + DATAINST(str_pers)[7] - '0'; t2 = mktime( &data_aux ); /* Dia da instalacao do produto */ if( t1 < t2 ) { /* O sacana mudou a data voltou a data para tras * para rodar o aplicativo. * Pau nele. */ return( PE_DATA ); } /* o dia de instalacao nao guarda horas/minutos e portanto * eh como se tivessemos instalado a meia noite do dia. * por isso, dah um dia de graca. Pegamos agora o * numero de dias do time bomb. */ istrncpychar( data, DATA(str_pers), MAXDATA, '.' ); t2 += ( atol(data) + 1 ) * 3600 * 24; num_dias = CmpDatas( t2, t1 ); if( num_dias < 0 ) { return( PE_DATA ); } return( PE_OK ); } if( isdigit( DATA(str_pers)[0] ) && DATA(str_pers)[0]>'0' ){ /* Eh uma copia demo com data absoluta. VAMOS VERIFICAR!!! */ time( &tloc ); dma = localtime( &tloc ); sprintf( szBufAux, "%04.2d%02.2d", dma->tm_year + 1900, dma->tm_mon + 1 ); // MAXDATA deve ser 6 ; yyyymm. Assim mesmo nos protegemos procurando o '.' istrncpychar( data, DATA(str_pers), MAXDATA, '.' ); if( strncmp( szBufAux, data, MAXDATA ) > 0 ) { return( PE_DATA ); } return( PE_OK ); } // Qualquer outra coisa no campo data indica uma copia // Full (nao demo). Logo, retornamos PE_OK para a galera. return( PE_OK ); }
/** Read a line of data and store in d. @return 0 on success */ int datareader_tmy3_data(DataReader *d){ //CONSOLE_DEBUG("Reading data, i = %d",d->i); unsigned year,month,day,hour,minute; Tmy3Point row; // in the following 'C' are char fiels, 'I' are integer fields; // the suffix 'e' means error/uncertainty and 's' means source of data. #define NUMFIELDS(C,I,X) I(3_EGHI) X I(4_EDNI) \ X I(5_GHI) X C(6_GHIs) X I(7_GHIe) \ X I(8_DNI) X C(9_DNIs) X I(10_DNIe) \ X I(11_DiffHI) X C(12_DiffHIs) X I(13_DiffHIe) \ X I(14_GHIll) X C(15_GHIlls) X I(16_GHIlle) \ X I(17_DNIll) X C(18_DNIlls) X I(19_DNIlle) \ X I(20_DiffHIll) X C(21_DiffHIlls) X I(22_DiffHIlle) \ X I(23_ZenLum) X C(24_ZenLums) X I(25_ZenLume) \ X I(26_TotCov) X C(27_TotCovs) X C(28_TotCove) \ X I(29_OpaqCov) X C(30_OpaqCovs) X C(31_OpenCove) \ X I(32_T) X C(33_Ts) X C(34_Te) \ X I(35_Tdew) X C(36_Tdews) X C(37_Tdewe) \ X I(38_RH) X C(39_RHs) X C(40_RHe) \ X I(41_P) X C(42_Ps) X C(43_Pe) \ X I(44_WD) X C(45_WDs) X C(46_WDe) \ X I(47_WS) X C(48_WSs) X C(49_WSe) \ X I(50_HViz) X C(51_HVizs) X C(52_HVize) \ X I(53_HViz) X C(54_HVizs) X C(55_HVize) \ X I(56_HViz) X C(57_HVizs) X C(58_HVize) \ X I(59_HViz) X C(60_HVizs) X C(61_HVize) \ X I(62_HViz) X C(63_HVizs) X C(64_HVize) \ X I(65_RainDepth) X I(66_RainDuration) X C(67_Rains) X C(68_Raine) #define CHARDECL(NAME) char tmy3_field_##NAME; #define NUMDECL(NAME) double tmy3_field_##NAME; #define NUTHIN_HERE NUMFIELDS(CHARDECL,NUMDECL,NUTHIN_HERE); #undef CHARDECL #undef NUMDECL #undef NUTHIN_HERE // TODO what to do with 'missing' values?? parse *p = DATA(d)->p; #define PARSEINT(NAME) parseDouble(p,&tmy3_field_##NAME) #define PARSECHAR(NAME) parseAChar(p,&tmy3_field_##NAME) #define ANDTHEN && parseThisString(p,",") && // example row: // 01/25/1988,12:00,821,1411,530,1,13,580,1,9,192,1,13,565,1,13,593,1,9,219,1,13,442,1,21,10,A,7,4,A,7,13.3,A,7,-8.9,A,7,21,A,7,960,A,7,60,A,7,3.6,A,7,80500,A,7,77777,A,7,0.5,E,8,0.030,F,8,-9900.000,?,0,-9900,-9900,?,0 if(!( (( /* parse the date and time first... */ parseNumber(p,&month) && parseThisString(p,"/") && parseNumber(p,&day) && parseThisString(p,"/") && parseNumber(p,&year) && parseThisString(p,",") && parseNumber(p,&hour) && parseThisString(p,":") && parseNumber(p,&minute) && parseThisString(p,",") /* then come the data fields */ && NUMFIELDS(PARSECHAR,PARSEINT,ANDTHEN) ) || parseError(p,"Missing/incorrect data field") ) && ( parseEOL(p) || parseError(p,"Expected end-of-line") ) )){ ERROR_REPORTER_HERE(ASC_PROG_ERROR,"Failed to parse E/E data file"); return 1; }; #undef ANDTHEN #undef PARSEINT #undef PARSECHAR /* TODO add check for data for Feb 29... just in case */ // ignore year, so that data sampled from a leap year isn't somehow offset. row.t = ((day_of_year(day,month) - 1)*24.0 + hour)*3600.0 + minute*60.; row.T = tmy3_field_32_T + 273.15 /* convert to K */; row.p = tmy3_field_41_P * 100.; row.rh = tmy3_field_38_RH * 0.01; row.DNI = tmy3_field_8_DNI * 1.; row.GHI = tmy3_field_5_GHI * 1.; row.v_wind = tmy3_field_47_WS * 1.; row.d_wind = tmy3_field_44_WD * 3.14159265358 / 180.; DATA(d)->rows[d->i] = row; //CONSOLE_DEBUG("Read i = %d, t = %f d, T = %.1f°C, rh = %.1f %",d->i,row.t / 3600. / 24., T, row.rh*100); d->i++; return 0; }
static void stdio_close(io_t *io) { close(DATA(io)->fd); free(io->data); free(io); }