static void git_stash_list_command_handle_output (GitCommand *git_command, const gchar *output) { GitStashListCommand *self; GMatchInfo *match_info; gchar *stash_id; gchar *stash_number; gchar *stash_message; GitStash *stash; self = GIT_STASH_LIST_COMMAND (git_command); match_info = NULL; stash_id = NULL; stash_message = NULL; stash = NULL; if (g_regex_match (self->priv->stash_regex, output, 0, &match_info)) { stash_id = g_match_info_fetch (match_info, 1); stash_number = g_match_info_fetch (match_info, 2); stash_message = g_match_info_fetch (match_info, 3); stash = git_stash_new (stash_id, stash_message, atoi (stash_number)); g_free (stash_id); g_free (stash_number); g_free (stash_message); g_queue_push_head (self->priv->output, stash); anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command)); } if (match_info) g_match_info_free (match_info); }
static void add_new_position(const gchar *utf8_filename, gint pos) { filepos *npos; guint i; if (queue_pos_matches(nav_queue_pos, utf8_filename, pos)) return; /* prevent duplicates */ npos = g_new0(filepos, 1); npos->file = utf8_filename; npos->pos = pos; /* if we've jumped to a new position from inside the queue rather than going forward */ if (nav_queue_pos > 0) { for (i = 0; i < nav_queue_pos; i++) { g_free(g_queue_pop_head(navigation_queue)); } nav_queue_pos = 0; } g_queue_push_head(navigation_queue, npos); adjust_buttons(); }
static void invoke_user_callback (HTTPServer *http_server, RequestData **request_data_pointer) { RequestData *request_data = *request_data_pointer; GstClockTime cb_ret; cb_ret = http_server->user_callback (request_data, http_server->user_data); if (cb_ret == GST_CLOCK_TIME_NONE) { /* block */ g_mutex_lock (&(http_server->block_queue_mutex)); request_data->status = HTTP_BLOCK; /* block time out is 300ms */ request_data->wakeup_time = gst_clock_get_time (http_server->system_clock) + 300 * GST_MSECOND; g_queue_push_head (http_server->block_queue, request_data_pointer); g_mutex_unlock (&(http_server->block_queue_mutex)); } else if (cb_ret > 0) { /* idle */ GST_DEBUG ("insert idle queue end, sock %d wakeuptime %lu", request_data->sock, cb_ret); http_server->encoder_click += 1; request_data->wakeup_time = cb_ret; g_mutex_lock (&(http_server->idle_queue_mutex)); while (g_tree_lookup (http_server->idle_queue, &(request_data->wakeup_time)) != NULL) { /* avoid time conflict */ request_data->wakeup_time++; } request_data->status = HTTP_IDLE; g_tree_insert (http_server->idle_queue, &(request_data->wakeup_time), request_data_pointer); g_cond_signal (&(http_server->idle_queue_cond)); g_mutex_unlock (&(http_server->idle_queue_mutex)); } else { /* finish */ GST_DEBUG ("callback return 0, request finish, sock %d", request_data->sock); request_data_release (http_server, request_data_pointer); } }
static gboolean photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *object) { PhotosItemManager *self = PHOTOS_ITEM_MANAGER (manager); PhotosItemManagerPrivate *priv = self->priv; GtkRecentManager *recent; gboolean ret_val; const gchar *uri; g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (object) || object == NULL, FALSE); ret_val = PHOTOS_BASE_MANAGER_CLASS (photos_item_manager_parent_class)->set_active_object (manager, object); if (!ret_val) goto out; if (object == NULL) goto out; if (photos_base_item_is_collection (PHOTOS_BASE_ITEM (object))) { GObject *collection; collection = photos_base_manager_get_active_object (priv->col_mngr); g_queue_push_head (priv->collection_path, (collection != NULL) ? g_object_ref (collection) : NULL); photos_base_manager_set_active_object (priv->col_mngr, object); goto out; } recent = gtk_recent_manager_get_default (); uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (object)); gtk_recent_manager_add_item (recent, uri); out: return ret_val; }
static void msn_soap_message_send_internal(MsnSession *session, MsnSoapMessage *message, const char *host, const char *path, gboolean secure, MsnSoapCallback cb, gpointer cb_data, gboolean first) { MsnSoapConnection *conn = msn_soap_get_connection(session, host); MsnSoapRequest *req = g_new0(MsnSoapRequest, 1); req->path = g_strdup(path); req->message = message; req->secure = secure; req->cb = cb; req->cb_data = cb_data; if (first) { g_queue_push_head(conn->queue, req); } else { g_queue_push_tail(conn->queue, req); } if (conn->run_timer == 0) conn->run_timer = purple_timeout_add(0, msn_soap_connection_run, conn); }
void qq_tray_stop_blinking_for(QQTray *tray, const gchar *uin) { if(tray == NULL || uin == NULL){ return; } QQTrayPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE(tray, qq_tray_get_type() , QQTrayPriv); gchar *tmpuin = NULL; g_queue_clear(priv -> tmp_queue); while(!g_queue_is_empty(priv -> blinking_queue)){ tmpuin = g_queue_pop_tail(priv -> blinking_queue); if(g_strcmp0(tmpuin, uin) == 0){ //remove it g_free(tmpuin); break; } g_queue_push_head(priv -> tmp_queue, tmpuin); } while(!g_queue_is_empty(priv -> tmp_queue)){ g_queue_push_tail(priv -> blinking_queue , g_queue_pop_head(priv -> tmp_queue)); } GdkPixbuf *pb; if(g_queue_is_empty(priv -> blinking_queue)){ // no more blinking gtk_status_icon_set_blinking(GTK_STATUS_ICON(tray), FALSE); pb = gdk_pixbuf_new_from_file(IMGDIR"/webqq_icon.png", NULL); gtk_status_icon_set_from_pixbuf(GTK_STATUS_ICON(tray), pb); g_object_unref(pb); }else{ qq_tray_blinking(tray, g_queue_peek_tail(priv -> blinking_queue)); } }
static gboolean photos_item_manager_set_window_mode_internal (PhotosItemManager *self, PhotosWindowMode mode, PhotosWindowMode *out_old_mode) { PhotosWindowMode old_mode; gboolean ret_val = FALSE; old_mode = self->mode; if (old_mode == mode) goto out; g_queue_push_head (self->history, GINT_TO_POINTER (old_mode)); self->mode = mode; if (out_old_mode != NULL) *out_old_mode = old_mode; ret_val = TRUE; out: return ret_val; }
gboolean ide_xml_find_opening_element (const GtkTextIter *start, const GtkTextIter *end, GtkTextIter *found_element_start, GtkTextIter *found_element_end) { IdeXmlElementTagType tag_type; GQueue *element_queue; guint element_queue_length = 0; gchar *element_name = NULL; g_return_val_if_fail (found_element_start != NULL, FALSE); g_return_val_if_fail (found_element_end != NULL, FALSE); tag_type = ide_xml_get_element_tag_type (start, end); if (tag_type != IDE_XML_ELEMENT_TAG_END) return FALSE; element_name = ide_xml_get_element_name (start, end); if (element_name == NULL) return FALSE; element_queue = g_queue_new(); g_queue_push_head(element_queue, element_name); while (g_queue_get_length (element_queue) > 0 && ide_xml_find_previous_element (start, found_element_start, found_element_end)) { tag_type = ide_xml_get_element_tag_type (found_element_start, found_element_end); if (tag_type == IDE_XML_ELEMENT_TAG_END) { element_name = ide_xml_get_element_name (found_element_start, found_element_end); if (element_name != NULL) g_queue_push_head(element_queue, element_name); } else if (tag_type == IDE_XML_ELEMENT_TAG_START) { element_name = ide_xml_get_element_name (found_element_start, found_element_end); if (element_name != NULL) { if(g_strcmp0 (g_queue_peek_head(element_queue), element_name) == 0) { g_free (g_queue_pop_head (element_queue)); g_free (element_name); } /*Unbalanced element.Stop parsing*/ else { g_free (element_name); goto completed; } } } start = found_element_start; } completed: element_queue_length = g_queue_get_length (element_queue); g_queue_free_full (element_queue, g_free); return element_queue_length > 0 ? FALSE : TRUE; }
static void _tcp_flush(TCP* tcp) { MAGIC_ASSERT(tcp); /* make sure our information is up to date */ _tcp_updateReceiveWindow(tcp); _tcp_updateSendWindow(tcp); /* flush packets that can now be sent to socket */ while(g_queue_get_length(tcp->throttledOutput) > 0) { /* get the next throttled packet, in sequence order */ Packet* packet = g_queue_pop_head(tcp->throttledOutput); /* break out if we have no packets left */ if(!packet) { break; } guint length = packet_getPayloadLength(packet); if(length > 0) { PacketTCPHeader header; packet_getTCPHeader(packet, &header); /* we cant send it if our window is too small */ gboolean fitsInWindow = (header.sequence < (tcp->send.unacked + tcp->send.window)) ? TRUE : FALSE; /* we cant send it if we dont have enough space */ gboolean fitsInBuffer = (length <= socket_getOutputBufferSpace(&(tcp->super))) ? TRUE : FALSE; if(!fitsInBuffer || !fitsInWindow) { /* we cant send the packet yet */ g_queue_push_head(tcp->throttledOutput, packet); break; } else { /* we will send: store length in virtual retransmission buffer * so we can reduce buffer space consumed when we receive the ack */ _tcp_addRetransmit(tcp, header.sequence, length); } } /* packet is sendable, we removed it from out buffer */ tcp->throttledOutputLength -= length; /* update TCP header to our current advertised window and acknowledgement */ packet_updateTCP(packet, tcp->receive.next, tcp->receive.window); /* keep track of the last things we sent them */ tcp->send.lastAcknowledgement = tcp->receive.next; tcp->send.lastWindow = tcp->receive.window; /* socket will queue it ASAP */ gboolean success = socket_addToOutputBuffer(&(tcp->super), packet); /* we already checked for space, so this should always succeed */ g_assert(success); } /* any packets now in order can be pushed to our user input buffer */ while(g_queue_get_length(tcp->unorderedInput) > 0) { Packet* packet = g_queue_pop_head(tcp->unorderedInput); PacketTCPHeader header; packet_getTCPHeader(packet, &header); if(header.sequence == tcp->receive.next) { /* move from the unordered buffer to user input buffer */ gboolean fitInBuffer = socket_addToInputBuffer(&(tcp->super), packet); if(fitInBuffer) { tcp->unorderedInputLength -= packet_getPayloadLength(packet); (tcp->receive.next)++; continue; } } /* we could not buffer it because its out of order or we have no space */ g_queue_push_head(tcp->unorderedInput, packet); break; } /* check if user needs an EOF signal */ gboolean wantsEOF = ((tcp->flags & TCPF_LOCAL_CLOSED) || (tcp->flags & TCPF_REMOTE_CLOSED)) ? TRUE : FALSE; if(wantsEOF) { /* if anyone closed, can't send anymore */ tcp->error |= TCPE_SEND_EOF; if((tcp->receive.next >= tcp->receive.end) && !(tcp->flags & TCPF_EOF_SIGNALED)) { /* user needs to read a 0 so it knows we closed */ tcp->error |= TCPE_RECEIVE_EOF; descriptor_adjustStatus((Descriptor*)tcp, DS_READABLE, TRUE); } } }
static void post_video_event(int event) { fs_mutex_lock(g_video_event_mutex); g_queue_push_head(g_video_event_queue, FS_INT_TO_POINTER(event)); fs_mutex_unlock(g_video_event_mutex); }
/* * Process the send return SOAP string * If got SOAP Fault,get the lock key,and resend it. */ static void msn_oim_send_read_cb(MsnSoapMessage *request, MsnSoapMessage *response, gpointer data) { MsnOim *oim = data; MsnOimSendReq *msg = g_queue_pop_head(oim->send_queue); g_return_if_fail(msg != NULL); if (response == NULL) { purple_debug_info("msn", "cannot send OIM: %s\n", msg->oim_msg); } else { xmlnode *faultNode = xmlnode_get_child(response->xml, "Body/Fault"); if (faultNode == NULL) { /*Send OK! return*/ purple_debug_info("msn", "sent OIM: %s\n", msg->oim_msg); } else { xmlnode *faultcode = xmlnode_get_child(faultNode, "faultcode"); if (faultcode) { char *faultcode_str = xmlnode_get_data(faultcode); if (g_str_equal(faultcode_str, "q0:AuthenticationFailed")) { xmlnode *challengeNode = xmlnode_get_child(faultNode, "detail/LockKeyChallenge"); if (challengeNode == NULL) { if (oim->challenge) { g_free(oim->challenge); oim->challenge = NULL; purple_debug_info("msn", "Resending OIM: %s\n", msg->oim_msg); g_queue_push_head(oim->send_queue, msg); msn_oim_send_msg(oim); } else { purple_debug_info("msn", "Can't find lock key for OIM: %s\n", msg->oim_msg); } } else { char buf[33]; char *challenge = xmlnode_get_data(challengeNode); msn_handle_chl(challenge, buf); g_free(oim->challenge); oim->challenge = g_strndup(buf, sizeof(buf)); g_free(challenge); purple_debug_info("msn", "Found lockkey:{%s}\n", oim->challenge); /*repost the send*/ purple_debug_info("msn", "Resending OIM: %s\n", msg->oim_msg); g_queue_push_head(oim->send_queue, msg); msn_oim_send_msg(oim); } } else { /* Report the error */ const char *str_reason; if (g_str_equal(faultcode_str, "q0:SystemUnavailable")) { str_reason = _("Message was not sent because the system is " "unavailable. This normally happens when the " "user is blocked or does not exist."); } else if (g_str_equal(faultcode_str, "q0:SenderThrottleLimitExceeded")) { str_reason = _("Message was not sent because messages " "are being sent too quickly."); } else if (g_str_equal(faultcode_str, "q0:InvalidContent")) { str_reason = _("Message was not sent because an unknown " "encoding error occurred."); } else { str_reason = _("Message was not sent because an unknown " "error occurred."); } msn_session_report_user(oim->session, msg->to_member, str_reason, PURPLE_MESSAGE_ERROR); msn_session_report_user(oim->session, msg->to_member, msg->oim_msg, PURPLE_MESSAGE_RAW); } g_free(faultcode_str); } } } }
static GstPadProbeReturn handle_mq_input (GstPad * pad, GstPadProbeInfo * info, MqStreamCtx * ctx) { GstSplitMuxSink *splitmux = ctx->splitmux; GstBuffer *buf; MqStreamBuf *buf_info = NULL; GstClockTime ts; gboolean loop_again; gboolean keyframe = FALSE; GST_LOG_OBJECT (pad, "Fired probe type 0x%x\n", info->type); /* FIXME: Handle buffer lists, until then make it clear they won't work */ if (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST) { g_warning ("Buffer list handling not implemented"); return GST_PAD_PROBE_DROP; } if (info->type & GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) { GstEvent *event = gst_pad_probe_info_get_event (info); switch (GST_EVENT_TYPE (event)) { case GST_EVENT_SEGMENT: gst_event_copy_segment (event, &ctx->in_segment); break; case GST_EVENT_FLUSH_STOP: GST_SPLITMUX_LOCK (splitmux); gst_segment_init (&ctx->in_segment, GST_FORMAT_UNDEFINED); ctx->in_eos = FALSE; ctx->in_bytes = 0; ctx->in_running_time = 0; GST_SPLITMUX_UNLOCK (splitmux); break; case GST_EVENT_EOS: GST_SPLITMUX_LOCK (splitmux); ctx->in_eos = TRUE; if (splitmux->state == SPLITMUX_STATE_STOPPED) goto beach; if (ctx->is_video) { GST_INFO_OBJECT (splitmux, "Got Video EOS. Finishing up"); /* Act as if this is a new keyframe with infinite timestamp */ splitmux->max_in_running_time = GST_CLOCK_TIME_NONE; splitmux->state = SPLITMUX_STATE_WAITING_GOP_COMPLETE; /* Wake up other input pads to collect this GOP */ GST_SPLITMUX_BROADCAST (splitmux); check_completed_gop (splitmux, ctx); } else if (splitmux->state == SPLITMUX_STATE_WAITING_GOP_COMPLETE) { /* If we are waiting for a GOP to be completed (ie, for aux * pads to catch up), then this pad is complete, so check * if the whole GOP is. */ check_completed_gop (splitmux, ctx); } GST_SPLITMUX_UNLOCK (splitmux); break; default: break; } return GST_PAD_PROBE_PASS; } buf = gst_pad_probe_info_get_buffer (info); ctx->in_running_time = gst_segment_to_running_time (&ctx->in_segment, GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf)); buf_info = mq_stream_buf_new (); if (GST_BUFFER_PTS_IS_VALID (buf)) ts = GST_BUFFER_PTS (buf); else ts = GST_BUFFER_DTS (buf); GST_SPLITMUX_LOCK (splitmux); if (splitmux->state == SPLITMUX_STATE_STOPPED) goto beach; /* If this buffer has a timestamp, advance the input timestamp of the * stream */ if (GST_CLOCK_TIME_IS_VALID (ts)) { GstClockTime running_time = gst_segment_to_running_time (&ctx->in_segment, GST_FORMAT_TIME, GST_BUFFER_TIMESTAMP (buf)); if (GST_CLOCK_TIME_IS_VALID (running_time) && (ctx->in_running_time == GST_CLOCK_TIME_NONE || running_time > ctx->in_running_time)) ctx->in_running_time = running_time; } /* Try to make sure we have a valid running time */ if (!GST_CLOCK_TIME_IS_VALID (ctx->in_running_time)) { ctx->in_running_time = gst_segment_to_running_time (&ctx->in_segment, GST_FORMAT_TIME, ctx->in_segment.start); } buf_info->run_ts = ctx->in_running_time; buf_info->buf_size = gst_buffer_get_size (buf); /* Update total input byte counter for overflow detect */ ctx->in_bytes += buf_info->buf_size; GST_DEBUG_OBJECT (pad, "Buf TS %" GST_TIME_FORMAT " total in_bytes %" G_GSIZE_FORMAT, GST_TIME_ARGS (buf_info->run_ts), ctx->in_bytes); loop_again = TRUE; do { if (ctx->flushing) break; switch (splitmux->state) { case SPLITMUX_STATE_COLLECTING_GOP_START: if (ctx->is_video) { /* If a keyframe, we have a complete GOP */ if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT) || !GST_CLOCK_TIME_IS_VALID (ctx->in_running_time) || splitmux->max_in_running_time >= ctx->in_running_time) { /* Pass this buffer through */ loop_again = FALSE; break; } GST_INFO_OBJECT (pad, "Have keyframe with running time %" GST_TIME_FORMAT, GST_TIME_ARGS (ctx->in_running_time)); keyframe = TRUE; splitmux->state = SPLITMUX_STATE_WAITING_GOP_COMPLETE; splitmux->max_in_running_time = ctx->in_running_time; /* Wake up other input pads to collect this GOP */ GST_SPLITMUX_BROADCAST (splitmux); check_completed_gop (splitmux, ctx); } else { /* We're still waiting for a keyframe on the video pad, sleep */ GST_LOG_OBJECT (pad, "Sleeping for GOP start"); GST_SPLITMUX_WAIT (splitmux); GST_LOG_OBJECT (pad, "Done sleeping for GOP start state now %d", splitmux->state); } break; case SPLITMUX_STATE_WAITING_GOP_COMPLETE: /* After a GOP start is found, this buffer might complete the GOP */ /* If we overran the target timestamp, it might be time to process * the GOP, otherwise bail out for more data */ GST_LOG_OBJECT (pad, "Checking TS %" GST_TIME_FORMAT " against max %" GST_TIME_FORMAT, GST_TIME_ARGS (ctx->in_running_time), GST_TIME_ARGS (splitmux->max_in_running_time)); if (ctx->in_running_time < splitmux->max_in_running_time) { loop_again = FALSE; break; } GST_LOG_OBJECT (pad, "Collected last packet of GOP. Checking other pads"); check_completed_gop (splitmux, ctx); break; case SPLITMUX_STATE_ENDING_FILE: case SPLITMUX_STATE_START_NEXT_FRAGMENT: /* A fragment is ending, wait until that's done before continuing */ GST_DEBUG_OBJECT (pad, "Sleeping for fragment restart"); GST_SPLITMUX_WAIT (splitmux); GST_DEBUG_OBJECT (pad, "Done sleeping for fragment restart state now %d", splitmux->state); break; default: loop_again = FALSE; break; } } while (loop_again); if (keyframe) { splitmux->queued_gops++; buf_info->keyframe = TRUE; } /* Now add this buffer to the queue just before returning */ g_queue_push_head (&ctx->queued_bufs, buf_info); /* Check the buffer will fit in the mq */ check_queue_length (splitmux, ctx); GST_LOG_OBJECT (pad, "Returning to queue buffer %" GST_PTR_FORMAT " run ts %" GST_TIME_FORMAT, buf, GST_TIME_ARGS (ctx->in_running_time)); GST_SPLITMUX_UNLOCK (splitmux); return GST_PAD_PROBE_PASS; beach: GST_SPLITMUX_UNLOCK (splitmux); if (buf_info) mq_stream_buf_free (buf_info); return GST_PAD_PROBE_PASS; }
// the cache retains one reference, and the caller gets another one. the // entry must be unreffed when the caller is done with it. void _openslide_cache_put(struct _openslide_cache *cache, void *plane, int64_t x, int64_t y, void *data, int size_in_bytes, struct _openslide_cache_entry **_entry) { // always create cache entry for caller's reference struct _openslide_cache_entry *entry = g_slice_new(struct _openslide_cache_entry); // one ref for the caller g_atomic_int_set(&entry->refcount, 1); entry->data = data; entry->size = size_in_bytes; *_entry = entry; // lock g_mutex_lock(cache->mutex); // don't try to put anything in the cache that cannot possibly fit if (size_in_bytes > cache->capacity) { //g_debug("refused %p", entry); g_mutex_unlock(cache->mutex); _openslide_performance_warn_once(&cache->warned_overlarge_entry, "Rejecting overlarge cache entry of " "size %d bytes", size_in_bytes); return; } possibly_evict(cache, size_in_bytes); // already checks for size >= 0 // create key struct _openslide_cache_key *key = g_slice_new(struct _openslide_cache_key); key->plane = plane; key->x = x; key->y = y; // create value struct _openslide_cache_value *value = g_slice_new(struct _openslide_cache_value); value->key = key; value->cache = cache; value->entry = entry; // insert at head of queue g_queue_push_head(cache->list, value); value->link = g_queue_peek_head_link(cache->list); // insert into hash table g_hash_table_replace(cache->hashtable, key, value); // increase size cache->total_size += size_in_bytes; // another ref for the cache g_atomic_int_inc(&entry->refcount); // unlock g_mutex_unlock(cache->mutex); //g_debug("insert %p", entry); }
void handle_dbus_message(DBusMessage *msg) { int state; char **new_uris; int uri_count; GstState pipeline_state; int hemp_state; int i; int new_head = 0; /* is there a new hotlist head? If so, play means skip */ if (!strncmp (HEMP_DBUS_DESTINATION, dbus_message_get_destination(msg), strlen(HEMP_DBUS_DESTINATION))) { dbus_message_get_args (msg, NULL, DBUS_TYPE_INT32, &state, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &new_uris, &uri_count, DBUS_TYPE_INVALID); for (i = 0; i<uri_count; i++) { g_queue_push_head(hotlist, new_playlist_entry(new_uris[i])); new_head = 1; } if (uri_count) write_playlist(); if (!GST_IS_ELEMENT(pipeline)) init_pipeline(); gst_element_get_state(GST_ELEMENT (pipeline), &pipeline_state, NULL, GST_CLOCK_TIME_NONE); if (pipeline_state == GST_STATE_PAUSED) { hemp_state = HEMP_STATE_PAUSED; } else { hemp_state = HEMP_STATE_PLAYING; } switch (state) { case HEMP_STATE_TOGGLE: if (pipeline_state == GST_STATE_PLAYING) { gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED); } else { gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); } break; case HEMP_STATE_SKIP: next(hemp_state, 1); break; case HEMP_STATE_PREVIOUS: previous(hemp_state); break; case HEMP_STATE_PLAYING: if (new_head) { next(HEMP_STATE_PLAYING, 0); } else { gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); } break; case HEMP_STATE_PAUSED: gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED); break; case HEMP_STATE_STOP: drop_pipeline(0); break; case HEMP_STATE_PING: printf("ping!\n"); break; default: printf("Unknown state %d\n", state); } } }
static gboolean msn_soap_connection_run(gpointer data) { MsnSoapConnection *conn = data; MsnSoapRequest *req = g_queue_peek_head(conn->queue); conn->run_timer = 0; if (req) { if (conn->ssl == NULL) { conn->ssl = purple_ssl_connect(conn->session->account, conn->host, 443, msn_soap_connected_cb, msn_soap_error_cb, conn); } else if (conn->connected) { int len = -1; char *body = xmlnode_to_str(req->message->xml, &len); GSList *iter; g_queue_pop_head(conn->queue); conn->buf = g_string_new(""); g_string_append_printf(conn->buf, "POST /%s HTTP/1.1\r\n" "SOAPAction: %s\r\n" "Content-Type:text/xml; charset=utf-8\r\n" "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n" "Accept: */*\r\n" "Host: %s\r\n" "Content-Length: %d\r\n" "Connection: Keep-Alive\r\n" "Cache-Control: no-cache\r\n", req->path, req->message->action ? req->message->action : "", conn->host, len); for (iter = req->message->headers; iter; iter = iter->next) { g_string_append(conn->buf, (char *)iter->data); g_string_append(conn->buf, "\r\n"); } g_string_append(conn->buf, "\r\n"); g_string_append(conn->buf, body); if (req->secure && !purple_debug_is_unsafe()) purple_debug_misc("soap", "Sending secure request.\n"); else purple_debug_misc("soap", "%s\n", conn->buf->str); conn->handled_len = 0; conn->current_request = req; if (conn->event_handle) purple_input_remove(conn->event_handle); conn->event_handle = purple_input_add(conn->ssl->fd, PURPLE_INPUT_WRITE, msn_soap_write_cb, conn); if (!msn_soap_write_cb_internal(conn, conn->ssl->fd, PURPLE_INPUT_WRITE, TRUE)) { /* Not connected => reconnect and retry */ purple_debug_info("soap", "not connected, reconnecting\n"); conn->connected = FALSE; conn->current_request = NULL; msn_soap_connection_sanitize(conn, FALSE); g_queue_push_head(conn->queue, req); conn->run_timer = purple_timeout_add(0, msn_soap_connection_run, conn); } g_free(body); } } return FALSE; }
static void handle_context_element (ParserState *parser_state) { gchar *id, *parent_id, *style_ref; xmlChar *ref, *sub_pattern, *tmp; int is_empty; gboolean success; gboolean ignore_style = FALSE; GtkSourceContextRefOptions options = 0; GSList *context_classes; GError *tmp_error = NULL; g_return_if_fail (parser_state->error == NULL); ref = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "ref"); sub_pattern = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "sub-pattern"); tmp = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "ignore-style"); if (tmp != NULL && str_to_bool (tmp)) ignore_style = TRUE; xmlFree (tmp); tmp = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "style-ref"); if (tmp == NULL || id_is_decorated ((gchar*) tmp, NULL)) style_ref = g_strdup ((gchar*) tmp); else style_ref = decorate_id (parser_state, (gchar*) tmp); xmlFree (tmp); if (ignore_style && ref == NULL) { g_set_error (&parser_state->error, PARSER_ERROR, PARSER_ERROR_WRONG_STYLE, "ignore-style used not in a reference to context"); xmlFree (ref); g_free (style_ref); return; } if (ignore_style) { options |= GTK_SOURCE_CONTEXT_IGNORE_STYLE; if (style_ref != NULL) g_warning ("in file %s: style-ref and ignore-style used simultaneously", parser_state->filename); } /* XXX */ if (!ignore_style && style_ref != NULL && g_hash_table_lookup (parser_state->styles_mapping, style_ref) == NULL) { g_warning ("in file %s: style '%s' not defined", parser_state->filename, style_ref); } context_classes = parse_classes (parser_state); if (ref != NULL) { tmp = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "original"); if (tmp != NULL && str_to_bool (tmp)) options |= GTK_SOURCE_CONTEXT_REF_ORIGINAL; xmlFree (tmp); if (style_ref != NULL) options |= GTK_SOURCE_CONTEXT_OVERRIDE_STYLE; add_ref (parser_state, (gchar*) ref, options, style_ref, &tmp_error); } else { char *freeme = NULL; tmp = xmlTextReaderGetAttribute (parser_state->reader, BAD_CAST "id"); if (tmp == NULL) { freeme = generate_new_id (parser_state); tmp = xmlStrdup (BAD_CAST freeme); } if (id_is_decorated ((gchar*) tmp, NULL)) id = g_strdup ((gchar*) tmp); else id = decorate_id (parser_state, (gchar*) tmp); g_free (freeme); xmlFree (tmp); if (parser_state->ctx_data != NULL) { if (sub_pattern != NULL) { create_sub_pattern (parser_state, id, (gchar *)sub_pattern, style_ref, context_classes, &tmp_error); } else { parent_id = g_queue_peek_head ( parser_state->curr_parents); is_empty = xmlTextReaderIsEmptyElement ( parser_state->reader); if (is_empty) success = _gtk_source_context_data_define_context (parser_state->ctx_data, id, parent_id, "$^", NULL, NULL, NULL, NULL, 0, &tmp_error); else success = create_definition (parser_state, id, parent_id, style_ref, context_classes, &tmp_error); if (success && !is_empty) { /* Push the new context in the curr_parents * stack only if other contexts can be * defined inside it */ g_queue_push_head (parser_state->curr_parents, g_strdup (id)); } } } g_free (id); } g_slist_free_full (context_classes, (GDestroyNotify)gtk_source_context_class_free); g_free (style_ref); xmlFree (sub_pattern); xmlFree (ref); if (tmp_error != NULL) g_propagate_error (&parser_state->error, tmp_error); }
SevenCupConnection * sevencup_post_or_get(SevenCupAccount *sa, SteamMethod method, const gchar *host, const gchar *url, const gchar *postdata, SteamProxyCallbackFunc callback_func, gpointer user_data, gboolean keepalive) { GString *request; gchar *cookies; SevenCupConnection *scon; gchar *real_url; gboolean is_proxy = FALSE; const gchar *user_agent; const gchar* const *languages; gchar *language_names; PurpleProxyInfo *proxy_info = NULL; gchar *proxy_auth; gchar *proxy_auth_base64; if (host == NULL) host = "www.7cupsoftea.com"; if (sa && sa->account) { if (purple_account_get_bool(sa->account, "use-https", TRUE)) method |= STEAM_METHOD_SSL; } if (sa && sa->account && !(method & STEAM_METHOD_SSL)) { proxy_info = purple_proxy_get_setup(sa->account); if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_USE_GLOBAL) proxy_info = purple_global_proxy_get_info(); if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_HTTP) { is_proxy = TRUE; } } if (is_proxy == TRUE) { real_url = g_strdup_printf("http://%s%s", host, url); } else { real_url = g_strdup(url); } cookies = sevencup_cookies_to_string(sa); user_agent = purple_account_get_string(sa->account, "user-agent", "Steam 1.2.0 / iPhone"); if (method & STEAM_METHOD_POST && !postdata) postdata = ""; /* Build the request */ request = g_string_new(NULL); g_string_append_printf(request, "%s %s HTTP/1.1\r\n", (method & STEAM_METHOD_POST) ? "POST" : "GET", real_url); if (is_proxy == FALSE) g_string_append_printf(request, "Host: %s\r\n", host); g_string_append_printf(request, "Connection: %s\r\n", (keepalive ? "Keep-Alive" : "close")); g_string_append_printf(request, "User-Agent: %s\r\n", user_agent); if (method & STEAM_METHOD_POST) { g_string_append_printf(request, "Content-Type: application/x-www-form-urlencoded\r\n"); g_string_append_printf(request, "Content-length: %zu\r\n", strlen(postdata)); } g_string_append_printf(request, "Accept: */*\r\n"); g_string_append_printf(request, "Cookie: %s\r\n", cookies); g_string_append_printf(request, "Accept-Encoding: gzip\r\n"); if (is_proxy == TRUE) { if (purple_proxy_info_get_username(proxy_info) && purple_proxy_info_get_password(proxy_info)) { proxy_auth = g_strdup_printf("%s:%s", purple_proxy_info_get_username(proxy_info), purple_proxy_info_get_password(proxy_info)); proxy_auth_base64 = purple_base64_encode((guchar *)proxy_auth, strlen(proxy_auth)); g_string_append_printf(request, "Proxy-Authorization: Basic %s\r\n", proxy_auth_base64); g_free(proxy_auth_base64); g_free(proxy_auth); } } /* Tell the server what language we accept, so that we get error messages in our language (rather than our IP's) */ languages = g_get_language_names(); language_names = g_strjoinv(", ", (gchar **)languages); purple_util_chrreplace(language_names, '_', '-'); g_string_append_printf(request, "Accept-Language: %s\r\n", language_names); g_free(language_names); purple_debug_info("7cups", "getting url %s\n", url); g_string_append_printf(request, "\r\n"); if (method & STEAM_METHOD_POST) g_string_append_printf(request, "%s", postdata); /* If it needs to go over a SSL connection, we probably shouldn't print * it in the debug log. Without this condition a user's password is * printed in the debug log */ if (method == STEAM_METHOD_POST) purple_debug_info("7cups", "sending request data:\n%s\n", postdata); g_free(cookies); scon = g_new0(SevenCupConnection, 1); scon->sa = sa; scon->url = real_url; scon->method = method; scon->hostname = g_strdup(host); scon->request = request; scon->callback = callback_func; scon->user_data = user_data; scon->fd = -1; scon->connection_keepalive = keepalive; scon->request_time = time(NULL); g_queue_push_head(sa->waiting_conns, scon); sevencup_next_connection(sa); return scon; }
static void sevencup_post_or_get_readdata_cb(gpointer data, gint source, PurpleInputCondition cond) { SevenCupConnection *scon; SevenCupAccount *sa; gchar buf[4096]; gssize len; scon = data; sa = scon->sa; if (scon->method & STEAM_METHOD_SSL) { len = purple_ssl_read(scon->ssl_conn, buf, sizeof(buf) - 1); } else { len = recv(scon->fd, buf, sizeof(buf) - 1, 0); } if (len < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { /* Try again later */ return; } if (scon->method & STEAM_METHOD_SSL && scon->rx_len > 0) { /* * This is a slightly hacky workaround for a bug in either * GNU TLS or in the SSL implementation on steam's web * servers. The sequence of events is: * 1. We attempt to read the first time and successfully read * the server's response. * 2. We attempt to read a second time and libpurple's call * to gnutls_record_recv() returns the error * GNUTLS_E_UNEXPECTED_PACKET_LENGTH, or * "A TLS packet with unexpected length was received." * * Normally the server would have closed the connection * cleanly and this second read() request would have returned * 0. Or maybe it's normal for SSL connections to be severed * in this manner? In any case, this differs from the behavior * of the standard recv() system call. */ purple_debug_warning("7cups", "ssl error, but data received. attempting to continue\n"); } else { /* Try resend the request */ scon->retry_count++; if (scon->retry_count < 3) { sevencup_connection_close(scon); scon->request_time = time(NULL); g_queue_push_head(sa->waiting_conns, scon); sevencup_next_connection(sa); } else { sevencup_fatal_connection_cb(scon); } return; } } if (len > 0) { buf[len] = '\0'; scon->rx_buf = g_realloc(scon->rx_buf, scon->rx_len + len + 1); memcpy(scon->rx_buf + scon->rx_len, buf, len + 1); scon->rx_len += len; /* Wait for more data before processing */ return; } /* The server closed the connection, let's parse the data */ sevencup_connection_process_data(scon); sevencup_connection_destroy(scon); sevencup_next_connection(sa); }
/** * @brief Queue data for write in the client's output queue * * @param client The client to write the data to * @param data The GByteArray object to queue for sending * * @note after calling this function, the @p data object should no * longer be referenced by the code path. */ void rtsp_write_data_queue(RTSP_Client *client, GByteArray *data) { g_queue_push_head(client->out_queue, data); ev_io_start(client->loop, &client->ev_io_write); }
static bool input_curl_seek(struct input_stream *is, goffset offset, int whence, GError **error_r) { struct input_curl *c = (struct input_curl *)is; bool ret; assert(is->ready); if (whence == SEEK_SET && offset == is->offset) /* no-op */ return true; if (!is->seekable) return false; /* calculate the absolute offset */ switch (whence) { case SEEK_SET: break; case SEEK_CUR: offset += is->offset; break; case SEEK_END: if (is->size < 0) /* stream size is not known */ return false; offset += is->size; break; default: return false; } if (offset < 0) return false; /* check if we can fast-forward the buffer */ while (offset > is->offset && !g_queue_is_empty(c->buffers)) { struct buffer *buffer; size_t length; buffer = (struct buffer *)g_queue_pop_head(c->buffers); length = buffer->size - buffer->consumed; if (offset - is->offset < (goffset)length) length = offset - is->offset; buffer = consume_buffer(buffer, length); if (buffer != NULL) g_queue_push_head(c->buffers, buffer); is->offset += length; } if (offset == is->offset) return true; /* close the old connection and open a new one */ input_curl_easy_free(c); is->offset = offset; if (is->offset == is->size) { /* seek to EOF: simulate empty result; avoid triggering a "416 Requested Range Not Satisfiable" response */ c->eof = true; return true; } ret = input_curl_easy_init(c, error_r); if (!ret) return false; /* send the "Range" header */ if (is->offset > 0) { c->range = g_strdup_printf("%lld-", (long long)is->offset); curl_easy_setopt(c->easy, CURLOPT_RANGE, c->range); } ret = input_curl_send_request(c, error_r); if (!ret) return false; return input_curl_multi_info_read(c, error_r); }
static void gst_insert_bin_do_change (GstInsertBin * self, GstPad * pad) { struct ChangeData *data; GST_OBJECT_LOCK (self); if (!is_right_direction_for_block (pad)) { GST_WARNING_OBJECT (self, "Block pad does not have the expected direction"); goto next; } while ((data = g_queue_pop_head (&self->priv->change_queue)) != NULL) { GstPad *peer = NULL; GstPad *other_peer = NULL; GST_OBJECT_UNLOCK (self); if (data->action == GST_INSERT_BIN_ACTION_ADD && !validate_element (self, data->element)) goto error; peer = gst_pad_get_peer (pad); if (peer == NULL) { GST_WARNING_OBJECT (self, "Blocked pad has no peer"); goto error; } if (data->action == GST_INSERT_BIN_ACTION_ADD) { GstPad *srcpad = NULL, *sinkpad = NULL; GstPad *peersrcpad, *peersinkpad; /* First let's make sure we have the right pad */ if (data->sibling) { GstElement *parent = NULL; GstPad *siblingpad; if ((gst_pad_get_direction (pad) == GST_PAD_SRC && data->direction == DIRECTION_BEFORE) || (gst_pad_get_direction (pad) == GST_PAD_SINK && data->direction == DIRECTION_AFTER)) siblingpad = peer; else siblingpad = pad; parent = gst_pad_get_parent_element (siblingpad); if (parent != NULL) gst_object_unref (parent); if (parent != data->sibling) goto retry; } else { GstObject *parent; GstPad *ghost; GstPad *proxypad; if (data->direction == DIRECTION_BEFORE) { ghost = self->priv->srcpad; if (gst_pad_get_direction (pad) == GST_PAD_SINK) proxypad = pad; else proxypad = peer; } else { ghost = self->priv->sinkpad; if (gst_pad_get_direction (pad) == GST_PAD_SINK) proxypad = peer; else proxypad = pad; } if (!GST_IS_PROXY_PAD (proxypad)) goto retry; parent = gst_pad_get_parent (proxypad); if (!parent) goto retry; gst_object_unref (parent); if (GST_PAD_CAST (parent) != ghost) goto retry; } if (gst_pad_get_direction (pad) == GST_PAD_SRC) { peersrcpad = pad; peersinkpad = peer; } else { peersrcpad = peer; peersinkpad = pad; } if (GST_IS_PROXY_PAD (peersrcpad)) { GstObject *parent = gst_pad_get_parent (peersrcpad); if (GST_PAD_CAST (parent) == self->priv->sinkpad) peersrcpad = NULL; if (parent) gst_object_unref (parent); } if (GST_IS_PROXY_PAD (peersinkpad)) { GstObject *parent = gst_pad_get_parent (peersinkpad); if (GST_PAD_CAST (parent) == self->priv->srcpad) peersinkpad = NULL; if (parent) gst_object_unref (parent); } if (peersinkpad && peersrcpad) { gst_pad_unlink (peersrcpad, peersinkpad); } else { if (!peersinkpad) gst_ghost_pad_set_target (GST_GHOST_PAD (self->priv->srcpad), NULL); if (!peersrcpad) gst_ghost_pad_set_target (GST_GHOST_PAD (self->priv->sinkpad), NULL); } srcpad = get_single_pad (data->element, GST_PAD_SRC); sinkpad = get_single_pad (data->element, GST_PAD_SINK); if (srcpad == NULL || sinkpad == NULL) { GST_WARNING_OBJECT (self, "Can not get element src or sink pad"); goto error; } if (!gst_bin_add (GST_BIN (self), data->element)) { GST_WARNING_OBJECT (self, "Can not add element to bin"); goto error; } if (peersrcpad) { if (GST_PAD_LINK_FAILED (gst_pad_link (peersrcpad, sinkpad))) { GST_WARNING_OBJECT (self, "Can not link sibling's %s:%s pad" " to element's %s:%s pad", GST_DEBUG_PAD_NAME (peersrcpad), GST_DEBUG_PAD_NAME (sinkpad)); goto error; } } else { if (!gst_ghost_pad_set_target (GST_GHOST_PAD (self->priv->sinkpad), sinkpad)) { GST_WARNING_OBJECT (self, "Can not set %s:%s as target for %s:%s", GST_DEBUG_PAD_NAME (sinkpad), GST_DEBUG_PAD_NAME (self->priv->sinkpad)); goto error; } } if (peersinkpad) { if (GST_PAD_LINK_FAILED (gst_pad_link (srcpad, peersinkpad))) { GST_WARNING_OBJECT (self, "Can not link element's %s:%s pad" " to sibling's %s:%s pad", GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (peersinkpad)); goto error; } } else { if (!gst_ghost_pad_set_target (GST_GHOST_PAD (self->priv->srcpad), srcpad)) { GST_WARNING_OBJECT (self, "Can not set %s:%s as target for %s:%s", GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (self->priv->srcpad)); goto error; } } gst_object_unref (srcpad); gst_object_unref (sinkpad); if (!gst_element_sync_state_with_parent (data->element)) { GST_WARNING_OBJECT (self, "Can not sync element's state with parent"); goto error; } } else { GstElement *parent = NULL; GstPad *other_pad; GstCaps *caps = NULL, *peercaps = NULL; gboolean can_intersect; gboolean success; parent = gst_pad_get_parent_element (peer); if (parent != NULL) gst_object_unref (parent); if (parent != data->element) goto retry; if (gst_pad_get_direction (peer) == GST_PAD_SRC) other_pad = get_single_pad (data->element, GST_PAD_SINK); else other_pad = get_single_pad (data->element, GST_PAD_SRC); if (!other_pad) { GST_WARNING_OBJECT (self, "Can not get element's other pad"); goto error; } other_peer = gst_pad_get_peer (other_pad); gst_object_unref (other_pad); if (!other_peer) { GST_WARNING_OBJECT (self, "Can not get element's other peer"); goto error; } /* Get the negotiated caps for the source pad peer, * because renegotiation while the pipeline is playing doesn't work * that fast. */ if (gst_pad_get_direction (pad) == GST_PAD_SRC) caps = gst_pad_get_current_caps (pad); else peercaps = gst_pad_get_current_caps (other_peer); if (!caps) caps = gst_pad_query_caps (pad, NULL); if (!peercaps) peercaps = gst_pad_query_caps (other_peer, NULL); can_intersect = gst_caps_can_intersect (caps, peercaps); gst_caps_unref (caps); gst_caps_unref (peercaps); if (!can_intersect) { GST_WARNING_OBJECT (self, "Pads are incompatible without the element"); goto error; } if (gst_pad_get_direction (other_peer) == GST_PAD_SRC && gst_pad_is_active (other_peer)) { gulong probe_id; probe_id = gst_pad_add_probe (other_peer, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, wait_and_drop_eos_cb, NULL, NULL); gst_pad_send_event (peer, gst_event_new_eos ()); gst_pad_remove_probe (other_peer, probe_id); } gst_element_set_locked_state (data->element, TRUE); gst_element_set_state (data->element, GST_STATE_NULL); if (!gst_bin_remove (GST_BIN (self), data->element)) { GST_WARNING_OBJECT (self, "Element removal rejected"); goto error; } gst_element_set_locked_state (data->element, FALSE); if (gst_pad_get_direction (pad) == GST_PAD_SRC) success = GST_PAD_LINK_SUCCESSFUL (gst_pad_link_full (pad, other_peer, GST_PAD_LINK_CHECK_HIERARCHY | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)); else success = GST_PAD_LINK_SUCCESSFUL (gst_pad_link_full (other_peer, pad, GST_PAD_LINK_CHECK_HIERARCHY | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)); gst_object_unref (other_peer); other_peer = NULL; if (!success) { GST_ERROR_OBJECT (self, "Could not re-link after the element's" " removal"); goto error; } } gst_insert_bin_change_data_complete (self, data, TRUE); gst_object_unref (peer); GST_OBJECT_LOCK (self); continue; done: if (other_peer != NULL) gst_object_unref (other_peer); if (peer != NULL) gst_object_unref (peer); break; retry: GST_OBJECT_LOCK (self); g_queue_push_head (&self->priv->change_queue, data); goto done; error: /* Handle error */ gst_insert_bin_change_data_complete (self, data, FALSE); GST_OBJECT_LOCK (self); goto done; } next: gst_insert_bin_block_pad_unlock (self); }
static void search_cb (GVimeo *vimeo, GList *video_list, gpointer user_data) { GrlMedia *media = NULL; AddMediaUrlData *amud; SearchData *sd = (SearchData *) user_data; gint count = grl_operation_options_get_count (sd->ss->options); gint id; gchar *media_type; gint video_list_size; /* Go to offset element */ video_list = g_list_nth (video_list, sd->offset); /* No more elements can be sent */ if (!video_list) { sd->ss->callback (sd->ss->source, sd->ss->operation_id, NULL, 0, sd->ss->user_data, NULL); g_slice_free (SearchData, sd); return; } video_list_size = g_list_length (video_list); if (count > video_list_size) { count = video_list_size; } if (sd->get_url) { sd->queue = g_queue_new (); } while (video_list && count) { media_type = g_hash_table_lookup (video_list->data, "title"); if (media_type) { media = grl_media_video_new (); } else { media = NULL; } if (media) { update_media (media, video_list->data); if (sd->get_url) { amud = g_slice_new (AddMediaUrlData); amud->computed = FALSE; amud->media = media; amud->index = --count; amud->sd = sd; g_queue_push_head (sd->queue, amud); id = (gint) g_ascii_strtod (grl_media_get_id (media), NULL); g_vimeo_video_get_play_url (sd->vimeo, id, add_url_media_cb, amud); } else { sd->ss->callback (sd->ss->source, sd->ss->operation_id, media, --count, sd->ss->user_data, NULL); } } video_list = g_list_next (video_list); } if (!sd->get_url) { g_slice_free (SearchData, sd); } }
static void start_element( GMarkupParseContext *ctx, const gchar *tag, const gchar **attr_names, const gchar **attr_values, gpointer ud, GError **error) { parse_data_t *pd = (parse_data_t*)ud; union { gint id; gpointer pid; } id; gint ii; // Check to see if the first element found has been closed // If so, ignore any junk following it. if (pd->closed_top) return; for (ii = 0; ii < TAG_MAP_SZ; ii++) { if (strcmp(tag, tag_map[ii].tag) == 0) { id.id = tag_map[ii].id; break; } } if (ii == TAG_MAP_SZ) { g_warning("Unrecognized start tag (%s)", tag); return; } g_queue_push_head(pd->tag_stack, id.pid); GType gtype = 0; GValue *gval = NULL; GValue *current = g_queue_peek_head(pd->stack); switch (id.id) { case R_SECTION: { const gchar *name; name = lookup_attr_value("name", attr_names, attr_values); if (name && strcmp(name, "icons") == 0) { gval = ghb_dict_value_new(); if (pd->key) g_free(pd->key); pd->key = g_strdup(name); g_queue_push_head(pd->stack, gval); } } break; case R_ICON: { gchar *filename; const gchar *name; name = lookup_attr_value("file", attr_names, attr_values); filename = find_file(inc_list, name); name = lookup_attr_value("name", attr_names, attr_values); if (filename && name) { ghb_rawdata_t *rd; GdkPixbuf *pb; GError *err = NULL; pb = gdk_pixbuf_new_from_file(filename, &err); if (pb == NULL) { g_warning("Failed to open icon file %s: %s", filename, err->message); break; } gval = ghb_dict_value_new(); int colorspace = gdk_pixbuf_get_colorspace(pb); gboolean alpha = gdk_pixbuf_get_has_alpha(pb); int width = gdk_pixbuf_get_width(pb); int height = gdk_pixbuf_get_height(pb); int bps = gdk_pixbuf_get_bits_per_sample(pb); int rowstride = gdk_pixbuf_get_rowstride(pb); ghb_dict_insert(gval, g_strdup("colorspace"), ghb_int_value_new(colorspace)); ghb_dict_insert(gval, g_strdup("alpha"), ghb_boolean_value_new(alpha)); ghb_dict_insert(gval, g_strdup("width"), ghb_int_value_new(width)); ghb_dict_insert(gval, g_strdup("height"), ghb_int_value_new(height)); ghb_dict_insert(gval, g_strdup("bps"), ghb_int_value_new(bps)); ghb_dict_insert(gval, g_strdup("rowstride"), ghb_int_value_new(rowstride)); rd = g_malloc(sizeof(ghb_rawdata_t)); rd->data = gdk_pixbuf_get_pixels(pb); rd->size = height * rowstride * bps / 8; GValue *data = ghb_rawdata_value_new(rd); ghb_dict_insert(gval, g_strdup("data"), data); if (pd->key) g_free(pd->key); pd->key = g_strdup(name); g_free(filename); } else { g_warning("%s:missing a requried attribute", name); exit(EXIT_FAILURE); } } break; case R_PLIST: { gchar *filename; const gchar *name; name = lookup_attr_value("file", attr_names, attr_values); filename = find_file(inc_list, name); name = lookup_attr_value("name", attr_names, attr_values); if (filename && name) { gval = ghb_plist_parse_file(filename); if (pd->key) g_free(pd->key); pd->key = g_strdup(name); g_free(filename); } else { g_warning("%s:missing a requried attribute", name); exit(EXIT_FAILURE); } } break; case R_STRING: { gchar *filename; const gchar *name; name = lookup_attr_value("file", attr_names, attr_values); filename = find_file(inc_list, name); name = lookup_attr_value("name", attr_names, attr_values); if (filename && name) { gval = read_string_from_file(filename); if (pd->key) g_free(pd->key); pd->key = g_strdup(name); g_free(filename); } else { g_warning("%s:missing a requried attribute", name); exit(EXIT_FAILURE); } } break; } // Add the element to the current container if (gval) { // There's an element to add if (current == NULL) { pd->plist = gval; return; } gtype = G_VALUE_TYPE(current); if (gtype == ghb_array_get_type()) { ghb_array_append(current, gval); } else if (gtype == ghb_dict_get_type()) { if (pd->key == NULL) { g_warning("No key for dictionary item"); ghb_value_free(gval); } else { ghb_dict_insert(current, g_strdup(pd->key), gval); } } else { g_error("Invalid container type. This shouldn't happen"); } } }
void server(session_t* session) { gchar **lines, **tokens, **chunks; char verb[VERB_SIZE], resource[RESOURCE_SIZE], protocol[PROTOCOL_SIZE]; char buffer[BUFFER_SIZE]; int selectStatus, currentReadFd, readBytes; session->q = g_queue_new(); struct timeval timer; timer.tv_sec = 30; timer.tv_usec = 0; // Setup read file descriptor set and timer for select() fd_set reader; FD_ZERO(&reader); session->read_fds = newFdSet(); // Keep track of largest file descriptor session->listener = createSocket(session->server); session->maxFd = session->listener; session->connections = g_hash_table_new (g_direct_hash, g_direct_equal); FD_SET(session->listener, &session->read_fds); // Main Loop for (;;) { reader = session->read_fds; selectStatus = select(session->maxFd + 1, &reader, NULL, NULL, &timer); if (selectStatus == -1) { fprintf(stderr, "Select failed\n"); exit(1); } // Handle timeouts else if (selectStatus == 0) { if (g_queue_get_length(session->q) > 0) { session->maxFd = closeSocket(GPOINTER_TO_INT(g_queue_pop_tail(session->q)), session); continue; } } // There's something to read for(currentReadFd = 0; currentReadFd <= session->maxFd; currentReadFd++) { if (!FD_ISSET(currentReadFd, &reader)) { continue; } if (currentReadFd == session->listener) { newConnection(session); } else { memset(buffer, '\0', BUFFER_SIZE); memset(verb, '\0', VERB_SIZE); memset(resource, '\0', RESOURCE_SIZE); memset(protocol, '\0', PROTOCOL_SIZE); readBytes = recv(currentReadFd, buffer, BUFFER_SIZE - 1, 0);; if (readBytes <= 0) { closeSocket(currentReadFd, session); continue; } chunks = g_strsplit(buffer, "\r\n\r\n", 2); lines = g_strsplit(chunks[0], "\r\n", 20); tokens = g_strsplit(lines[0], " ", 3); strncpy(verb, tokens[0], strlen(tokens[0])); strncpy(resource, tokens[1], strlen(tokens[1])); strncpy(protocol, tokens[2], strlen(tokens[2])); setSessionHeaders(session, lines); setSessionVerb(session, verb); if (session->verb == VERB_HEAD || session->verb == VERB_GET) { logToFile(session, currentReadFd, resource, verb, 200); handleRequest(session, currentReadFd, resource, NULL); } else if (session->verb == VERB_POST) { logToFile(session, currentReadFd, resource, verb, 200); handleRequest(session, currentReadFd, resource, chunks[1]); } else { logToFile(session, currentReadFd, resource, verb, 200); } gchar* connection = (gchar *) g_hash_table_lookup(session->headers, "Connection"); g_queue_remove(session->q, GINT_TO_POINTER(currentReadFd)); g_queue_push_head(session->q, GINT_TO_POINTER(currentReadFd)); if ((g_strcmp0(protocol, "HTTP/1.0") == 0 && g_strcmp0(connection, "keep-alive") != 0) || (g_strcmp0(connection, "close") == 0)) { closeSocket(currentReadFd, session); } } } } g_hash_table_destroy(session->connections); FD_ZERO(&session->read_fds); close(session->listener); }
static gboolean brasero_dvdcss_create_scrambled_sectors_map (BraseroDvdcss *self, BraseroDrive *drive, GQueue *map, dvdcss_handle *handle, BraseroVolFile *parent, GError **error) { GList *iter; /* this allows to cache keys for encrypted files */ for (iter = parent->specific.dir.children; iter; iter = iter->next) { BraseroVolFile *file; file = iter->data; if (!file->isdir) { if (!strncmp (file->name + strlen (file->name) - 6, ".VOB", 4)) { BraseroScrambledSectorRange *range; gsize current_extent; GSList *extents; BRASERO_JOB_LOG (self, "Retrieving keys for %s", file->name); /* take the first address for each extent of the file */ if (!file->specific.file.extents) { BRASERO_JOB_LOG (self, "Problem: file has no extents"); return FALSE; } range = g_new0 (BraseroScrambledSectorRange, 1); for (extents = file->specific.file.extents; extents; extents = extents->next) { BraseroVolFileExtent *extent; extent = extents->data; range->start = extent->block; range->end = extent->block + BRASERO_BYTES_TO_SECTORS (extent->size, DVDCSS_BLOCK_SIZE); BRASERO_JOB_LOG (self, "From 0x%llx to 0x%llx", range->start, range->end); g_queue_push_head (map, range); if (extent->size == 0) { BRASERO_JOB_LOG (self, "0 size extent"); continue; } current_extent = dvdcss_seek (handle, range->start, DVDCSS_SEEK_KEY); if (current_extent != range->start) { BRASERO_JOB_LOG (self, "Problem: could not retrieve key"); g_set_error (error, BRASERO_BURN_ERROR, BRASERO_BURN_ERROR_GENERAL, /* Translators: %s is the path to a drive. "regionset %s" * should be left as is just like "DVDCSS_METHOD=title * brasero --no-existing-session" */ _("Error while retrieving a key used for encryption. You may solve such a problem with one of the following methods: in a terminal either set the proper DVD region code for your CD/DVD player with the \"regionset %s\" command or run the \"DVDCSS_METHOD=title brasero --no-existing-session\" command"), brasero_drive_get_device (drive)); return FALSE; } } } } else if (!brasero_dvdcss_create_scrambled_sectors_map (self, drive, map, handle, file, error)) return FALSE; } return TRUE; }
/* as-set/route-set expansion !ias-bar */ void irr_set_expand (irr_connection_t *irr, char *name) { irr_database_t *database; time_t start_time; GArray *array; GQueue *stack; GHashTable *hash_member_examined; member_examined_hash_t *member_examined_ptr; LINKED_LIST *ll_setlist; char *set_name, *last_set_name, *mstr, *db; char *range_op, abuf[BUFSIZE]; char *lasts = NULL; int i, first, dup, expand_flag = NO_EXPAND; hash_spec_t *hash_spec; if (strchr(name, ',') != NULL) { strtok_r(name, ",", &lasts); /* check if we are expanding a route-set */ if ( (set_name = strchr(name, ':')) != NULL) set_name++; else set_name = name; if (!strncasecmp (set_name, "rs-", 3)) expand_flag = ROUTE_SET_EXPAND; else expand_flag = OTHER_EXPAND; } start_time = time(NULL); convert_toupper (name); stack = g_queue_new(); hash_member_examined = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)HashMemberExaminedDestroy); ll_setlist = LL_Create (LL_DestroyFunction, free, NULL); mstr = rpsl_macro_expand_add (" ", name, irr, NULL); g_queue_push_head(stack, mstr); member_examined_ptr = irrd_malloc(sizeof(member_examined_hash_t)); member_examined_ptr->key = strdup(name); g_hash_table_insert(hash_member_examined, member_examined_ptr->key, member_examined_ptr); while (!g_queue_is_empty(stack)) { if ( IRR.expansion_timeout > 0 ) { if ( (time(NULL) - start_time) > IRR.expansion_timeout ) { trace (ERROR, default_trace, "irr_set_expand(): Set expansion timeout\n"); sprintf(abuf, "Expansion maximum CPU time exceeded: %d seconds", IRR.expansion_timeout); irr_send_error(irr, abuf); goto getout; } } mstr = (char *) g_queue_pop_head(stack); /* might want to check the examined list to see if this set name has been examined already */ first = 1; lasts = NULL; range_op = strtok_r (mstr, ",", &lasts); if (!strcmp (range_op, " ")) range_op = NULL; set_name = strtok_r (NULL, ",", &lasts); irr_lock_all(irr); /* lock db's while searching */ while ((db = strtok_r (NULL, ",", &lasts)) != NULL) { if ((database = find_database (db)) == NULL) { trace (ERROR, default_trace, "irr_set_expand(): Database not found %s\n", db); sprintf(abuf, "Database not found: %s", db); irr_send_error(irr, abuf); goto getout; } make_setobj_key (abuf, set_name); if ((hash_spec = fetch_hash_spec (database, abuf, UNPACK)) != NULL) { first = 0; update_members_list (database, range_op, AF_INET, expand_flag, hash_member_examined, ll_setlist, hash_spec->ll_1, stack, irr); mbrs_by_ref_set (database, range_op, AF_INET, expand_flag, ll_setlist, set_name, hash_spec->ll_2, irr); Delete_hash_spec (hash_spec); } if (first == 0) break; } irr_unlock_all(irr); free (mstr); } first = 1; dup = 0; i = 0; last_set_name = ""; array = g_array_sized_new(FALSE, TRUE, sizeof(char*), ll_setlist->count); LL_ContIterate (ll_setlist, set_name) { g_array_append_val(array, set_name); }
static void views_parser_start_element (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error) { ViewsParserData *parser_data = user_data; GtkWidget *item; g_assert (context != NULL); g_assert (element_name != NULL); g_assert (parser_data != NULL); if (g_strcmp0 (element_name, "views") == 0) { } else if (g_strcmp0 (element_name, "view") == 0) { const gchar *name = NULL; if (!check_parent (context, "views", error)) return; if (!g_markup_collect_attributes (element_name, attribute_names, attribute_values, error, G_MARKUP_COLLECT_STRING, "name", &name, G_MARKUP_COLLECT_INVALID)) return; item = g_object_new (GB_TYPE_SHORTCUTS_VIEW, "view-name", name, "visible", TRUE, NULL); g_queue_push_head (parser_data->stack, g_object_ref_sink (item)); } else if (g_strcmp0 (element_name, "page") == 0) { if (!check_parent (context, "view", error)) return; item = g_object_new (GB_TYPE_SHORTCUTS_PAGE, "visible", TRUE, NULL); g_queue_push_head (parser_data->stack, g_object_ref_sink (item)); } else if (g_strcmp0 (element_name, "column") == 0) { GtkSizeGroup *size_group; if (!check_parent (context, "page", error)) return; size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); g_queue_push_head (parser_data->column_image_size_groups, size_group); size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); g_queue_push_head (parser_data->column_desc_size_groups, size_group); item = g_object_new (GB_TYPE_SHORTCUTS_COLUMN, "visible", TRUE, NULL); g_queue_push_head (parser_data->stack, g_object_ref_sink (item)); } else if (g_strcmp0 (element_name, "group") == 0) { if (!check_parent (context, "column", error)) return; item = g_object_new (GB_TYPE_SHORTCUTS_GROUP, "visible", TRUE, NULL); g_queue_push_head (parser_data->stack, g_object_ref_sink (item)); } else if (g_strcmp0 (element_name, "shortcut") == 0) { GtkSizeGroup *accel_size_group; GtkSizeGroup *desc_size_group; if (!check_parent (context, "group", error)) return; accel_size_group = g_queue_peek_head (parser_data->column_image_size_groups); desc_size_group = g_queue_peek_head (parser_data->column_desc_size_groups); parser_data->search_item = g_object_new (GB_TYPE_SHORTCUTS_SHORTCUT, "visible", TRUE, NULL); item = g_object_new (GB_TYPE_SHORTCUTS_SHORTCUT, "accelerator-size-group", accel_size_group, "title-size-group", desc_size_group, "visible", TRUE, NULL); g_queue_push_head (parser_data->stack, g_object_ref_sink (item)); } else if (g_strcmp0 (element_name, "gesture") == 0) { GtkSizeGroup *accel_size_group; GtkSizeGroup *desc_size_group; if (!check_parent (context, "group", error)) return; accel_size_group = g_queue_peek_head (parser_data->column_image_size_groups); desc_size_group = g_queue_peek_head (parser_data->column_desc_size_groups); parser_data->search_item = g_object_new (GB_TYPE_SHORTCUTS_GESTURE, "visible", TRUE, NULL); item = g_object_new (GB_TYPE_SHORTCUTS_GESTURE, "desc-size-group", desc_size_group, "icon-size-group", accel_size_group, "visible", TRUE, NULL); g_queue_push_head (parser_data->stack, g_object_ref_sink (item)); } else if (g_strcmp0 (element_name, "property") == 0) { const gchar *name = NULL; const gchar *translatable = NULL; item = g_queue_peek_head (parser_data->stack); if (item == NULL) { g_set_error (error, GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_TAG, "Property called without a parent object"); return; } if (!g_markup_collect_attributes (element_name, attribute_names, attribute_values, error, G_MARKUP_COLLECT_STRING, "name", &name, G_MARKUP_COLLECT_OPTIONAL | G_MARKUP_COLLECT_STRING, "translatable", &translatable, G_MARKUP_COLLECT_INVALID)) return; g_free (parser_data->property_name); parser_data->property_name = g_strdup (name); parser_data->translatable = (g_strcmp0 (translatable, "yes") == 0); } else { const GSList *stack; const gchar *parent_name; const gchar *our_name; gint line; gint col; stack = g_markup_parse_context_get_element_stack (context); our_name = stack->data; parent_name = stack->next ? stack->next->data : ""; g_markup_parse_context_get_position (context, &line, &col); g_set_error (error, GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_TAG, "%d:%d: Unknown element <%s> found in <%s>.", line, col, our_name, parent_name); } }
static void _source_notification_added_cb (MexNotificationSource *source, MexNotification *notification, MexNotificationArea *area) { MexNotificationAreaPrivate *priv = GET_PRIVATE (area); ClutterActor *actor; ClutterActor *last_top_actor; ClutterAnimation *animation; actor = _make_notification_actor (notification); g_hash_table_insert (priv->notification_to_actor, notification, actor); clutter_container_add_actor (CLUTTER_CONTAINER (area), actor); mx_stack_child_set_x_fill (MX_STACK (area), actor, FALSE); mx_stack_child_set_y_fill (MX_STACK (area), actor, FALSE); mx_stack_child_set_x_align (MX_STACK (area), actor, MX_ALIGN_MIDDLE); mx_stack_child_set_y_align (MX_STACK (area), actor, MX_ALIGN_MIDDLE); /* Get the last notification since we want to fade that out */ last_top_actor = g_queue_peek_head (priv->stack); g_queue_push_head (priv->stack, actor); clutter_container_raise_child (CLUTTER_CONTAINER (area), actor, last_top_actor); /* Fade out old notification */ if (last_top_actor) { clutter_actor_animate (last_top_actor, CLUTTER_EASE_OUT_QUAD, 350, "opacity", 0x00, NULL); } clutter_actor_set_opacity (actor, 0); animation = clutter_actor_animate (actor, CLUTTER_EASE_OUT_QUAD, 350, "opacity", 0xff, NULL); /* Delay new notification fade in if we had an old one */ if (last_top_actor) { ClutterTimeline *timeline; timeline = clutter_animation_get_timeline (animation); clutter_timeline_set_delay (timeline, 450); } g_object_set_data (G_OBJECT (actor), "notification-area", area); g_object_set_data (G_OBJECT (actor), "notification", notification); if (notification->duration > 0) { guint timeout_id = g_timeout_add_seconds (notification->duration, (GSourceFunc)_notification_timeout_cb, actor); g_hash_table_insert (priv->notification_to_timeout_id, notification, GINT_TO_POINTER (timeout_id)); } }
int ddb_gvfs_scandir (const char *dir, struct dirent ***namelist, int (*selector) (const struct dirent *), int (*cmp) (const struct dirent **, const struct dirent **)) { GQueue *file_list = g_queue_new (); GQueue *dir_list = g_queue_new (); g_queue_push_head (dir_list, g_file_new_for_uri (dir)); GFile *gdir; while ((gdir = g_queue_pop_head (dir_list)) != NULL) { GFileEnumerator *file_enumerator = g_file_enumerate_children (gdir, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL); if (file_enumerator == NULL) { g_object_unref (gdir); continue; } GFileInfo *file_info; GFile *child_file; while ((file_info = g_file_enumerator_next_file (file_enumerator, NULL, NULL)) != NULL) { child_file = g_file_get_child (gdir, g_file_info_get_name (file_info)); g_object_unref (file_info); if (g_file_query_file_type (child_file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY) g_queue_push_head (dir_list, child_file); else { g_queue_push_tail (file_list, g_file_get_uri (child_file)); g_object_unref (child_file); } } g_file_enumerator_close (file_enumerator, NULL, NULL); g_object_unref (file_enumerator); g_object_unref (gdir); } g_queue_free (dir_list); int num_files = 0; *namelist = malloc (sizeof(void *) * g_queue_get_length (file_list)); char *fname; while ((fname = g_queue_pop_head (file_list)) != NULL) { struct dirent entry; strncpy (entry.d_name, fname, sizeof(entry.d_name) - 1); entry.d_name[sizeof(entry.d_name) - 1] = '\0'; if (selector == NULL || (selector && selector(&entry))) { (*namelist)[num_files] = calloc (1, sizeof (struct dirent)); strcpy ((*namelist)[num_files]->d_name, entry.d_name); num_files++; } g_free (fname); } g_queue_free (file_list); return num_files; }
static void parasite_python_shell_process_line(GtkWidget *python_shell) { ParasitePythonShellPrivate *priv = PARASITE_PYTHON_SHELL_GET_PRIVATE(python_shell); char *command = parasite_python_shell_get_input(python_shell); char last_char; parasite_python_shell_append_text(PARASITE_PYTHON_SHELL(python_shell), "\n", NULL); if (*command != '\0') { /* Save this command in the history. */ g_queue_push_head(priv->history, command); priv->cur_history_item = NULL; if (g_queue_get_length(priv->history) > MAX_HISTORY_LENGTH) g_free(g_queue_pop_tail(priv->history)); } last_char = command[MAX(0, strlen(command) - 1)]; if (last_char == ':' || last_char == '\\' || (priv->in_block && g_ascii_isspace(command[0]))) { printf("in block.. %c, %d, %d\n", last_char, priv->in_block, g_ascii_isspace(command[0])); /* This is a multi-line expression */ if (priv->pending_command == NULL) priv->pending_command = g_string_new(command); else g_string_append(priv->pending_command, command); g_string_append_c(priv->pending_command, '\n'); if (last_char == ':') priv->in_block = TRUE; } else { if (priv->pending_command != NULL) { g_string_append(priv->pending_command, command); g_string_append_c(priv->pending_command, '\n'); /* We're not actually leaking this. It's in the history. */ command = g_string_free(priv->pending_command, FALSE); } parasite_python_run(command, parasite_python_shell_log_stdout, parasite_python_shell_log_stderr, python_shell); if (priv->pending_command != NULL) { /* Now do the cleanup. */ g_free(command); priv->pending_command = NULL; priv->in_block = FALSE; } } parasite_python_shell_write_prompt(python_shell); }