void fwd (ChimeraState * chstate, Message * msg) { Key cur, dest; char deststr[64]; char curstr[64]; sscanf (msg->payload, "%s %s", curstr, deststr); str_to_key (curstr, &cur); str_to_key (deststr, &dest); fprintf (stderr, "message to %s routed by %s\n", dest.keystr, cur.keystr); if (key_equal (dest, current)) { hops++; } }
void del (ChimeraState * chstate, Message * msg) { Key cur, dest; char deststr[64]; char curstr[64]; sscanf (msg->payload, "%s %s", curstr, deststr); str_to_key (curstr, &cur); str_to_key (deststr, &dest); fprintf (stderr, "message to %s routes delivered to %s\n", dest.keystr, cur.keystr); if (key_equal (dest, current)) { sema_v (sem); } }
void gethostinfo (ChimeraHost * CHost) { char tmp[64]; CHost->name = (char *) malloc (sizeof (char) * 64); printf ("Enter key: "); scanf ("%s", tmp); str_to_key (tmp, &(CHost->key)); printf ("Key :"); key_print (CHost->key); }
JRB read_hosts (char *fn, int *nhosts) { FILE *fp; char s[256]; char hn[128]; int port; Key key; JRB hosts; Host *host; char keyinput[64]; fp = fopen (fn, "r"); if (fp == NULL) { perror (fn); exit (1); } hosts = make_jrb (); *nhosts = 0; while (fgets (s, 256, fp) != NULL) { sscanf (s, "%s %d %s", hn, &port, keyinput); host = (Host *) malloc (sizeof (Host)); host->name = strdup (hn); host->port = port; str_to_key (keyinput, &key); key_assign (&(host->key), key); sprintf (s, "%s:%d", hn, port); host->hnp = strdup (s); host->pid = 0; jrb_insert_str (hosts, strdup (s), new_jval_v (host)); *nhosts++; } fclose (fp); return (hosts); }
int mdhim_mysql_get_prev(void *dbh, void **key, int *key_len, void **data, int32_t *data_len){ struct MDI *x = (struct MDI *)(dbh); MYSQL *db = x->msqdb; if (db == NULL) { fprintf(stderr, "%s\n", mysql_error(db)); return MDHIM_DB_ERROR; } int ret = MDHIM_SUCCESS; void *old_key; struct timeval start, end; int key_lg; if (!key_len){ key_lg = 0; *key = NULL;} else key_lg = *key_len; char get_prev[MYSQL_BUFFER+key_lg]; MYSQL_RES *key_result; MYSQL_ROW key_row; void *msl_data; void *msl_key; char *table_name; //Init the data to return gettimeofday(&start, NULL); old_key = *key; char *key_copy; if (x->msqkt == MDHIM_STRING_KEY || x->msqkt == MDHIM_BYTE_KEY) { if (old_key) key_copy = sb_key_copy(db, (char*)old_key, *key_len); } //Start with Keys/data being null if (key_len) { *key = NULL; *key_len = 0; } else{ *key = NULL; key_len = &key_lg; } *data = NULL; *data_len = 0; table_name = x->table; //Get the Key/Value from the tables and if there was no old key, use the last one. if (!old_key){ snprintf(get_prev, sizeof(char)*(MYSQL_BUFFER+*key_len),"Select * from %s where Id = (Select max(Id) From %s)", table_name,table_name); if(mysql_query(db, get_prev)) { mlog(MDHIM_SERVER_DBG2, "Could not get the previous key/value"); goto error; } } else { switch(x->msqkt){ case MDHIM_STRING_KEY: snprintf(get_prev, sizeof(char)*(MYSQL_BUFFER+*key_len), "Select * From %s where Id = (Select max(Id) from %s where Id < '%s')", table_name,table_name, key_copy); free(key_copy); break; case MDHIM_FLOAT_KEY: snprintf(get_prev, sizeof(char)*(MYSQL_BUFFER+*key_len),"Select * From %s where Id = (Select max(Id) from %s where Id <%f)", table_name,table_name, *((float*)old_key)); break; case MDHIM_DOUBLE_KEY: snprintf(get_prev, sizeof(char)*(MYSQL_BUFFER+*key_len),"Select * From %s where Id = (Select max(Id) from %s where Id <%.9g)", table_name,table_name, *((double*)old_key)); break; case MDHIM_INT_KEY: snprintf(get_prev, sizeof(char)*(MYSQL_BUFFER+*key_len),"Select * From %s where Id = (Select max(Id) from %s where Id <%d)", table_name,table_name, *((int*)old_key)); break; case MDHIM_LONG_INT_KEY: snprintf(get_prev, sizeof(char)*(MYSQL_BUFFER+*key_len),"Select * From %s where Id = (Select max(Id) from %s where Id <%ld)", table_name,table_name, *((long*)old_key)); break; case MDHIM_BYTE_KEY: snprintf(get_prev, sizeof(char)*(MYSQL_BUFFER+*key_len),"Select * From %s where Id = (Select max(Id) from %s where Id < '%s')", table_name,table_name, key_copy); free(key_copy); break; } //Query the database if(mysql_query(db, get_prev)) { mlog(MDHIM_SERVER_DBG2, "Could not get the previous key/value"); goto error; } } //STore the result, you MUST use mysql_store_result because of it being parallel key_result = mysql_store_result(db); if (key_result->row_count == 0) { mlog(MDHIM_SERVER_DBG2, "Could not get mysql result"); goto error; } //Fetch row and get data from database key_row = mysql_fetch_row(key_result); unsigned long *dl = mysql_fetch_lengths(key_result); int r_size; msl_key = str_to_key(key_row, x->msqkt, &r_size); *key_len = r_size; *data_len = dl[1]; msl_data = key_row[1]; //Allocate data and key to mdhim program if (key_row && *key_row) { *key = malloc(*key_len+1); memset(*key, 0, *key_len+1); memcpy(*key, msl_key, *key_len); *data = malloc(*data_len); memset(*data, 0, *data_len); memcpy(*data, msl_data, *data_len); //printf("\nCopied here\n"); } else { *key = NULL; *key_len = 0; *data = NULL; *data_len = 0; } mysql_free_result(key_result); //End timing gettimeofday(&end, NULL); mlog(MDHIM_SERVER_DBG, "Took: %d seconds to get the prev record", (int) (end.tv_sec - start.tv_sec)); return ret; error: *key = NULL; *key_len = 0; *data = NULL; *data_len = 0; return MDHIM_DB_ERROR; }
void handle_msg(int *msg) { WINDOWP window; wake_mouse(); window= get_window(msg[3]); /* Zugeh�riges Fenster */ switch (msg[0]) /* Art der Nachricht */ { case MN_SELECTED: if (makro_rec) /* Makro wird Tastendruck vorgegaukelt */ { int kstate, kreturn; char str[50]; get_string(menu, msg[4], str); if (str_to_key(str, &kstate, &kreturn)) { kstate |= (kstate & 3); to_makro(kstate, kreturn); } } handle_menu(msg[3], msg[4], menu_ctrl); menu_ctrl = FALSE; break; case WM_REDRAW : if (msg[3] == akt_handle) redraw_aktion(); else redraw_window (window, (GRECT*)(msg+4)); break; case WM_CLOSED : do_icon(window->handle, DO_DELETE); break; case WM_FULLED : full_window (window); break; case WM_ARROWED : arrow_window (window, msg[4], 1); break; case WM_HSLID : h_slider (window, msg[4]); break; case WM_VSLID : v_slider (window, msg[4]); break; case WM_SIZED : size_window (window, (GRECT*)(msg+4), TRUE); break; case WM_MOVED : move_window (window, (GRECT*)(msg+4)); break; case WM_NEWTOP : /* Fenster von qed ist irgendwie nach oben gekommen */ case WM_ONTOP : ontop_window(window); break; case WM_TOPPED : top_window (window); break; case WM_UNTOPPED: /* qed hat jetzt nicht mehr das Top-Fenster */ untop_window (window); break; case WM_BOTTOMED: /* AES 4.00 MagiC 3 : Fenster nach hinten */ case WM_M_BDROPPED : /* Magic 2 */ bottom_window (window, msg[0]); break; case WM_ICONIFY: iconify_window(window, (GRECT*)(msg+4)); break; case WM_ALLICONIFY: all_iconify(window, (GRECT*)(msg+4)); break; case WM_UNICONIFY: if (all_iconified) all_uniconify(NULL, (GRECT*)(msg+4)); else uniconify_window(window, (GRECT*)(msg+4)); break; case WM_SHADED : case WM_UNSHADED : shade_window(window, msg[0]); break; case AP_TERM: if (all_iconified) all_uniconify(NULL, NULL); quick_close = TRUE; if (prepare_quit()) do_quit(); break; case AP_DRAGDROP : if (all_iconified) Bconout(2, 7); else handle_dd(msg); break; case SC_CHANGED : /* * Ignorieren, da wir vor dem Paste sowieso neu laden. */ break; case VA_START : case VA_PROTOSTATUS : case VA_DRAG_COMPLETE : case VA_DRAGACCWIND : case AV_SENDKEY : handle_av(msg); break; case SE_INIT: case SE_OK: case SE_ACK: case SE_OPEN: case SE_ERROR: case SE_ERRFILE: case SE_PROJECT: case SE_QUIT: case SE_TERMINATE: case SE_CLOSE : case SE_MENU : if (all_iconified) all_uniconify(NULL, NULL); handle_se(msg); break; case OLGA_INIT : case OLE_NEW : case OLGA_ACK : case OLE_EXIT : handle_olga(msg); break; case SH_WDRAW: /* schickt Freedom st�ndig */ case DHST_ACK: /* SMU antwortet */ /* ignore */ break; case FONT_CHANGED : if (msg[4] != 0) font_id = msg[4]; if (msg[5] != 0) font_pts = msg[5]; font_change(); break; default: if (debug_level) { char str[12]; int d, i, id; if ((appl_xgetinfo(4, &d, &d, &i, &d)) && (i == 1)) /* gibts appl_search? */ { i = appl_search(0, str, &d, &id); while (i != 0) { if (id == msg[1]) break; i = appl_search( 1, str, &d, &id); } } else { strcpy(str, ""); id = msg[1]; } debug("Unbekannte Msg %d (0x%X) von %s (%d)\n", msg[0], msg[0], str, id); } break; } }