static void dissect_ata_pdu(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gboolean response, guint32 tag) { proto_item *tmp_item; guint8 aflags; guint64 lba; ata_info_t *ata_info=NULL; conversation_t *conversation; /* only create a conversation for ATA commands */ conversation = find_or_create_conversation(pinfo); if( !(pinfo->fd->flags.visited) ){ if(!response){ ata_info_t *tmp_ata_info; /* first time we see this request so add a struct for request/response matching */ ata_info=wmem_new(wmem_file_scope(), ata_info_t); ata_info->tag=tag; ata_info->conversation=conversation; ata_info->request_frame=pinfo->fd->num; ata_info->response_frame=0; ata_info->cmd=tvb_get_guint8(tvb, offset+3); ata_info->req_time=pinfo->fd->abs_ts; tmp_ata_info=(ata_info_t *)g_hash_table_lookup(ata_cmd_unmatched, ata_info); if(tmp_ata_info){ g_hash_table_remove(ata_cmd_unmatched, tmp_ata_info); } g_hash_table_insert(ata_cmd_unmatched, ata_info, ata_info); } else { ata_info_t tmp_ata_info; /* first time we see this response so see if we can match it with a request */ tmp_ata_info.tag=tag; tmp_ata_info.conversation=conversation; ata_info=(ata_info_t *)g_hash_table_lookup(ata_cmd_unmatched, &tmp_ata_info); /* woo hoo we could, so no need to store this in unmatched any more, move both request and response to the matched table */ if(ata_info){ ata_info->response_frame=pinfo->fd->num; g_hash_table_remove(ata_cmd_unmatched, ata_info); g_hash_table_insert(ata_cmd_matched, GUINT_TO_POINTER(ata_info->request_frame), ata_info); g_hash_table_insert(ata_cmd_matched, GUINT_TO_POINTER(ata_info->response_frame), ata_info); } } } else { ata_info=(ata_info_t *)g_hash_table_lookup(ata_cmd_matched, GUINT_TO_POINTER(pinfo->fd->num)); } if(ata_info){ if(response){ if(ata_info->request_frame){ nstime_t delta_ts; tmp_item=proto_tree_add_uint(tree, hf_aoe_response_to, tvb, 0, 0, ata_info->request_frame); PROTO_ITEM_SET_GENERATED(tmp_item); nstime_delta(&delta_ts, &pinfo->fd->abs_ts, &ata_info->req_time); tmp_item=proto_tree_add_time(tree, hf_aoe_time, tvb, offset, 0, &delta_ts); PROTO_ITEM_SET_GENERATED(tmp_item); } } else { if(ata_info->response_frame){ tmp_item=proto_tree_add_uint(tree, hf_aoe_response_in, tvb, 0, 0, ata_info->response_frame); PROTO_ITEM_SET_GENERATED(tmp_item); } } } /* aflags */ aflags=tvb_get_guint8(tvb, offset); proto_tree_add_item(tree, hf_aoe_aflags_e, tvb, offset, 1, ENC_BIG_ENDIAN); if(aflags&AOE_AFLAGS_E){ proto_tree_add_item(tree, hf_aoe_aflags_d, tvb, offset, 1, ENC_BIG_ENDIAN); } if(aflags&AOE_AFLAGS_W){ proto_tree_add_item(tree, hf_aoe_aflags_a, tvb, offset, 1, ENC_BIG_ENDIAN); } proto_tree_add_item(tree, hf_aoe_aflags_w, tvb, offset, 1, ENC_BIG_ENDIAN); offset++; /* err/feature */ proto_tree_add_item(tree, hf_aoe_err_feature, tvb, offset, 1, ENC_BIG_ENDIAN); offset++; /* sector count */ proto_tree_add_item(tree, hf_aoe_sector_count, tvb, offset, 1, ENC_BIG_ENDIAN); offset++; /* ata command/status */ if(!response){ proto_tree_add_item(tree, hf_aoe_acmd, tvb, offset, 1, ENC_BIG_ENDIAN); col_append_fstr(pinfo->cinfo, COL_INFO, " ATA:%s", val_to_str(tvb_get_guint8(tvb, offset), ata_cmd_vals, " Unknown ATA<0x%02x>")); } else { proto_tree_add_item(tree, hf_aoe_astatus, tvb, offset, 1, ENC_BIG_ENDIAN); if(ata_info != NULL && ata_info->request_frame){ /* we don't know what command it was unless we saw the request_frame */ tmp_item=proto_tree_add_uint(tree, hf_aoe_acmd, tvb, 0, 0, ata_info->cmd); PROTO_ITEM_SET_GENERATED(tmp_item); col_append_fstr(pinfo->cinfo, COL_INFO, " ATA:%s", val_to_str(ata_info->cmd, ata_cmd_vals, " Unknown ATA<0x%02x>")); } } offset++; /*lba probably complete wrong */ lba=tvb_get_letohs(tvb, offset+4); lba=(lba<<32)|tvb_get_letohl(tvb, offset); offset+=8; proto_tree_add_uint64(tree, hf_aoe_lba, tvb, offset-8, 6, lba); }
int init(void) { int ct = 0; char **input; char **host, **port, **user, **pwd, **thr; int i = 0; #ifndef USE_ST struct sigaction new_action; new_action.sa_handler = sigalarm_handler; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; sigaction (SIGALRM, &new_action, NULL); #endif hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, queue_free); if (!HAVE_OPT(THREADS)) { fprintf(stderr, "missing threads option\n"); return 0; } if (!HAVE_OPT(INPUT)) { fprintf(stderr, "missing input option\n"); return 0; } ct = STACKCT_OPT( INPUT ); input = (char **) &STACKLST_OPT(INPUT); host = (char **) &STACKLST_OPT(HOST); port = (char **) &STACKLST_OPT(PORT); user = (char **) &STACKLST_OPT(UWUSER); pwd = (char **) &STACKLST_OPT(UWPASSWD); thr = (char **) &STACKLST_OPT(THREADS); // read in options for queuing for (i=0; input[i] && i < ct && i < 4; i++) { struct q_info *q = g_hash_table_lookup(hash, input[i]); char buf[256]; if (q == NULL) { q = g_malloc0(sizeof(struct q_info)); q->name = strdup(input[i]); g_hash_table_insert(hash, strdup(input[i]), q); } if (!host || !host[i]) { fprintf(stderr, "missing host option for input %s\n", input[i]); return 0; } else if (strcmp(host[i], "none") == 0) { g_hash_table_remove(hash, host[i]); continue; } if (!port || !port[i]) { fprintf(stderr, "missing port option for input queue %s\n", input[i]); return 0; } if (!user || !user[i]) { fprintf(stderr, "missing uwuser option for input queue %s\n", input[i]); return 0; } if (!pwd || !pwd[i]) { fprintf(stderr, "missing uwpasswd option for input %s\n", input[i]); return 0; } if (q->host) g_free(q->host); if (q->user) g_free(q->user); if (q->pwd) g_free(q->pwd); q->host = strdup(host[i]); q->port = atoi(port[i]); strcpy(buf, user[i]); // preset if (!strchr(user[i], '@') && HAVE_OPT(REALM)) { sprintf(buf, "%s@%s", user[i], OPT_ARG(REALM)); } q->user = strdup(buf); q->pwd = strdup(pwd[i]); q->maxthreads = thr[i] ? atoi(thr[i]) : 1; } if (HAVE_OPT(ONCE)) { every = ONE_SHOT; daemonize = FALSE; } else { daemonize = TRUE; every = EVERY_5SECS; } xmlSetGenericErrorFunc(NULL, UpwatchXmlGenericErrorFunc); return(1); }
GdkFilterReturn event_filter_func (GdkXEvent *gdkxevent, GdkEvent *event, gpointer data) { GdkDisplay *gdkdisplay; XEvent *xevent = gdkxevent; gulong xid = 0; Window select = 0; gdkdisplay = gdk_display_get_default (); switch (xevent->type) { case CreateNotify: { if (!wnck_window_get (xevent->xcreatewindow.window)) { GdkWindow *toplevel = create_foreign_window (xevent->xcreatewindow.window); if (toplevel) { gdk_window_set_events (toplevel, gdk_window_get_events (toplevel) | GDK_PROPERTY_CHANGE_MASK); /* check if the window is a switcher and update accordingly */ if (get_window_prop (xevent->xcreatewindow.window, select_window_atom, &select)) update_switcher_window (xevent->xcreatewindow.window, select); } } } break; case ButtonPress: case ButtonRelease: xid = (gulong) g_hash_table_lookup (frame_table, GINT_TO_POINTER (xevent->xbutton.window)); break; case EnterNotify: case LeaveNotify: xid = (gulong) g_hash_table_lookup (frame_table, GINT_TO_POINTER (xevent->xcrossing.window)); break; case MotionNotify: xid = (gulong) g_hash_table_lookup (frame_table, GINT_TO_POINTER (xevent->xmotion.window)); break; case PropertyNotify: if (xevent->xproperty.atom == frame_input_window_atom) { WnckWindow *win; xid = xevent->xproperty.window; win = wnck_window_get (xid); if (win) { Window frame; if (!get_window_prop (xid, select_window_atom, &select)) { if (get_window_prop (xid, frame_input_window_atom, &frame)) add_frame_window (win, frame, FALSE); else remove_frame_window (win); } } } if (xevent->xproperty.atom == frame_output_window_atom) { WnckWindow *win; xid = xevent->xproperty.window; win = wnck_window_get (xid); if (win) { Window frame; if (!get_window_prop (xid, select_window_atom, &select)) { if (get_window_prop (xid, frame_output_window_atom, &frame)) add_frame_window (win, frame, TRUE); else remove_frame_window (win); } } } else if (xevent->xproperty.atom == compiz_shadow_info_atom || xevent->xproperty.atom == compiz_shadow_color_atom) { GdkScreen *g_screen = gdk_display_get_default_screen (gdkdisplay); Window root = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (g_screen)); WnckScreen *screen; screen = wnck_screen_get_for_root (root); if (screen) { if (gwd_process_decor_shadow_property_update ()) decorations_changed (screen); } } else if (xevent->xproperty.atom == mwm_hints_atom) { WnckWindow *win; xid = xevent->xproperty.window; win = wnck_window_get (xid); if (win) { decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); gboolean decorated = FALSE; /* Only decorations that are actually bound to windows can be decorated * ignore cases where a broken application which shouldn't be decorated * sets the decoration hint */ if (get_mwm_prop (xid) & (MWM_DECOR_ALL | MWM_DECOR_TITLE) && d->win) decorated = TRUE; if (decorated != d->decorated) { d->decorated = decorated; if (decorated) { d->context = NULL; d->width = d->height = 0; d->frame = gwd_get_decor_frame (get_frame_type (win)); update_window_decoration_state (win); update_window_decoration_actions (win); update_window_decoration_icon (win); request_update_window_decoration_size (win); update_event_windows (win); } else { remove_frame_window (win); } } } } else if (xevent->xproperty.atom == select_window_atom) { Window select; if (get_window_prop (xevent->xproperty.window, select_window_atom, &select)) update_switcher_window (xevent->xproperty.window, select); } break; case DestroyNotify: g_hash_table_remove (frame_table, GINT_TO_POINTER (xevent->xproperty.window)); break; case ClientMessage: if (xevent->xclient.message_type == toolkit_action_atom) { long action; action = xevent->xclient.data.l[0]; if (action == toolkit_action_window_menu_atom) { WnckWindow *win; win = wnck_window_get (xevent->xclient.window); if (win) { action_menu_map (win, xevent->xclient.data.l[2], xevent->xclient.data.l[1]); } } else if (action == toolkit_action_force_quit_dialog_atom) { WnckWindow *win; win = wnck_window_get (xevent->xclient.window); if (win) { if (xevent->xclient.data.l[2]) show_force_quit_dialog (win, xevent->xclient.data.l[1]); else hide_force_quit_dialog (win); } } } else if (xevent->xclient.message_type == decor_request_atom) { WnckWindow *win = wnck_window_get (xevent->xclient.window); if (win) update_window_decoration_size (win); } default: break; } if (xid) { WnckWindow *win; win = wnck_window_get (xid); if (win) { decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); if (d->decorated) { gint i, j; event_callback cb = NULL; Window w = xevent->xany.window; for (i = 0; i < 3; ++i) for (j = 0; j < 3; ++j) if (d->event_windows[i][j].window == w) cb = d->event_windows[i][j].callback; if (!cb) { for (i = 0; i < BUTTON_NUM; ++i) if (d->button_windows[i].window == w) cb = d->button_windows[i].callback; } if (cb) { decor_event gtkwd_event; decor_event_type gtkwd_type; gtkwd_event.window = w; switch (xevent->type) { case ButtonPress: case ButtonRelease: if (xevent->type == ButtonPress) gtkwd_type = GButtonPress; else gtkwd_type = GButtonRelease; gtkwd_event.button = xevent->xbutton.button; gtkwd_event.x = xevent->xbutton.x; gtkwd_event.y = xevent->xbutton.y; gtkwd_event.x_root = xevent->xbutton.x_root; gtkwd_event.y_root = xevent->xbutton.y_root; gtkwd_event.time = xevent->xbutton.time; break; case EnterNotify: case LeaveNotify: if (xevent->type == EnterNotify) gtkwd_type = GEnterNotify; else gtkwd_type = GLeaveNotify; gtkwd_event.x = xevent->xcrossing.x; gtkwd_event.y = xevent->xcrossing.y; gtkwd_event.x_root = xevent->xcrossing.x_root; gtkwd_event.y_root = xevent->xcrossing.y_root; gtkwd_event.time = xevent->xcrossing.time; break; default: cb = NULL; break; } if (cb) (*cb) (win, >kwd_event, gtkwd_type); } } } } return GDK_FILTER_CONTINUE; }
void lrm_state_destroy(const char *node_name) { g_hash_table_remove(lrm_state_table, node_name); }
static ros_call_response_t * ros_match_call_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint invokeId, gboolean isInvoke) { ros_call_response_t rcr, *rcrp=NULL; ros_conv_info_t *ros_info = ros_info_items; /* first see if we have already matched this */ rcr.invokeId=invokeId; rcr.is_request = isInvoke; if(isInvoke) { rcr.req_frame=pinfo->fd->num; rcr.rep_frame=0; } else { rcr.req_frame=0; rcr.rep_frame=pinfo->fd->num; } rcrp=(ros_call_response_t *)g_hash_table_lookup(ros_info->matched, &rcr); if(rcrp) { /* we have found a match */ rcrp->is_request=rcr.is_request; } else { /* we haven't found a match - try and match it up */ if(isInvoke) { /* this a a request - add it to the unmatched list */ /* check that we dont already have one of those in the unmatched list and if so remove it */ rcr.invokeId=invokeId; rcrp=(ros_call_response_t *)g_hash_table_lookup(ros_info->unmatched, &rcr); if(rcrp){ g_hash_table_remove(ros_info->unmatched, rcrp); } /* if we cant reuse the old one, grab a new chunk */ if(!rcrp){ rcrp=wmem_new(wmem_file_scope(), ros_call_response_t); } rcrp->invokeId=invokeId; rcrp->req_frame=pinfo->fd->num; rcrp->req_time=pinfo->fd->abs_ts; rcrp->rep_frame=0; rcrp->is_request=TRUE; g_hash_table_insert(ros_info->unmatched, rcrp, rcrp); return NULL; } else { /* this is a result - it should be in our unmatched list */ rcr.invokeId=invokeId; rcrp=(ros_call_response_t *)g_hash_table_lookup(ros_info->unmatched, &rcr); if(rcrp){ if(!rcrp->rep_frame){ g_hash_table_remove(ros_info->unmatched, rcrp); rcrp->rep_frame=pinfo->fd->num; rcrp->is_request=FALSE; g_hash_table_insert(ros_info->matched, rcrp, rcrp); } } } } if(rcrp){ /* we have found a match */ proto_item *item = NULL; if(rcrp->is_request){ item=proto_tree_add_uint(tree, hf_ros_response_in, tvb, 0, 0, rcrp->rep_frame); PROTO_ITEM_SET_GENERATED (item); } else { nstime_t ns; item=proto_tree_add_uint(tree, hf_ros_response_to, tvb, 0, 0, rcrp->req_frame); PROTO_ITEM_SET_GENERATED (item); nstime_delta(&ns, &pinfo->fd->abs_ts, &rcrp->req_time); item=proto_tree_add_time(tree, hf_ros_time, tvb, 0, 0, &ns); PROTO_ITEM_SET_GENERATED (item); } } return rcrp; }
static void irc_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) { struct irc_conn *irc = (struct irc_conn *)gc->proto_data; g_hash_table_remove(irc->buddies, buddy->name); }
void pending_reads_send_user (struct tgl_state *TLS, tgl_peer_id_t id) { if (g_hash_table_remove (tls_get_data (TLS)->pending_reads, GINT_TO_POINTER (tgl_get_peer_id (id)))) { info ("tgl_do_mark_read (%d)", tgl_get_peer_id (id)); tgl_do_mark_read (TLS, id, tgp_notify_on_error_gw, NULL); } }
static enum op_stats unlock_variable(struct operation *op, int force) { GSList *t = NULL; struct operation *tmp_op; enum op_stats stats; char *strtrans; if (op == NULL) return OP_ERROR; if (is_transaction_waiting(op) && !force) return OP_WAIT; stats = OP_ERROR; t = g_hash_table_lookup(lock_x_table, op->var); if (t != NULL) { for (int i = 0; i < g_slist_length(t); i++) { tmp_op = g_slist_nth_data(t, i); if (op->transaction == tmp_op->transaction) { t = g_slist_remove(t, tmp_op); g_hash_table_insert(lock_x_table, op->var, t); if (g_slist_length(t) == 0) { g_hash_table_remove(lock_x_table, op->var); g_slist_free(t); t = NULL; } stats = OP_OK; break; } } } if (g_hash_table_size(lock_x_table) == 0) { g_hash_table_destroy(lock_x_table); lock_x_table = g_hash_table_new(g_str_hash, g_str_equal); } if (stats == OP_OK) goto END; t = g_hash_table_lookup(lock_s_table, op->var); if (t != NULL) { for (int i = 0; i < g_slist_length(t); i++) { tmp_op = g_slist_nth_data(t, i); if (op->transaction == tmp_op->transaction) { t = g_slist_remove(t, tmp_op); g_hash_table_insert(lock_s_table, op->var, t); if (g_slist_length(t) == 0) { g_hash_table_remove(lock_s_table, op->var); g_slist_free(t); t = NULL; } stats = OP_OK; break; } } } if (g_hash_table_size(lock_s_table) == 0) { g_hash_table_destroy(lock_s_table); lock_s_table = g_hash_table_new(g_str_hash, g_str_equal); } END: if (stats == OP_OK) { if (!did_unlocked(op)) { strtrans = g_strdup_printf("%d", op->transaction); unlocked_transaction_list = g_slist_append(unlocked_transaction_list, strtrans); } } return stats; }
static void _caps_disco_cb (SalutDisco *disco, SalutDiscoRequest *request, SalutContact *contact, const gchar *node, WockyNode *query_result, GError *error, gpointer user_data) { GSList *waiters, *i; DiscoWaiter *waiter_self; SalutPresenceCache *cache; SalutPresenceCachePrivate *priv; gboolean bad_hash = FALSE; CapabilityInfo *info = NULL; if (query_result == NULL) return; cache = SALUT_PRESENCE_CACHE (user_data); priv = SALUT_PRESENCE_CACHE_PRIV (cache); if (NULL == node) { DEBUG ("got disco response with NULL node, ignoring"); return; } waiters = g_hash_table_lookup (priv->disco_pending, node); if (NULL != error) { DiscoWaiter *waiter = NULL; DEBUG ("disco query failed: %s", error->message); for (i = waiters; NULL != i; i = i->next) { waiter = (DiscoWaiter *) i->data; if (!waiter->disco_requested) { salut_disco_request (disco, SALUT_DISCO_TYPE_INFO, waiter->contact, node, _caps_disco_cb, cache, G_OBJECT(cache), NULL); waiter->disco_requested = TRUE; break; } } if (NULL != i) { DEBUG ("sent a retry disco request to %s for URI %s", contact->name, node); } else { /* The contact sends us an error and we don't have any other * contacts to send the discovery request on the same node. We * cannot get the caps for this node. */ DEBUG ("failed to find a suitable candidate to retry disco " "request for URI %s", node); g_hash_table_remove (priv->disco_pending, node); } return; } waiter_self = NULL; for (i = waiters; NULL != i; i = i->next) { DiscoWaiter *waiter; waiter = (DiscoWaiter *) i->data; if (waiter->contact == contact) { waiter_self = waiter; break; } } if (NULL == waiter_self) { DEBUG ("Ignoring non requested disco reply"); return; } /* Only 'sha-1' is mandatory to implement by XEP-0115. If the remote contact * uses another hash algorithm, don't check the hash and fallback to the old * method. The hash method is not included in the discovery request nor * response but we saved it in disco_pending when we received the presence * stanza. */ if (!tp_strdiff (waiter_self->hash, "sha-1")) { gchar *computed_hash; computed_hash = wocky_caps_hash_compute_from_node (query_result); if (!g_str_equal (waiter_self->ver, computed_hash)) bad_hash = TRUE; if (!bad_hash) { info = capability_info_get (cache, node); if (info == NULL) { info = g_slice_new0 (CapabilityInfo); info->caps = gabble_capability_set_new_from_stanza ( query_result); info->data_forms = get_data_forms (query_result); g_hash_table_insert (priv->capabilities, g_strdup (node), info); } } else { /* The received reply does not match the */ DEBUG ("The announced verification string '%s' does not match " "our hash '%s'.", waiter_self->ver, computed_hash); } g_free (computed_hash); } else { /* Do not allow tubes caps if the contact does not observe XEP-0115 * version 1.5: we don't need to bother being compatible with both version * 1.3 and tubes caps */ DEBUG ("Unsupported hash algorithm, ignoring caps: %s", waiter_self->hash == NULL ? "(none)" : waiter_self->hash); } if (info == NULL) info = &priv->not_xep_capabilities; for (i = waiters; NULL != i;) { DiscoWaiter *waiter; waiter = (DiscoWaiter *) i->data; if (!bad_hash || waiter->contact == contact) { GSList *tmp; gpointer key; gpointer value; if (!bad_hash) { salut_presence_cache_change_caps (cache, waiter->contact, contact->name, info); } tmp = i; i = i->next; waiters = g_slist_delete_link (waiters, tmp); if (!g_hash_table_lookup_extended (priv->disco_pending, node, &key, &value)) g_assert_not_reached (); g_hash_table_steal (priv->disco_pending, node); g_hash_table_insert (priv->disco_pending, key, waiters); disco_waiter_free (waiter); } else { /* if the possible trust, not counting this guy, is too low, * we have been poisoned and reset our trust meters - disco * anybody we still haven't to be able to get more trusted replies */ if (!waiter->disco_requested) { salut_disco_request (disco, SALUT_DISCO_TYPE_INFO, waiter->contact, node, _caps_disco_cb, cache, G_OBJECT(cache), NULL); waiter->disco_requested = TRUE; } i = i->next; } } if (!bad_hash) g_hash_table_remove (priv->disco_pending, node); }
int backup_mmap_file(void* owner, void* data) { //转储MMAP文件并发送该文件 char filepath[DIR_PATH_LEN]; char newpath[DIR_PATH_LEN]; uint32_t i, j, pos; struct tm p; uint64_t sec; FILE *fp; //按时间、类型、项目号来备份mmap sec = time((time_t*)NULL); localtime_r((const time_t*)&sec,&p); //备份cdn的mmap for (i = 0; i < max_project_number; i++) { if (cdn_speed_ip_mmap[i].mmap_head->ready_num != 0) { snprintf(filepath, sizeof(filepath), "%s/tmp.mmap_backup_file_cdn_ip_[%03d]%04d-%02d-%02d-%02d-%02d-%02d", mmap_tmpfile_dirpath, i + 1, p.tm_year + 1900, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec); snprintf(newpath, sizeof(newpath), "%s/mmap_backup_file_cdn_ip_[%03d]%04d-%02d-%02d-%02d-%02d-%02d", mmap_tmpfile_dirpath, i + 1, p.tm_year + 1900, p.tm_mon + 1,p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec); fp = fopen(filepath, "wb+"); if (fp == NULL) ERROR_RETURN(("can't open backup file %s",filepath), -1); if (fwrite(cdn_speed_ip_mmap[i].mmap_head, 1, cdn_mmap_size_ip + MMAP_FILE_HEAD_LEN, fp) != (cdn_mmap_size_ip + MMAP_FILE_HEAD_LEN)) { ERROR_LOG("BACK UP CDN IP MMAP FILE ERROR:proj:%u,records:%u,ready:%u", i, cdn_speed_ip_mmap[i].mmap_head->records_num,cdn_speed_ip_mmap[i].mmap_head->ready_num); fclose(fp); remove(filepath); } else { fclose(fp); rename(filepath, newpath); cdn_speed_ip_mmap[i].ready_num = cdn_speed_ip_mmap[i].mmap_head->ready_num = 0; cdn_speed_ip_t *ptr = (cdn_speed_ip_t*)cdn_speed_ip_mmap[i].mmap_p; for (j = 0; j < cdn_speed_ip_mmap[i].mmap_head->records_num; j++) { pos = (ptr + j)->step; (ptr + j)->speed[pos] = 0; (ptr + j)->count[pos] = 0; memset((ptr + j)->speed_distribution[pos], 0, sizeof((ptr + j)->speed_distribution[pos])); pos = (pos + 1) % CDN_TIME_INTER; if ((ptr + j)->count[pos] != 0) { (ptr + j)->time[pos] = (ptr + j)->time[(ptr + j)->step] + 60; cdn_speed_ip_mmap[i].ready_num ++; cdn_speed_ip_mmap[i].mmap_head->ready_num ++; } (ptr + j)->step = pos; } } } if (cdn_speed_area_mmap[i].mmap_head->ready_num != 0) { snprintf(filepath, sizeof(filepath), "%s/tmp.mmap_backup_file_cdn_area_[%03d]%04d-%02d-%02d-%02d-%02d-%02d", mmap_tmpfile_dirpath, i + 1, p.tm_year + 1900, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec); snprintf(newpath, sizeof(newpath), "%s/mmap_backup_file_cdn_area_[%03d]%04d-%02d-%02d-%02d-%02d-%02d", mmap_tmpfile_dirpath, i + 1, p.tm_year + 1900, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec); fp = fopen(filepath, "wb+"); if (fp == NULL) ERROR_RETURN(("can't open backup file %s",filepath), -1); if (fwrite(cdn_speed_area_mmap[i].mmap_head, 1, cdn_mmap_size_area + MMAP_FILE_HEAD_LEN, fp) != (cdn_mmap_size_area + MMAP_FILE_HEAD_LEN)) { ERROR_LOG("BACK UP CDN AREA MMAP FILE ERROR:proj:%u,records:%u,ready:%u", i, cdn_speed_area_mmap[i].mmap_head->records_num,cdn_speed_area_mmap[i].mmap_head->ready_num); fclose(fp); remove(filepath); } else { fclose(fp); rename(filepath, newpath); cdn_speed_area_mmap[i].ready_num = cdn_speed_area_mmap[i].mmap_head->ready_num = 0; cdn_speed_area_t *ptr = (cdn_speed_area_t*)cdn_speed_area_mmap[i].mmap_p; INFO_LOG("BBBB: cdn_speed_area_mmap[%d].mmap_head->records_num: %u", i, cdn_speed_area_mmap[i].mmap_head->records_num); for (j = 0; j < cdn_speed_area_mmap[i].mmap_head->records_num; j++) { pos = (ptr + j)->step; //comments//////////////////////////////////////////////////////////////// cdn_speed_area_t *p_cdn_area = ptr + j; if (p_cdn_area->count[pos] != 0 || p_cdn_area->t_count != 0) { INFO_LOG("BBBB:time[%u] speed[%u] count[%u]", p_cdn_area->t_time, p_cdn_area->t_speed, p_cdn_area->t_count); INFO_LOG("BBBB:pos[%u] time[%u] speed[%u] count[%u]", pos, p_cdn_area->time[pos], p_cdn_area->speed[pos], p_cdn_area->count[pos]); int m = 0; for (m = 0; m < 6; m++) { INFO_LOG("BBBB:pos[%u] dis[%d]: %u", pos, m, p_cdn_area->speed_distribution[pos][m]); } int next_pos = (pos + 1) % CDN_TIME_INTER; INFO_LOG("BBBB:next_pos[%u] time[%u] speed[%u] count[%u]", next_pos, p_cdn_area->time[next_pos], p_cdn_area->speed[next_pos], p_cdn_area->count[next_pos]); for (m = 0; m < 6; m++) { INFO_LOG("BBBB:next_pos[%u] dis[%d]: %u", next_pos, m, p_cdn_area->speed_distribution[next_pos][m]); } } /** */ ////////////////////////////////////////////////////////////////////////// (ptr + j)->count[pos] = 0; (ptr + j)->speed[pos] = 0; memset((ptr + j)->speed_distribution[pos], 0, sizeof((ptr + j)->speed_distribution[pos])); pos = (pos + 1) % CDN_TIME_INTER; if ((ptr + j)->count[pos] != 0) { (ptr + j)->time[pos] = (ptr + j)->time[(ptr + j)->step] + 60; cdn_speed_area_mmap[i].ready_num ++; cdn_speed_area_mmap[i].mmap_head->ready_num ++; } (ptr + j)->step = pos; } } } } //备份url的mmap int now = (int)time((time_t*)NULL); for (i = 0; i < max_project_number; i++) { for (j = 0; j < max_page_per_proj; j++) { pos = i * max_page_per_proj + j; if (url_page_mmap[pos].mmap_head->ready_num != 0) { snprintf(filepath, sizeof(filepath), "%s/tmp.mmap_backup_file_url_page_[%03d_%d]%04d-%02d-%02d-%02d-%02d-%02d", mmap_tmpfile_dirpath, i + 1, url_page_mmap[pos].mmap_head->key, p.tm_year + 1900, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec); snprintf(newpath, sizeof(newpath), "%s/mmap_backup_file_url_page_[%03d_%d]%04d-%02d-%02d-%02d-%02d-%02d", mmap_tmpfile_dirpath, i + 1, url_page_mmap[pos].mmap_head->key, p.tm_year + 1900, p.tm_mon + 1, p.tm_mday, p.tm_hour, p.tm_min, p.tm_sec); fp = fopen(filepath, "wb+"); if (fp == NULL) ERROR_RETURN(("can't open backup file %s",filepath), -1); if (fwrite(url_page_mmap[pos].mmap_head, 1, url_mmap_size_page + MMAP_FILE_HEAD_LEN, fp) != (url_mmap_size_page + MMAP_FILE_HEAD_LEN)) { ERROR_LOG("BACK UP URL MMAP FILE ERROR:proj:%u,records:%u,ready:%u", url_page_mmap[pos].value, url_page_mmap[pos].mmap_head->records_num,url_page_mmap[pos].mmap_head->ready_num); fclose(fp); remove(filepath); } else { fclose(fp); rename(filepath, newpath); url_page_mmap[pos].ready_num = url_page_mmap[pos].mmap_head->ready_num = 0; uint32_t k; url_test_t *p = (url_test_t*)url_page_mmap[pos].mmap_p; for (k = 0; k < url_page_mmap[pos].mmap_head->records_num; k++) (p + k)->count = 0; } } else if ((now - (int)(url_page_mmap[pos].latest_time)) > 86400) {//mmap一天没用,则回收. g_hash_table_remove(url_page_index[i], &(url_page_mmap[pos].key)); url_page_mmap[pos].key = url_page_mmap[pos].mmap_head->key = 0; url_page_mmap[pos].value = url_page_mmap[pos].mmap_head->value = 0; url_page_mmap[pos].latest_time = url_page_mmap[pos].mmap_head->latest_time = 0; url_page_mmap[pos].ready_num = url_page_mmap[pos].mmap_head->ready_num = 0; url_page_status[i].status[url_page_mmap[pos].value] = 0; if (url_page_status[i].used_count > 0) url_page_status[i].used_count --; } } } //下一个整点分钟时间继续触发事件 if (data == NULL) { ADD_TIMER_EVENT(&g_timer, backup_mmap_file, NULL, get_now_tv()->tv_sec + 60 * backup_interval - get_now_tv()->tv_sec % 60); } return 0; }
static int send_cdn_ip_2_dbserver(char *mmap_p) { mmap_file_head_t *file_head_p = (mmap_file_head_t*)mmap_p; cdn_speed_ip_t *cdn_ip_p = (cdn_speed_ip_t*)(mmap_p + sizeof(mmap_file_head_t)); uint8_t buf[BUF_NET_SEND_LEN]; int len; uint32_t i; uint32_t send_count=0; uint32_t ready = file_head_p->ready_num; int number;// = cdn_ip_p->project_number; uint32_t packet_tag = tmp_packet_tag << SHIFT_BITS; int now; resend_cdnip: ready -= send_count; send_count = 0; now = (int)time(0); for (i = 0; i < file_head_p->records_num; i++) { (cdn_ip_p + i)->t_time = (cdn_ip_p + i)->time[(cdn_ip_p + i)->step]; (cdn_ip_p + i)->t_speed = (cdn_ip_p + i)->speed[(cdn_ip_p + i)->step]; (cdn_ip_p + i)->t_count = (cdn_ip_p + i)->count[(cdn_ip_p + i)->step]; //start-added by singku for remove ip which is out of date 2011-08-04 if ((cdn_ip_p + i)->t_count == 0 && (cdn_ip_p + i)->ip != 0 && (now - (int)((cdn_ip_p + i)->t_time)) > 86400) { //i如果此处有ip记录ip不为0,说明还没有到空白记录处,则判断该ip是否过期 ,一天都无数据 则删除. //先从hash表中删除当前ip. int proj = ((cdn_ip_p + i)->project_number - 1) % max_project_number; //tmp指向最后一个结果,将最后一个结果搬移过来,覆盖此处的数据. cdn_speed_ip_t *tmp = (cdn_speed_ip_t *)(cdn_speed_ip_mmap[proj].mmap_p); cdn_speed_ip_t *cur = tmp + i; pthread_spin_lock(&lock_cdn_ip); if (cur->t_count == 0 && (i+1) < cdn_speed_ip_mmap[proj].records_num) {//如果对应的当前mmap中该cdn ip也无数据 tmp += (cdn_speed_ip_mmap[proj].records_num -1); g_hash_table_remove(cdn_hash_ip[proj], &(cur->ip)); if (cur != tmp) { memcpy(cur, tmp, sizeof(cdn_speed_ip_t)); cur->offset = i;//重置offset //重新插入hash表 replace会替代老的key,value,所以不用担心没有remove掉原来的末尾ip. g_hash_table_replace(cdn_hash_ip[proj], &(cur->ip), &(cur->offset)); } if (cdn_speed_ip_mmap[proj].records_num > 0) { cdn_speed_ip_mmap[proj].records_num --; cdn_speed_ip_mmap[proj].mmap_head->records_num --; } } pthread_spin_unlock(&lock_cdn_ip); } //end-added by singku for remove ip which is out of date 2011-08-04 if ((cdn_ip_p + i)->t_count == 0) continue; /*start---added by singku for cache 11-07-27*/ if (other_start == 1) update_cache(proto_cache_cdn_node, (void*)(cdn_ip_p + i)); /*end ----added by singku for cache 11-07-27*/ //init protocol_head; number = ((cdn_ip_p + i)->project_number-1) % max_project_number + 1; len = sizeof(protocol_t) + sizeof(proto_cdn_speed_ip_t); init_proto_head(buf, len, proto_as_cdn_report_ip, (packet_tag + number), i, 0); DEBUG_LOG("SEND CDN IP PACKET___PROTO:%x,ID:%u,Number:%u,Time:%u,Speed:%u,Count:%u", proto_as_cdn_report_ip,i,number,(cdn_ip_p+i)->t_time, (cdn_ip_p+i)->t_speed/(cdn_ip_p+i)->t_count, (cdn_ip_p+i)->t_count); memcpy(buf + sizeof(protocol_t), &((cdn_ip_p + i)->project_number), sizeof(proto_cdn_speed_ip_t)); if (send_data(buf, len, proto_as_cdn_report_ip) == -1) return -1; send_count ++; if (send_count == ready) break; } if (send_count == 0) ERROR_RETURN(("SEND COUNT == 0:map_tag:%u,type:CDN IP", tmp_packet_tag), 0); if (wait_all_tmpdata_ok(mmap_p) == -1) { ERROR_LOG("CDN IP:WAIT RET PACKETS TIME OUT"); goto resend_cdnip; } return 0; }
static void cg_cell_renderer_flags_selected (CgComboFlags *combo, GtkTreeIter *iter, CgComboFlagsSelectionType type, gpointer user_data) { CgCellRendererFlags *cell_flags; CgCellRendererFlagsPrivate *priv; gpointer result; gchar *name; gchar *abbr; cell_flags = CG_CELL_RENDERER_FLAGS (user_data); priv = CG_CELL_RENDERER_FLAGS_PRIVATE (cell_flags); gtk_tree_model_get (priv->model, iter, priv->text_column, &name, priv->abbr_column, &abbr, -1); g_assert (priv->edit_status != NULL); result = g_hash_table_lookup (priv->edit_status, abbr); /* abbr needs not to be freed if it gets inserted into the hash table * because the hash table then takes ownership of it. */ switch (type) { case CG_COMBO_FLAGS_SELECTION_NONE: g_free (abbr); break; case CG_COMBO_FLAGS_SELECTION_SELECT: if (GPOINTER_TO_INT(result) != 1) g_hash_table_insert (priv->edit_status, abbr, GINT_TO_POINTER (1)); else g_free (abbr); break; case CG_COMBO_FLAGS_SELECTION_UNSELECT: if (GPOINTER_TO_INT (result) == 1) g_hash_table_remove(priv->edit_status, abbr); g_free (abbr); break; case CG_COMBO_FLAGS_SELECTION_TOGGLE: if (GPOINTER_TO_INT (result) == 1) { g_hash_table_remove (priv->edit_status, abbr); g_free(abbr); } else { g_hash_table_insert (priv->edit_status, abbr, GINT_TO_POINTER (1)); } break; default: g_assert_not_reached (); break; } /* This is done to get GTK+ to re-render this row with the changed flag * status that is set via the cell data func, but GTK+ does not call it * again because it does not know that the hash table changed. There are * probably better means to achieve this, but I am not aware of those. */ gtk_list_store_set (GTK_LIST_STORE (priv->model), iter, priv->text_column, name, -1); g_free (name); }
/* Thread */ void *janus_pfunix_thread(void *data) { JANUS_LOG(LOG_INFO, "Unix Sockets thread started\n"); int fds = 0; struct pollfd poll_fds[1024]; /* FIXME Should we allow for more clients? */ char buffer[BUFFER_SIZE]; struct iovec iov[1]; struct msghdr msg; memset(&msg, 0, sizeof(msg)); memset(iov, 0, sizeof(iov)); iov[0].iov_base = buffer; iov[0].iov_len = sizeof(buffer); msg.msg_iov = iov; msg.msg_iovlen = 1; while(g_atomic_int_get(&initialized) && !g_atomic_int_get(&stopping)) { /* Prepare poll list of file descriptors */ fds = 0; /* Writeable monitor */ poll_fds[fds].fd = write_fd[0]; poll_fds[fds].events = POLLIN; fds++; if(pfd > -1) { /* Janus API */ poll_fds[fds].fd = pfd; poll_fds[fds].events = POLLIN; fds++; } if(admin_pfd > -1) { /* Admin API */ poll_fds[fds].fd = admin_pfd; poll_fds[fds].events = POLLIN; fds++; } /* Iterate on available clients, to see if we need to POLLIN or POLLOUT too */ janus_mutex_lock(&clients_mutex); GHashTableIter iter; gpointer value; g_hash_table_iter_init(&iter, clients_by_fd); while(g_hash_table_iter_next(&iter, NULL, &value)) { janus_pfunix_client *client = value; if(client->fd > -1) { poll_fds[fds].fd = client->fd; poll_fds[fds].events = g_async_queue_length(client->messages) > 0 ? POLLIN | POLLOUT : POLLIN; fds++; } } janus_mutex_unlock(&clients_mutex); /* Start polling */ int res = poll(poll_fds, fds, -1); if(res == 0) continue; if(res < 0) { if(errno == EINTR) { JANUS_LOG(LOG_HUGE, "Got an EINTR (%s) polling the Unix Sockets descriptors, ignoring...\n", strerror(errno)); continue; } JANUS_LOG(LOG_ERR, "poll() failed: %d (%s)\n", errno, strerror(errno)); break; } int i = 0; for(i=0; i<fds; i++) { if(poll_fds[i].revents & (POLLERR | POLLHUP)) { /* Socket error? Shall we do something? */ if(poll_fds[i].fd == write_fd[0]) { /* Error in the wake-up socketpair, that sucks: try recreating it */ JANUS_LOG(LOG_WARN, "Error polling wake-up socketpair: %s...\n", poll_fds[i].revents & POLLERR ? "POLLERR" : "POLLHUP"); close(write_fd[0]); write_fd[0] = -1; close(write_fd[1]); write_fd[1] = -1; if(socketpair(PF_LOCAL, SOCK_STREAM, 0, write_fd) < 0) { JANUS_LOG(LOG_FATAL, "Error creating socket pair for writeable events: %d, %s\n", errno, strerror(errno)); continue; } } else if(poll_fds[i].fd == pfd) { /* Error in the Janus API socket */ JANUS_LOG(LOG_WARN, "Error polling Unix Sockets Janus API interface (%s), disabling it\n", poll_fds[i].revents & POLLERR ? "POLLERR" : "POLLHUP"); close(pfd); pfd = -1; continue; } else if(poll_fds[i].fd == admin_pfd) { /* Error in the Admin API socket */ JANUS_LOG(LOG_WARN, "Error polling Unix Sockets Admin API interface (%s), disabling it\n", poll_fds[i].revents & POLLERR ? "POLLERR" : "POLLHUP"); close(admin_pfd); admin_pfd = -1; continue; } else { /* Error in a client socket, find and remove it */ janus_mutex_lock(&clients_mutex); janus_pfunix_client *client = g_hash_table_lookup(clients_by_fd, GINT_TO_POINTER(poll_fds[i].fd)); if(client == NULL) { /* We're not handling this, ignore */ janus_mutex_unlock(&clients_mutex); continue; } JANUS_LOG(LOG_INFO, "Unix Sockets client disconnected (%d)\n", poll_fds[i].fd); /* Notify core */ gateway->transport_gone(&janus_pfunix_transport, client->ts); /* Notify handlers about this transport being gone */ if(notify_events && gateway->events_is_enabled()) { json_t *info = json_object(); json_object_set_new(info, "event", json_string("disconnected")); gateway->notify_event(&janus_pfunix_transport, client->ts, info); } /* Close socket */ shutdown(SHUT_RDWR, poll_fds[i].fd); close(poll_fds[i].fd); client->fd = -1; /* Destroy the client */ g_hash_table_remove(clients_by_fd, GINT_TO_POINTER(poll_fds[i].fd)); g_hash_table_remove(clients, client); /* Unref the transport instance */ janus_transport_session_destroy(client->ts); janus_mutex_unlock(&clients_mutex); continue; } continue; } if(poll_fds[i].revents & POLLOUT) { /* Find the client from its file descriptor */ janus_mutex_lock(&clients_mutex); janus_pfunix_client *client = g_hash_table_lookup(clients_by_fd, GINT_TO_POINTER(poll_fds[i].fd)); if(client != NULL) { char *payload = NULL; while((payload = g_async_queue_try_pop(client->messages)) != NULL) { int res = 0; do { if(client->fd < 0) break; res = write(client->fd, payload, strlen(payload)); } while(res == -1 && errno == EINTR); /* FIXME Should we check if sent everything? */ JANUS_LOG(LOG_HUGE, "Written %d/%zu bytes on %d\n", res, strlen(payload), client->fd); g_free(payload); } if(client->session_timeout) { /* We should actually get rid of this connection, now */ shutdown(SHUT_RDWR, poll_fds[i].fd); close(poll_fds[i].fd); client->fd = -1; /* Destroy the client */ g_hash_table_remove(clients_by_fd, GINT_TO_POINTER(poll_fds[i].fd)); g_hash_table_remove(clients, client); if(client->messages != NULL) { char *response = NULL; while((response = g_async_queue_try_pop(client->messages)) != NULL) { g_free(response); } g_async_queue_unref(client->messages); } g_free(client); } } janus_mutex_unlock(&clients_mutex); } if(poll_fds[i].revents & POLLIN) { if(poll_fds[i].fd == write_fd[0]) { /* Read and ignore: we use this to unlock the poll if there's data to write */ (void)read(poll_fds[i].fd, buffer, BUFFER_SIZE); } else if(poll_fds[i].fd == pfd || poll_fds[i].fd == admin_pfd) { /* Janus/Admin API: accept the new client (SOCK_SEQPACKET) or receive data (SOCK_DGRAM) */ struct sockaddr_un address; socklen_t addrlen = sizeof(address); if((poll_fds[i].fd == pfd && !dgram) || (poll_fds[i].fd == admin_pfd && !admin_dgram)) { /* SOCK_SEQPACKET */ int cfd = accept(poll_fds[i].fd, (struct sockaddr *) &address, &addrlen); if(cfd > -1) { JANUS_LOG(LOG_INFO, "Got new Unix Sockets %s API client: %d\n", poll_fds[i].fd == pfd ? "Janus" : "Admin", cfd); /* Allocate new client */ janus_pfunix_client *client = g_malloc(sizeof(janus_pfunix_client)); client->fd = cfd; memset(&client->addr, 0, sizeof(client->addr)); client->admin = (poll_fds[i].fd == admin_pfd); /* API client type */ client->messages = g_async_queue_new(); client->session_timeout = FALSE; /* Create a transport instance as well */ client->ts = janus_transport_session_create(client, janus_pfunix_client_free); /* Take note of this new client */ janus_mutex_lock(&clients_mutex); g_hash_table_insert(clients_by_fd, GINT_TO_POINTER(cfd), client); g_hash_table_insert(clients, client, client); janus_mutex_unlock(&clients_mutex); /* Notify handlers about this new transport */ if(notify_events && gateway->events_is_enabled()) { json_t *info = json_object(); json_object_set_new(info, "event", json_string("connected")); json_object_set_new(info, "admin_api", client->admin ? json_true() : json_false()); json_object_set_new(info, "fd", json_integer(client->fd)); gateway->notify_event(&janus_pfunix_transport, client->ts, info); } } } else { /* SOCK_DGRAM */ struct sockaddr_storage address; res = recvfrom(poll_fds[i].fd, buffer, sizeof(buffer), 0, (struct sockaddr *)&address, &addrlen); if(res < 0) { if(errno != EAGAIN && errno != EWOULDBLOCK) { JANUS_LOG(LOG_ERR, "Error reading from client (%s API)...\n", poll_fds[i].fd == pfd ? "Janus" : "Admin"); } continue; } buffer[res] = '\0'; /* Is this a new client, or one we knew about already? */ struct sockaddr_un *uaddr = (struct sockaddr_un *)&address; if(strlen(uaddr->sun_path) == 0) { /* No path provided, drop the packet */ JANUS_LOG(LOG_WARN, "Dropping packet from unknown source (no path provided)\n"); continue; } janus_mutex_lock(&clients_mutex); janus_pfunix_client *client = g_hash_table_lookup(clients_by_path, uaddr->sun_path); if(client == NULL) { JANUS_LOG(LOG_INFO, "Got new Unix Sockets %s API client: %s\n", poll_fds[i].fd == pfd ? "Janus" : "Admin", uaddr->sun_path); /* Allocate new client */ client = g_malloc(sizeof(janus_pfunix_client)); client->fd = -1; memcpy(&client->addr, uaddr, sizeof(struct sockaddr_un)); client->admin = (poll_fds[i].fd == admin_pfd); /* API client type */ client->messages = g_async_queue_new(); client->session_timeout = FALSE; /* Create a transport instance as well */ client->ts = janus_transport_session_create(client, janus_pfunix_client_free); /* Take note of this new client */ g_hash_table_insert(clients_by_path, uaddr->sun_path, client); g_hash_table_insert(clients, client, client); /* Notify handlers about this new transport */ if(notify_events && gateway->events_is_enabled()) { json_t *info = json_object(); json_object_set_new(info, "event", json_string("connected")); json_object_set_new(info, "admin_api", client->admin ? json_true() : json_false()); json_object_set_new(info, "fd", json_integer(client->fd)); json_object_set_new(info, "type", json_string("SOCK_DGRAM")); gateway->notify_event(&janus_pfunix_transport, client->ts, info); } } janus_mutex_unlock(&clients_mutex); JANUS_LOG(LOG_VERB, "Message from client %s (%d bytes)\n", uaddr->sun_path, res); JANUS_LOG(LOG_HUGE, "%s\n", buffer); /* Parse the JSON payload */ json_error_t error; json_t *root = json_loads(buffer, 0, &error); /* Notify the core, passing both the object and, since it may be needed, the error */ gateway->incoming_request(&janus_pfunix_transport, client->ts, NULL, client->admin, root, &error); } } else { /* Client data: receive message */ iov[0].iov_len = sizeof(buffer); res = recvmsg(poll_fds[i].fd, &msg, MSG_WAITALL); if(res < 0) { if(errno != EAGAIN && errno != EWOULDBLOCK) { JANUS_LOG(LOG_ERR, "Error reading from client %d...\n", poll_fds[i].fd); } continue; } if(msg.msg_flags & MSG_TRUNC) { /* Apparently our buffer is not large enough? */ JANUS_LOG(LOG_WARN, "Incoming message from client %d truncated (%d bytes), dropping it...\n", poll_fds[i].fd, res); continue; } /* Find the client from its file descriptor */ janus_mutex_lock(&clients_mutex); janus_pfunix_client *client = g_hash_table_lookup(clients_by_fd, GINT_TO_POINTER(poll_fds[i].fd)); if(client == NULL) { janus_mutex_unlock(&clients_mutex); JANUS_LOG(LOG_WARN, "Got data from unknown Unix Sockets client %d, closing connection...\n", poll_fds[i].fd); /* Close socket */ shutdown(SHUT_RDWR, poll_fds[i].fd); close(poll_fds[i].fd); continue; } if(res == 0) { JANUS_LOG(LOG_INFO, "Unix Sockets client disconnected (%d)\n", poll_fds[i].fd); /* Notify core */ gateway->transport_gone(&janus_pfunix_transport, client->ts); /* Notify handlers about this transport being gone */ if(notify_events && gateway->events_is_enabled()) { json_t *info = json_object(); json_object_set_new(info, "event", json_string("disconnected")); gateway->notify_event(&janus_pfunix_transport, client->ts, info); } /* Close socket */ shutdown(SHUT_RDWR, poll_fds[i].fd); close(poll_fds[i].fd); client->fd = -1; /* Destroy the client */ g_hash_table_remove(clients_by_fd, GINT_TO_POINTER(poll_fds[i].fd)); g_hash_table_remove(clients, client); /* Unref the transport instance */ janus_transport_session_destroy(client->ts); janus_mutex_unlock(&clients_mutex); continue; } janus_mutex_unlock(&clients_mutex); /* If we got here, there's data to handle */ buffer[res] = '\0'; JANUS_LOG(LOG_VERB, "Message from client %d (%d bytes)\n", poll_fds[i].fd, res); JANUS_LOG(LOG_HUGE, "%s\n", buffer); /* Parse the JSON payload */ json_error_t error; json_t *root = json_loads(buffer, 0, &error); /* Notify the core, passing both the object and, since it may be needed, the error */ gateway->incoming_request(&janus_pfunix_transport, client->ts, NULL, client->admin, root, &error); } } } } socklen_t addrlen = sizeof(struct sockaddr_un); void *addr = g_malloc(addrlen+1); if(pfd > -1) { /* Unlink the path name first */ #ifdef HAVE_LIBSYSTEMD if((getsockname(pfd, (struct sockaddr *)addr, &addrlen) != -1) && (FALSE == sd_socket)) { #else if(getsockname(pfd, (struct sockaddr *)addr, &addrlen) != -1) { #endif JANUS_LOG(LOG_INFO, "Unlinking %s\n", ((struct sockaddr_un *)addr)->sun_path); unlink(((struct sockaddr_un *)addr)->sun_path); } /* Close the socket */ close(pfd); } pfd = -1; if(admin_pfd > -1) { /* Unlink the path name first */ #ifdef HAVE_LIBSYSTEMD if((getsockname(admin_pfd, (struct sockaddr *)addr, &addrlen) != -1) && (FALSE == admin_sd_socket)) { #else if(getsockname(admin_pfd, (struct sockaddr *)addr, &addrlen) != -1) { #endif JANUS_LOG(LOG_INFO, "Unlinking %s\n", ((struct sockaddr_un *)addr)->sun_path); unlink(((struct sockaddr_un *)addr)->sun_path); } /* Close the socket */ close(admin_pfd); } admin_pfd = -1; g_free(addr); g_hash_table_destroy(clients_by_path); g_hash_table_destroy(clients_by_fd); g_hash_table_destroy(clients); /* Done */ JANUS_LOG(LOG_INFO, "Unix Sockets thread ended\n"); return NULL; }
void window_remove(Window xwin) { g_assert(xwin != None); g_hash_table_remove(window_map, &xwin); }
gboolean handler_remove(Client *c, const char *key) { return g_hash_table_remove(c->handlers.table, key); }
void connection_remove_available_resource(const char * const resource) { g_hash_table_remove(available_resources, resource); }
void jabber_chat_remove_handle(JabberChat *chat, const char *handle) { g_hash_table_remove(chat->members, handle); }
void __connman_connection_gateway_remove(struct connman_service *service, enum connman_ipconfig_type type) { struct gateway_data *data = NULL; gboolean set_default4 = FALSE, set_default6 = FALSE; int do_ipv4 = FALSE, do_ipv6 = FALSE; int err; DBG("service %p type %d", service, type); if (type == CONNMAN_IPCONFIG_TYPE_IPV4) do_ipv4 = TRUE; else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) do_ipv6 = TRUE; else do_ipv4 = do_ipv6 = TRUE; __connman_service_nameserver_del_routes(service, type); data = g_hash_table_lookup(gateway_hash, service); if (data == NULL) return; if (do_ipv4 == TRUE && data->ipv4_gateway != NULL) set_default4 = data->ipv4_gateway->vpn; if (do_ipv6 == TRUE && data->ipv6_gateway != NULL) set_default6 = data->ipv6_gateway->vpn; DBG("ipv4 gateway %s ipv6 gateway %s vpn %d/%d", data->ipv4_gateway ? data->ipv4_gateway->gateway : "<null>", data->ipv6_gateway ? data->ipv6_gateway->gateway : "<null>", set_default4, set_default6); if (do_ipv4 == TRUE && data->ipv4_gateway != NULL && data->ipv4_gateway->vpn == TRUE && data->index >= 0) connman_inet_del_host_route(data->index, data->ipv4_gateway->gateway); if (do_ipv6 == TRUE && data->ipv6_gateway != NULL && data->ipv6_gateway->vpn == TRUE && data->index >= 0) connman_inet_del_ipv6_host_route(data->index, data->ipv6_gateway->gateway); err = disable_gateway(data, type); /* * We remove the service from the hash only if all the gateway * settings are to be removed. */ if (do_ipv4 == do_ipv6 || (data->ipv4_gateway != NULL && data->ipv6_gateway == NULL && do_ipv4 == TRUE) || (data->ipv6_gateway != NULL && data->ipv4_gateway == NULL && do_ipv6 == TRUE) ) { connman_service_unref(service); g_hash_table_remove(gateway_hash, service); } else DBG("Not yet removing gw ipv4 %p/%d ipv6 %p/%d", data->ipv4_gateway, do_ipv4, data->ipv6_gateway, do_ipv6); /* with vpn this will be called after the network was deleted, * we need to call set_default here because we will not recieve any * gateway delete notification. * We hit the same issue if remove_gateway() fails. */ if (set_default4 || set_default6 || err < 0) { data = find_default_gateway(); if (data != NULL) set_default_gateway(data, type); } }
static void on_search_ready (GObject *source, GAsyncResult *result, gpointer user_data) { ResolveClosure *closure = (ResolveClosure *) user_data; GrlTmdbRequest *request = GRL_TMDB_REQUEST (source); GValue *value; GError *error = NULL; GRL_DEBUG ("Initial search ready..."); if (!grl_tmdb_request_run_finish (GRL_TMDB_REQUEST (source), result, &error)) { resolve_closure_callback (closure, error); resolve_closure_free (closure); g_error_free (error); return; } value = grl_tmdb_request_get (request, "$.total_results"); if (g_value_get_int64 (value) == 0) { /* Nothing found */ resolve_closure_callback (closure, NULL); resolve_closure_free (closure); g_value_unset (value); g_free (value); return; } g_value_unset (value); g_free (value); value = grl_tmdb_request_get (request, "$.results[0].id"); if (value == NULL) { /* Cannot continue without id */ error = g_error_new_literal (GRL_CORE_ERROR, GRL_CORE_ERROR_RESOLVE_FAILED, _("Remote data does not contain valid identifier")); resolve_closure_callback (closure, error); resolve_closure_free (closure); g_error_free (error); return; } if (SHOULD_RESOLVE (GRL_TMDB_METADATA_KEY_TMDB_ID)) { char *tmdb_id = g_strdup_printf ("%" G_GINT64_FORMAT, g_value_get_int64 (value)); grl_data_set_string (GRL_DATA (closure->rs->media), GRL_TMDB_METADATA_KEY_TMDB_ID, tmdb_id); g_free (tmdb_id); } closure->id = g_value_get_int64 (value); g_value_unset (value); g_free (value); if (SHOULD_RESOLVE (GRL_METADATA_KEY_RATING)) { value = grl_tmdb_request_get (request, "$.results[0].vote_average"); if (value != NULL) { grl_media_set_rating (closure->rs->media, (float) g_value_get_double (value), 10.0f); g_value_unset (value); g_free (value); } g_hash_table_remove (closure->keys, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_RATING)); } /* Add thumbnails first, and posters and backdrops later. * Posters more likely make a good thumbnail than backdrops. */ if (SHOULD_RESOLVE (GRL_METADATA_KEY_THUMBNAIL)) { value = grl_tmdb_request_get (request, "$.results[0].poster_path"); if (value != NULL) { add_image (closure->self, closure->rs->media, GRL_METADATA_KEY_THUMBNAIL, g_value_get_string (value)); g_value_unset (value); g_free (value); } } if (SHOULD_RESOLVE (GRL_TMDB_METADATA_KEY_POSTER)) { value = grl_tmdb_request_get (request, "$.results[0].poster_path"); if (value != NULL) { add_image (closure->self, closure->rs->media, GRL_TMDB_METADATA_KEY_POSTER, g_value_get_string (value)); g_value_unset (value); g_free (value); } } if (SHOULD_RESOLVE (GRL_TMDB_METADATA_KEY_BACKDROP)) { value = grl_tmdb_request_get (request, "$.results[0].backdrop_path"); if (value != NULL) { add_image (closure->self, closure->rs->media, GRL_TMDB_METADATA_KEY_BACKDROP, g_value_get_string (value)); g_value_unset (value); g_free (value); } } if (SHOULD_RESOLVE (GRL_METADATA_KEY_ORIGINAL_TITLE)) { value = grl_tmdb_request_get (request, "$.results[0].original_title"); if (value != NULL) { grl_media_video_set_original_title (GRL_MEDIA_VIDEO (closure->rs->media), g_value_get_string (value)); g_value_unset (value); g_free (value); } g_hash_table_remove (closure->keys, GRLKEYID_TO_POINTER (GRL_METADATA_KEY_ORIGINAL_TITLE)); } remove_request (closure, request); /* Check if we need to do additional requests. */ if (closure->slow) { resolve_slow_details (closure); if (run_pending_requests (closure, G_MAXINT) > 0) return; } resolve_closure_callback (closure, NULL); resolve_closure_free (closure); }
void gdk_selection_convert(GdkWindow * requestor, GdkAtom selection, GdkAtom target, guint32 time) { HGLOBAL hdata; GdkSelProp *prop; guchar *ptr, *data, *datap, *p; guint i, length, slength; gchar *sel_name, *tgt_name; g_return_if_fail(requestor != NULL); if (GDK_DRAWABLE_DESTROYED(requestor)) return; GDK_NOTE(DND, (sel_name = gdk_atom_name(selection), tgt_name = gdk_atom_name(target), g_print("gdk_selection_convert: %#x %#x (%s) %#x (%s)\n", GDK_DRAWABLE_XID(requestor), selection, sel_name, target, tgt_name), g_free(sel_name), g_free(tgt_name))); if (selection == gdk_clipboard_atom) { /* Converting the CLIPBOARD selection means he wants the * contents of the clipboard. Get the clipboard data, * and store it for later. */ GDK_NOTE(DND, g_print("...OpenClipboard(%#x)\n", GDK_DRAWABLE_XID(requestor))); if (!OpenClipboard(GDK_DRAWABLE_XID(requestor))) { WIN32_API_FAILED("OpenClipboard"); return; } GDK_NOTE(DND, g_print("...GetClipboardData(CF_TEXT)\n")); if ((hdata = GetClipboardData(CF_TEXT)) != NULL) { if ((ptr = GlobalLock(hdata)) != NULL) { length = GlobalSize(hdata); GDK_NOTE(DND, g_print("...got data: %d bytes: %.10s\n", length, ptr)); slength = 0; p = ptr; for (i = 0; i < length; i++) { if (*p == '\0') break; else if (*p != '\r') slength++; p++; } data = datap = g_malloc(slength + 1); p = ptr; for (i = 0; i < length; i++) { if (*p == '\0') break; else if (*p != '\r') *datap++ = *p; p++; } *datap++ = '\0'; gdk_sel_prop_store(requestor, GDK_TARGET_STRING, 8, data, strlen(data) + 1); GlobalUnlock(hdata); } } GDK_NOTE(DND, g_print("...CloseClipboard()\n")); CloseClipboard(); /* Send ourselves an ersatz selection notify message so that we actually * fetch the data. */ SendMessage(GDK_DRAWABLE_XID(requestor), gdk_selection_notify_msg, selection, target); } else if (selection == gdk_win32_dropfiles_atom) { /* This means he wants the names of the dropped files. * gdk_dropfiles_filter already has stored the text/uri-list * data, tempoarily on gdk_root_parent's selection "property". */ GdkSelProp *prop; prop = g_hash_table_lookup(sel_prop_table, &GDK_DRAWABLE_XID(gdk_parent_root)); if (prop != NULL) { g_hash_table_remove(sel_prop_table, &GDK_DRAWABLE_XID(gdk_parent_root)); gdk_sel_prop_store(requestor, prop->type, prop->format, prop->data, prop->length); g_free(prop); SendMessage(GDK_DRAWABLE_XID(requestor), gdk_selection_notify_msg, selection, target); } } else { g_warning("gdk_selection_convert: General case not implemented"); } }
static void mex_download_queue_cache_insert (MexDownloadQueue *queue, const gchar *uri, gchar *data, gsize length) { DQCacheItem *item; guint iterations = 0; item = g_slice_new (DQCacheItem); item->length = length; item->data = data; item->age = queue->priv->current_age++; g_hash_table_insert (queue->priv->cache, g_strdup (uri), item); queue->priv->cache_size += item->length; MEX_NOTE (DOWNLOAD_QUEUE, "cache (%'" G_GSSIZE_FORMAT "): added: %s", queue->priv->cache_size, uri); /* keep cache size under MAX_CACHE_SIZE */ while (queue->priv->cache_size > MAX_CACHE_SIZE && iterations < 3) { DQCacheItem *value, *value_to_remove = NULL; gchar *key_to_remove = NULL, *key; guint lowest = G_MAXINT; GHashTableIter iter; g_hash_table_iter_init (&iter, queue->priv->cache); while (g_hash_table_iter_next (&iter, (gpointer*) &key, (gpointer*) &value)) { /* find the item with the lowest age to evict from the cache */ if (value->age < lowest) { lowest = value->age; key_to_remove = key; value_to_remove = value; } } if (value_to_remove) { queue->priv->cache_size -= value_to_remove->length; MEX_NOTE (DOWNLOAD_QUEUE, "cache (%'" G_GSSIZE_FORMAT "): removed: %s", queue->priv->cache_size, key_to_remove); g_hash_table_remove (queue->priv->cache, key_to_remove); } else { /* nothing to remove, hash table must be empty */ break; } iterations++; } }
static void _tracker_logSocket(Tracker* tracker, GLogLevelFlags level, SimulationTime interval) { if(!tracker->didLogSocketHeader) { tracker->didLogSocketHeader = TRUE; logging_log(G_LOG_DOMAIN, level, __FILE__, __FUNCTION__, __LINE__, "[shadow-heartbeat] [socket-header] descriptor-number,protocol-string,hostname:port-peer;" "inbuflen-bytes,inbufsize-bytes,outbuflen-bytes,outbufsize-bytes;recv-bytes,send-bytes;" "inbound-localhost-counters;outbound-localhost-counters;" "inbound-remote-counters;outbound-remote-counters|..." // for each socket "where counters are: %s", _tracker_getCounterHeaderString()); } /* construct the log message from all sockets we have in the hash table */ GString* msg = g_string_new("[shadow-heartbeat] [socket] "); SocketStats* ss = NULL; GHashTableIter socketIterator; g_hash_table_iter_init(&socketIterator, tracker->socketStats); /* as we iterate, keep track of sockets that we should remove. we cant remove them * during the iteration because it will invalidate the iterator */ GQueue* handlesToRemove = g_queue_new(); gint socketLogCount = 0; while(g_hash_table_iter_next(&socketIterator, NULL, (gpointer*)&ss)) { /* don't log tcp sockets that don't have peer IP/port set */ if(!ss || (ss->type == PTCP && !ss->peerIP)) { continue; } gsize totalRecvBytes = _tracker_sumBytes(&ss->local.inCounters.bytes) + _tracker_sumBytes(&ss->remote.inCounters.bytes); gsize totalSendBytes = _tracker_sumBytes(&ss->local.outCounters.bytes) + _tracker_sumBytes(&ss->remote.outCounters.bytes); gchar* inLocal = _tracker_getCounterString(&ss->local.inCounters); gchar* outLocal = _tracker_getCounterString(&ss->local.outCounters); gchar* inRemote = _tracker_getCounterString(&ss->remote.inCounters); gchar* outRemote = _tracker_getCounterString(&ss->remote.outCounters); /* print the node separator between node logs */ if(socketLogCount > 0) { g_string_append_printf(msg, "|"); } socketLogCount++; g_string_append_printf(msg, "%d,%s,%s:%u;" "%"G_GSIZE_FORMAT",%"G_GSIZE_FORMAT",%"G_GSIZE_FORMAT",%"G_GSIZE_FORMAT";" "%"G_GSIZE_FORMAT",%"G_GSIZE_FORMAT";" "%s;%s;%s;%s", ss->handle, /*inet_ntoa((struct in_addr){socket->peerIP})*/ ss->type == PTCP ? "TCP" : ss->type == PUDP ? "UDP" : ss->type == PLOCAL ? "LOCAL" : "UNKNOWN", ss->peerHostname, ss->peerPort, ss->inputBufferLength, ss->inputBufferSize, ss->outputBufferLength, ss->outputBufferSize, totalRecvBytes, totalSendBytes, inLocal, outLocal, inRemote, outRemote); g_free(inLocal); g_free(outLocal); g_free(inRemote); g_free(outRemote); /* check if we should remove the socket after iterating */ if(ss->removeAfterNextLog) { g_queue_push_tail(handlesToRemove, GINT_TO_POINTER(ss->handle)); } } if(socketLogCount > 0) { logging_log(G_LOG_DOMAIN, level, __FILE__, __FUNCTION__, __LINE__, "%s", msg->str); } /* free all the tracker instances of the sockets that were closed, now that we logged the info */ while(!g_queue_is_empty(handlesToRemove)) { gint handle = GPOINTER_TO_INT(g_queue_pop_head(handlesToRemove)); g_hash_table_remove(tracker->socketStats, &handle); } g_queue_free(handlesToRemove); g_string_free(msg, TRUE); }
gboolean ghb_dict_remove(GValue *gval, const gchar *key) { GHashTable *dict = g_value_get_boxed(gval); return g_hash_table_remove(dict, key); }
/* do http recv */ static gboolean do_http_recv(GIOChannel *source, GIOCondition condition, gpointer data) { int l; struct http_fetch_buf *hfb=(struct http_fetch_buf *)data; l=recv(hfb->fd,hfb->buf+hfb->bufpos,sizeof(hfb->buf)-hfb->bufpos-1,0); if (l<=0) { if ((l==0)&&(hfb->outfd>=0)) { close(hfb->outfd); if (!hfb->use_tempname) { struct stat st; char *nfname=g_strdup_printf("%s.",hfb->filename); if ((!stat(nfname,&st))&& ((!hfb->size_check)||(hfb->size_check(hfb->filename,hfb->data,st.st_size)))) { if (!rename(nfname,hfb->filename)) { g_hash_table_remove(tile_files_to_fetch,hfb->filename); } } else { unlink(nfname); } g_free(nfname); } if (hfb->finish_cb) hfb->finish_cb(hfb->url,hfb->filename,hfb->data); hfb->outfd=-1; } else { if (hfb->fail_cb) hfb->fail_cb(hfb->url,hfb->filename,hfb->data); } cleanup_http_buf(hfb); return FALSE; } if (hfb->outfd>=0) { write(hfb->outfd,hfb->buf,l); } else { char *datapos; int newbufpos=hfb->bufpos+l; if ((datapos=strstr(hfb->buf,"\r\n\r\n"))) { if (!strncmp(hfb->buf+9,"200 OK",6)) { if (hfb->use_tempname) { #ifdef _WIN32 mktemp(hfb->filename); hfb->outfd=open(hfb->filename,O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,0666); printf("opened: %s\n",hfb->filename); #else hfb->outfd=mkstemp(hfb->filename); #endif } else { char *nfname=g_strdup_printf("%s.",hfb->filename); #ifdef _WIN32 hfb->outfd=open(nfname,O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,0666); #else hfb->outfd=open(nfname,O_WRONLY|O_CREAT|O_TRUNC,0666); #endif fprintf(stderr,"opened %s\n",nfname); g_free(nfname); } } else { datapos[0]=0; fprintf(stderr,"%s\n",hfb->buf); } if (hfb->outfd<0) { if (hfb->fail_cb) hfb->fail_cb(hfb->url,hfb->filename,hfb->data); cleanup_http_buf(hfb); return FALSE; } write(hfb->outfd,datapos+4,newbufpos-4-((int)(datapos-hfb->buf))); hfb->bufpos=0; } else { hfb->bufpos=newbufpos; } } return TRUE; }
static void rule_changed (EFilterRule *rule, CamelFolder *folder) { EMailBackend *backend; EMailSession *session; GList *sources_uri = NULL, *sources_folder = NULL; GString *query; const gchar *full_name; full_name = camel_folder_get_full_name (folder); backend = em_vfolder_rule_get_backend (EM_VFOLDER_RULE (rule)); session = e_mail_backend_get_session (backend); /* if the folder has changed name, then add it, then remove the old manually */ if (strcmp (full_name, rule->name) != 0) { gchar *oldname; gpointer key; gpointer oldfolder; G_LOCK (vfolder); d(printf("Changing folder name in hash table to '%s'\n", rule->name)); if (g_hash_table_lookup_extended (vfolder_hash, full_name, &key, &oldfolder)) { g_hash_table_remove (vfolder_hash, key); g_free (key); g_hash_table_insert (vfolder_hash, g_strdup (rule->name), folder); G_UNLOCK (vfolder); } else { G_UNLOCK (vfolder); g_warning("couldn't find a vfolder rule in our table? %s", full_name); } oldname = g_strdup (full_name); /* FIXME Not passing a GCancellable or GError. */ camel_store_rename_folder_sync ( vfolder_store, oldname, rule->name, NULL, NULL); g_free (oldname); } d(printf("Filter rule changed? for folder '%s'!!\n", folder->name)); /* find any (currently available) folders, and add them to the ones to open */ rule_add_sources ( session, &((EMVFolderRule *) rule)->sources, &sources_folder, &sources_uri); G_LOCK (vfolder); if (((EMVFolderRule *) rule)->with == EM_VFOLDER_RULE_WITH_LOCAL || ((EMVFolderRule *) rule)->with == EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE) rule_add_sources ( session, &source_folders_local, &sources_folder, &sources_uri); if (((EMVFolderRule *) rule)->with == EM_VFOLDER_RULE_WITH_REMOTE_ACTIVE || ((EMVFolderRule *) rule)->with == EM_VFOLDER_RULE_WITH_LOCAL_REMOTE_ACTIVE) rule_add_sources ( session, &source_folders_remote, &sources_folder, &sources_uri); G_UNLOCK (vfolder); query = g_string_new(""); e_filter_rule_build_code (rule, query); vfolder_setup (session, folder, query->str, sources_uri, sources_folder); g_string_free (query, TRUE); }
void scan_filesystems(void) { FILE *mtab; gchar buf[1024]; struct statfs sfs; int count = 0; g_free(fs_list); fs_list = g_strdup(""); g_hash_table_foreach_remove(moreinfo, remove_filesystem_entries, NULL); mtab = fopen("/etc/mtab", "r"); if (!mtab) return; while (fgets(buf, 1024, mtab)) { gfloat size, used, avail; gchar **tmp; tmp = g_strsplit(buf, " ", 0); if (!statfs(tmp[1], &sfs)) { gfloat use_ratio; size = (float) sfs.f_bsize * (float) sfs.f_blocks; avail = (float) sfs.f_bsize * (float) sfs.f_bavail; used = size - avail; if (size == 0.0f) { continue; } if (avail == 0.0f) { use_ratio = 100.0f; } else { use_ratio = 100.0f * (used / size); } gchar *strsize = size_human_readable(size), *stravail = size_human_readable(avail), *strused = size_human_readable(used); gchar *strhash; if ((strhash = g_hash_table_lookup(moreinfo, tmp[0]))) { g_hash_table_remove(moreinfo, tmp[0]); g_free(strhash); } strreplacechr(tmp[0], "#", '_'); strhash = g_strdup_printf("[%s]\n" "Filesystem=%s\n" "Mounted As=%s\n" "Mount Point=%s\n" "Size=%s\n" "Used=%s\n" "Available=%s\n", tmp[0], tmp[2], strstr(tmp[3], "rw") ? "Read-Write" : "Read-Only", tmp[1], strsize, strused, stravail); g_hash_table_insert(moreinfo, g_strdup_printf("FS%d", ++count), strhash); fs_list = h_strdup_cprintf("$FS%d$%s=%.2f %% (%s of %s)|%s\n", fs_list, count, tmp[0], use_ratio, stravail, strsize, tmp[1]); g_free(strsize); g_free(stravail); g_free(strused); } g_strfreev(tmp); } fclose(mtab); }
static gboolean ldsm_check_all_mounts (gpointer data) { GList *mounts; GList *l; GList *check_mounts = NULL; GList *full_mounts = NULL; guint number_of_mounts; guint number_of_full_mounts; gboolean multiple_volumes = FALSE; gboolean other_usable_volumes = FALSE; /* We iterate through the static mounts in /etc/fstab first, seeing if * they're mounted by checking if the GUnixMountPoint has a corresponding GUnixMountEntry. * Iterating through the static mounts means we automatically ignore dynamically mounted media. */ mounts = g_unix_mount_points_get (time_read); for (l = mounts; l != NULL; l = l->next) { GUnixMountPoint *mount_point = l->data; GUnixMountEntry *mount; LdsmMountInfo *mount_info; const gchar *path; path = g_unix_mount_point_get_mount_path (mount_point); mount = g_unix_mount_at (path, time_read); g_unix_mount_point_free (mount_point); if (mount == NULL) { /* The GUnixMountPoint is not mounted */ continue; } mount_info = g_new0 (LdsmMountInfo, 1); mount_info->mount = mount; path = g_unix_mount_get_mount_path (mount); if (g_unix_mount_is_readonly (mount)) { ldsm_free_mount_info (mount_info); continue; } if (ldsm_mount_is_user_ignore (g_unix_mount_get_mount_path (mount))) { ldsm_free_mount_info (mount_info); continue; } if (gsd_should_ignore_unix_mount (mount)) { ldsm_free_mount_info (mount_info); continue; } if (statvfs (path, &mount_info->buf) != 0) { ldsm_free_mount_info (mount_info); continue; } if (ldsm_mount_is_virtual (mount_info)) { ldsm_free_mount_info (mount_info); continue; } check_mounts = g_list_prepend (check_mounts, mount_info); } g_list_free (mounts); number_of_mounts = g_list_length (check_mounts); if (number_of_mounts > 1) multiple_volumes = TRUE; for (l = check_mounts; l != NULL; l = l->next) { LdsmMountInfo *mount_info = l->data; if (!ldsm_mount_has_space (mount_info)) { full_mounts = g_list_prepend (full_mounts, mount_info); } else { g_hash_table_remove (ldsm_notified_hash, g_unix_mount_get_mount_path (mount_info->mount)); ldsm_free_mount_info (mount_info); } } number_of_full_mounts = g_list_length (full_mounts); if (number_of_mounts > number_of_full_mounts) other_usable_volumes = TRUE; ldsm_maybe_warn_mounts (full_mounts, multiple_volumes, other_usable_volumes); g_list_free (check_mounts); g_list_free (full_mounts); return TRUE; }
// Caller will acquire htbl locks cc_of_ret update_global_htbl_lockfree(htbl_type_e htbl_type, htbl_update_ops_e htbl_op, gpointer htbl_key, gpointer htbl_data, gboolean *new_entry) { GHashTable *cc_htbl; gpointer key, info_data; *new_entry = FALSE; guint old_count; switch(htbl_type) { case OFDEV: cc_htbl = cc_of_global.ofdev_htbl; if ((htbl_op == ADD) && (g_hash_table_contains(cc_htbl, htbl_key))) { htbl_op = UPD; /* create a new key. the insert operation will free this */ key = malloc(sizeof(cc_ofdev_key_t)); memcpy(key, htbl_key, sizeof(cc_ofdev_key_t)); info_data = malloc(sizeof(cc_ofdev_info_t)); memcpy(info_data, htbl_data, sizeof(cc_ofdev_info_t)); } break; case OFRW: cc_htbl = cc_of_global.ofrw_htbl; if ((htbl_op == ADD) && (g_hash_table_contains(cc_htbl, htbl_key))) { htbl_op = UPD; /* create a new key. the insert operation will free ths */ key = malloc(sizeof(cc_ofrw_key_t)); memcpy(key, htbl_key, sizeof(cc_ofrw_key_t)); info_data = malloc(sizeof(cc_ofrw_info_t)); memcpy(info_data, htbl_data, sizeof(cc_ofrw_info_t)); } break; case OFCHANN: cc_htbl = cc_of_global.ofchannel_htbl; if ((htbl_op == ADD) && (g_hash_table_contains(cc_htbl, htbl_key))) { /* create a new key. the insert operation will free this */ key = malloc(sizeof(cc_ofchannel_key_t)); memcpy(key, htbl_key, sizeof(cc_ofchannel_key_t)); info_data = malloc(sizeof(cc_ofchannel_info_t)); memcpy(info_data, htbl_data, sizeof(cc_ofchannel_info_t)); } break; default: CC_LOG_ERROR("%s(%d): invalid htbl type %d", __FUNCTION__, __LINE__, htbl_type); } if (htbl_op == ADD) { old_count = g_hash_table_size(cc_htbl); CC_LOG_DEBUG("%s(%d): insert operation for htbl_type %s", __FUNCTION__, __LINE__, (htbl_type == OFDEV)? "OFDEV": ((htbl_type == OFRW)?"OFRW":"OFCHANN")); if (htbl_type == OFDEV) { CC_LOG_DEBUG("%s(%d) key has controller ip 0x%x, switch ip 0x%x and port %d", __FUNCTION__, __LINE__, ((cc_ofdev_key_t *)htbl_key)->controller_ip_addr, ((cc_ofdev_key_t *)htbl_key)->switch_ip_addr, ((cc_ofdev_key_t *)htbl_key)->controller_L4_port); } else if (htbl_type == OFRW) { CC_LOG_DEBUG("%s(%d) insert key has socket %d", __FUNCTION__, __LINE__, ((cc_ofrw_key_t *)htbl_key)->rw_sockfd); CC_LOG_DEBUG("%s(%d) insert info has l4 proto %s", __FUNCTION__, __LINE__, (((cc_ofrw_info_t *)htbl_data)->layer4_proto == TCP)? "TCP":((((cc_ofrw_info_t *)htbl_data)->layer4_proto == UDP)? "UDP":"INVALID")); if (g_hash_table_contains(cc_htbl, htbl_key)) { CC_LOG_DEBUG("(%s(%d): OFRW htbl already contains %d", __FUNCTION__, __LINE__, ((cc_ofrw_key_t *)htbl_key)->rw_sockfd); } } else if (htbl_type == OFCHANN) { CC_LOG_DEBUG("%s(%d) ofchannel key dp/aux %lu/%hu", __FUNCTION__, __LINE__, ((cc_ofchannel_key_t *)htbl_key)->dp_id, ((cc_ofchannel_key_t *)htbl_key)->aux_id); } g_hash_table_insert(cc_htbl, htbl_key, htbl_data); if (htbl_type == OFDEV) { } else if (htbl_type == OFRW) { gpointer rwht_key = NULL, rwht_info = NULL; if (g_hash_table_contains(cc_htbl, htbl_key)) { CC_LOG_DEBUG("(%s(%d): OFRW htbl contains %d", __FUNCTION__, __LINE__, ((cc_ofrw_key_t *)htbl_key)->rw_sockfd); } CC_LOG_DEBUG("OFRW htbl size after insert of %d: %d", ((cc_ofrw_key_t *)htbl_key)->rw_sockfd, g_hash_table_size(cc_htbl)); if (g_hash_table_lookup_extended(cc_of_global.ofrw_htbl, htbl_key, &rwht_key, &rwht_info) == FALSE) { CC_LOG_DEBUG("extended lookup failed"); } else { cc_ofrw_key_t *rw_key = NULL; cc_ofrw_info_t *rw_info = NULL; rw_key = (cc_ofrw_key_t *)rwht_key; rw_info = (cc_ofrw_info_t *)rwht_info; CC_LOG_DEBUG("extended lookup passed"); CC_LOG_DEBUG("key: rw_sockfd: %d " "info: layer4_proto: %s " "info: poll thread name: %s" "info: devkey controller ip: 0x%x" "info: devkey switch ip: 0x%x" "info: devkey l4port: %d", rw_key->rw_sockfd, (rw_info->layer4_proto == TCP)? "TCP":"UDP", rw_info->thr_mgr_p->tname, rw_info->dev_key.controller_ip_addr, rw_info->dev_key.switch_ip_addr, rw_info->dev_key.controller_L4_port); } CC_LOG_DEBUG("%s(%d) key has socket %d", __FUNCTION__, __LINE__, ((cc_ofrw_key_t *)htbl_key)->rw_sockfd); } if (g_hash_table_size(cc_htbl) > old_count) { *new_entry = TRUE; } } else if (htbl_op == DEL) { CC_LOG_DEBUG("%s(%d).. HTBL DEL ", __FUNCTION__, __LINE__); if (g_hash_table_contains(cc_htbl, htbl_key)) { CC_LOG_DEBUG("%s(%d) DEL operation found entry", __FUNCTION__, __LINE__); } if (g_hash_table_remove(cc_htbl, htbl_key) == FALSE) { CC_LOG_DEBUG("%s(%d) DEL unsuccessful", __FUNCTION__, __LINE__); return CC_OF_EHTBL; } } else if (htbl_op == UPD) { old_count = g_hash_table_size(cc_htbl); CC_LOG_DEBUG("%s(%d): replace existing entry operation", __FUNCTION__, __LINE__); if (htbl_type == OFDEV) { CC_LOG_DEBUG("%s(%d) key has controller ip 0x%x, switch ip 0x%x and port %d", __FUNCTION__, __LINE__, ((cc_ofdev_key_t *)key)->controller_ip_addr, ((cc_ofdev_key_t *)key)->switch_ip_addr, ((cc_ofdev_key_t *)key)->controller_L4_port); } g_hash_table_insert(cc_htbl, key, info_data); if (htbl_type == OFDEV) { } else if (htbl_type == OFCHANN) { } else if (htbl_type == OFRW) { gpointer rwht_key = NULL, rwht_info = NULL; if (g_hash_table_contains(cc_htbl, htbl_key)) { CC_LOG_DEBUG("(%s(%d): OFRW htbl contains %d", __FUNCTION__, __LINE__, ((cc_ofrw_key_t *)htbl_key)->rw_sockfd); } CC_LOG_DEBUG("OFRW htbl size after insert of %d: %d", ((cc_ofrw_key_t *)htbl_key)->rw_sockfd, g_hash_table_size(cc_htbl)); if (g_hash_table_lookup_extended(cc_of_global.ofrw_htbl, htbl_key, &rwht_key, &rwht_info) == FALSE) { CC_LOG_DEBUG("extended lookup failed"); } else { cc_ofrw_key_t *rw_key = NULL; cc_ofrw_info_t *rw_info = NULL; rw_key = (cc_ofrw_key_t *)rwht_key; rw_info = (cc_ofrw_info_t *)rwht_info; CC_LOG_DEBUG("extended lookup passed"); CC_LOG_DEBUG("key: rw_sockfd: %d " "info: layer4_proto: %s " "info: poll thread name: %s" "info: devkey controller ip: 0x%x" "info: devkey switch ip: 0x%x" "info: devkey l4port: %d", rw_key->rw_sockfd, (rw_info->layer4_proto == TCP)? "TCP":"UDP", rw_info->thr_mgr_p->tname, rw_info->dev_key.controller_ip_addr, rw_info->dev_key.switch_ip_addr, rw_info->dev_key.controller_L4_port); } } if (g_hash_table_size(cc_htbl) > old_count) { *new_entry = TRUE; } } return CC_OF_OK; }
/** * Locate statistics structure for the file. * * If a SHA1 is given, we search by SHA1. Otherwise we search by (name, size) * and if the record is missing the SHA1, probably because it was not * available at the time of insertion, then it is added to the structure * and recorded as such. */ static struct ul_stats * upload_stats_find(const struct sha1 *sha1, const char *pathname, guint64 size) { struct ul_stats *s = NULL; if (upload_stats_list) { static const struct ul_stats zero_stats; struct ul_stats key; gconstpointer orig_key; g_assert(upload_stats_by_sha1); if (sha1) { s = g_hash_table_lookup(upload_stats_by_sha1, sha1); if (s) goto done; /* Found it by SHA1 */ } key = zero_stats; key.pathname = atom_str_get(pathname); key.size = size; if (hash_list_find(upload_stats_list, &key, &orig_key)) s = deconstify_gpointer(orig_key); atom_str_free_null(&key.pathname); if (s && sha1) { /* Was missing from the by-SHA1 table */ if (NULL == s->sha1) { /* SHA1 was unknown */ s->sha1 = atom_sha1_get(sha1); } else { /* SHA1 changed, file was modified */ struct ul_stats *old = g_hash_table_lookup(upload_stats_by_sha1, s->sha1); g_assert(old == s); /* Must be the same filename entry */ g_hash_table_remove(upload_stats_by_sha1, s->sha1); atom_sha1_free(s->sha1); s->sha1 = atom_sha1_get(sha1); } gm_hash_table_insert_const(upload_stats_by_sha1, s->sha1, s); } } done: /* We guarantee the SHA1 is present in the record if known */ g_assert(!(s && sha1) || s->sha1); /* Postcondition: if we return something, it must be "correct" */ if (s != NULL) { g_assert(atom_is_str(s->pathname)); g_assert(atom_is_str(s->filename)); g_assert(s->norm >= 0.0); } return s; }
static gboolean ggp_roster_reply_list_read_buddy(PurpleConnection *gc, PurpleXmlNode *node, ggp_roster_content *content, GHashTable *remove_buddies) { gchar *alias, *group_name = NULL; uin_t uin; gboolean succ = TRUE; PurpleXmlNode *group_list, *group_elem; PurpleBuddy *buddy = NULL; PurpleGroup *group = NULL; PurpleGroup *currentGroup; gboolean alias_changed; PurpleAccount *account = purple_connection_get_account(gc); succ &= ggp_xml_get_string(node, "ShowName", &alias); succ &= ggp_xml_get_uint(node, "GGNumber", &uin); group_list = purple_xmlnode_get_child(node, "Groups"); succ &= (group_list != NULL); if (!succ) { g_free(alias); g_return_val_if_reached(FALSE); } g_hash_table_insert(content->contact_nodes, GINT_TO_POINTER(uin), node); /* check, if alias is set */ if (strlen(alias) == 0 || strcmp(alias, ggp_uin_to_str(uin)) == 0) { g_free(alias); alias = NULL; } /* getting (eventually creating) group */ group_elem = purple_xmlnode_get_child(group_list, "GroupId"); while (group_elem != NULL) { gchar *id; gboolean isbot; if (!ggp_xml_get_string(group_elem, NULL, &id)) continue; isbot = (0 == g_strcmp0(id, content->bots_group_id)); group_name = g_hash_table_lookup(content->group_names, id); g_free(id); /* we don't want to import bots; * they are inserted to roster by default */ if (isbot) { g_free(alias); return TRUE; } if (group_name != NULL) break; group_elem = purple_xmlnode_get_next_twin(group_elem); } if (group_name) { group = purple_blist_find_group(group_name); if (!group) { group = purple_group_new(group_name); purple_blist_add_group(group, NULL); } } /* add buddy, if doesn't exists */ buddy = purple_blist_find_buddy(account, ggp_uin_to_str(uin)); g_hash_table_remove(remove_buddies, GINT_TO_POINTER(uin)); if (!buddy) { purple_debug_info("gg", "ggp_roster_reply_list_read_buddy: " "adding %u (%s) to buddy list\n", uin, alias); buddy = purple_buddy_new(account, ggp_uin_to_str(uin), alias); purple_blist_add_buddy(buddy, NULL, group, NULL); ggp_roster_set_synchronized(gc, buddy, TRUE); g_free(alias); return TRUE; } /* buddy exists, but is not synchronized - local list has priority */ if (!ggp_roster_is_synchronized(buddy)) { purple_debug_misc("gg", "ggp_roster_reply_list_read_buddy: " "ignoring not synchronized %u (%s)\n", uin, purple_buddy_get_name(buddy)); g_free(alias); return TRUE; } currentGroup = ggp_purplew_buddy_get_group_only(buddy); alias_changed = (0 != g_strcmp0(alias, purple_buddy_get_alias_only(buddy))); if (currentGroup == group && !alias_changed) { g_free(alias); return TRUE; } purple_debug_misc("gg", "ggp_roster_reply_list_read_buddy: " "updating %u (%s) - alias=\"%s\"->\"%s\", group=%p->%p (%s)\n", uin, purple_buddy_get_name(buddy), purple_buddy_get_alias(buddy), alias, currentGroup, group, group_name); if (alias_changed) purple_buddy_set_local_alias(buddy, alias); if (currentGroup != group) purple_blist_add_buddy(buddy, NULL, group, NULL); g_free(alias); return TRUE; }