static void parse_trestle_image_description(openslide_t *osr, const char *description, int32_t *overlap_count_OUT, int32_t **overlaps_OUT) { char **first_pass = g_strsplit(description, ";", -1); int32_t overlap_count = 0; int32_t *overlaps = NULL; if (osr) { add_properties(osr->properties, first_pass); } for (char **cur_str = first_pass; *cur_str != NULL; cur_str++) { //g_debug(" XX: %s", *cur_str); if (g_str_has_prefix(*cur_str, OVERLAPS_XY)) { // found it char **second_pass = g_strsplit(*cur_str, " ", -1); overlap_count = g_strv_length(second_pass) - 1; // skip fieldname overlaps = g_new(int32_t, overlap_count); int i = 0; // skip fieldname for (char **cur_str2 = second_pass + 1; *cur_str2 != NULL; cur_str2++) { overlaps[i] = g_ascii_strtoull(*cur_str2, NULL, 10); i++; } g_strfreev(second_pass); } else if (g_str_has_prefix(*cur_str, BACKGROUND_COLOR)) { // found background color errno = 0; uint64_t bg = g_ascii_strtoull((*cur_str) + strlen(BACKGROUND_COLOR), NULL, 16); if (bg || !errno) { if (osr) { _openslide_set_background_color_property(osr->properties, (bg >> 16) & 0xFF, (bg >> 8) & 0xFF, bg & 0xFF); } } } }
static guint64 uint64_parse (const gchar* str) { guint64 result = 0ULL; const gchar* _tmp0_ = NULL; guint64 _tmp1_ = 0ULL; g_return_val_if_fail (str != NULL, 0ULL); _tmp0_ = str; _tmp1_ = g_ascii_strtoull (_tmp0_, NULL, (guint) 0); result = _tmp1_; return result; }
guint64 node_to_num (xmlNode *node) { guint64 ret; xmlChar *tmp; tmp = xmlNodeGetContent (node); ret = g_ascii_strtoull ((char*) tmp, NULL, 10); xmlFree (tmp); return ret; }
/** * zif_lock_get_pid: **/ static guint zif_lock_get_pid (ZifLock *lock, const gchar *filename, GError **error) { gboolean ret; GError *error_local = NULL; guint64 pid = 0; gchar *contents = NULL; gchar *endptr = NULL; g_return_val_if_fail (ZIF_IS_LOCK (lock), FALSE); /* file doesn't exists */ ret = g_file_test (filename, G_FILE_TEST_EXISTS); if (!ret) { g_set_error_literal (error, ZIF_LOCK_ERROR, ZIF_LOCK_ERROR_FAILED, "lock file not present"); goto out; } /* get contents */ ret = g_file_get_contents (filename, &contents, NULL, &error_local); if (!ret) { g_set_error (error, ZIF_LOCK_ERROR, ZIF_LOCK_ERROR_FAILED, "lock file not set: %s", error_local->message); g_error_free (error_local); goto out; } /* convert to int */ pid = g_ascii_strtoull (contents, &endptr, 10); /* failed to parse */ if (contents == endptr) { g_set_error (error, ZIF_LOCK_ERROR, ZIF_LOCK_ERROR_FAILED, "failed to parse pid: %s", contents); pid = 0; goto out; } /* too large */ if (pid > G_MAXUINT) { g_set_error (error, ZIF_LOCK_ERROR, ZIF_LOCK_ERROR_FAILED, "pid too large %" G_GUINT64_FORMAT, pid); pid = 0; goto out; } out: g_free (contents); return (guint) pid; }
/* Handle a FILE_WRITE command. */ static void process_file_write(taper_state_t * state, struct cmdargs * cmdargs) { dump_info_t dump_state; char * holding_disk_file; guint64 splitsize; char * argnames[] = {"command", /* 0 */ "handle", /* 1 */ "filename", /* 2 */ "hostname", /* 3 */ "diskname", /* 4 */ "level", /* 5 */ "datestamp", /* 6 */ "splitsize", /* 7 */ NULL }; validate_args(cmdargs, argnames); dump_state.handle = g_strdup(cmdargs->argv[1]); holding_disk_file = g_strdup(cmdargs->argv[2]); dump_state.hostname = g_strdup(cmdargs->argv[3]); dump_state.diskname = g_strdup(cmdargs->argv[4]); errno = 0; dump_state.level = strtol(cmdargs->argv[5], NULL, 10); if (errno != 0) { error("error [taper FILE-WRITE: Invalid dump level %s]", cmdargs->argv[5]); g_assert_not_reached(); } dump_state.timestamp = strdup(cmdargs->argv[6]); errno = 0; splitsize = g_ascii_strtoull(cmdargs->argv[7], NULL, 10); if (errno != 0) { error("error [taper FILE-WRITE: Invalid splitsize %s]", cmdargs->argv[7]); g_assert_not_reached(); } dump_state.id_string = g_strdup_printf("%s:%s.%d", dump_state.hostname, dump_state.diskname, dump_state.level); dump_state.source = taper_source_new(dump_state.handle, FILE_WRITE, holding_disk_file, -1, NULL, splitsize, -1); /* FIXME: This should be handled properly. */ g_assert(dump_state.source != NULL); run_device_output(state, &dump_state); free_dump_info(&dump_state); amfree(holding_disk_file); }
/* report total system memory in kB (given to us by /proc/meminfo) */ guint64 totalMemory(void) { int i = 0, len = 0; guint64 total = 0; unsigned long long int dtotal = 0; gchar *contents = NULL; gchar **lines = NULL, **fields = NULL; GError *fileErr = NULL; if (!g_file_get_contents(MEMINFO, &contents, NULL, &fileErr)) { logMessage(ERROR, "error reading %s: %s", MEMINFO, fileErr->message); g_error_free(fileErr); return total; } lines = g_strsplit(contents, "\n", 0); g_free(contents); for (i = 0; i < g_strv_length(lines); i++) { if (g_str_has_prefix(lines[i], "MemTotal:")) { fields = g_strsplit(lines[i], " ", 0); len = g_strv_length(fields); if (len < 3) { logMessage(ERROR, "unknown format for MemTotal line in %s", MEMINFO); g_strfreev(fields); g_strfreev(lines); return total; } errno = 0; total = g_ascii_strtoull(fields[len - 2], NULL, 10); if ((errno == ERANGE && total == G_MAXUINT64) || (errno == EINVAL && total == 0)) { logMessage(ERROR, "%s: %d: %m", __func__, __LINE__); abort(); } g_strfreev(fields); break; } } /* Because /proc/meminfo only gives us the MemTotal (total physical RAM * minus the kernel binary code), we need to round this up. Assuming * every machine has the total RAM MB number divisible by 128. */ total /= 1024; total = (total / 128 + 1) * 128; total *= 1024; dtotal = total; logMessage(INFO, "%lld kB (%lld MB) are available", dtotal, dtotal / 1024); return total; }
/** * gs_plugin_xdg_app_reviews_vote: */ static gboolean gs_plugin_xdg_app_reviews_vote (GsPlugin *plugin, GsReview *review, const gchar *uri, GError **error) { const gchar *tmp; g_autofree gchar *data = NULL; g_autoptr(JsonBuilder) builder = NULL; g_autoptr(JsonGenerator) json_generator = NULL; g_autoptr(JsonNode) json_root = NULL; /* create object with vote data */ builder = json_builder_new (); json_builder_begin_object (builder); json_builder_set_member_name (builder, "user_hash"); json_builder_add_string_value (builder, plugin->priv->user_hash); json_builder_set_member_name (builder, "user_skey"); json_builder_add_string_value (builder, gs_review_get_metadata_item (review, "user_skey")); json_builder_set_member_name (builder, "app_id"); json_builder_add_string_value (builder, gs_review_get_metadata_item (review, "app_id")); tmp = gs_review_get_metadata_item (review, "review_id"); if (tmp != NULL) { guint64 review_id; json_builder_set_member_name (builder, "review_id"); review_id = g_ascii_strtoull (tmp, NULL, 10); json_builder_add_int_value (builder, review_id); } json_builder_end_object (builder); /* export as a string */ json_root = json_builder_get_root (builder); json_generator = json_generator_new (); json_generator_set_pretty (json_generator, TRUE); json_generator_set_root (json_generator, json_root); data = json_generator_to_data (json_generator, NULL); if (data == NULL) return FALSE; /* clear cache */ if (!gs_plugin_xdg_app_reviews_invalidate_cache (review, error)) return FALSE; /* send to server */ if (!gs_plugin_xdg_app_reviews_json_post (plugin->soup_session, uri, data, error)) return FALSE; /* mark as voted */ gs_review_add_flags (review, GS_REVIEW_FLAG_VOTED); /* success */ return TRUE; }
gboolean _gum_duk_parse_pointer (duk_context * ctx, duk_idx_t index, GumDukCore * core, gpointer * ptr) { if (duk_is_string (ctx, index)) { const gchar * ptr_as_string, * end; gboolean valid; ptr_as_string = duk_require_string (ctx, index); if (g_str_has_prefix (ptr_as_string, "0x")) { *ptr = GSIZE_TO_POINTER ( g_ascii_strtoull (ptr_as_string + 2, (gchar **) &end, 16)); valid = end != ptr_as_string + 2; } else { *ptr = GSIZE_TO_POINTER ( g_ascii_strtoull (ptr_as_string, (gchar **) &end, 10)); valid = end != ptr_as_string; } return valid; } else if (duk_is_number (ctx, index)) { duk_double_t number; number = duk_require_number (ctx, index); if (number < 0) return FALSE; *ptr = GSIZE_TO_POINTER ((gsize) number); return TRUE; } return _gum_duk_get_pointer (ctx, index, core, ptr); }
static gboolean number_from_string_10(const gchar *str, guint64 *number) { gchar *end_ptr; *number = g_ascii_strtoull(str, &end_ptr, 10); if (*end_ptr == '\0') { return TRUE; } else { return FALSE; } }
/** * gusb_cmd_replug: **/ static gboolean gusb_cmd_replug (GUsbCmdPrivate *priv, gchar **values, GError **error) { GUsbDevice *device; GUsbDevice *device_new; guint16 vid, pid; /* check args */ if (g_strv_length (values) != 2) { g_set_error_literal (error, 1, 0, "no VID:PID specified"); return FALSE; } /* get vid:pid */ vid = g_ascii_strtoull (values[0], NULL, 16); pid = g_ascii_strtoull (values[1], NULL, 16); device = g_usb_context_find_by_vid_pid (priv->usb_ctx, vid, pid, error); if (device == NULL) return FALSE; /* watch for debugging */ g_signal_connect (priv->usb_ctx, "device-added", G_CALLBACK (gusb_device_list_added_cb), priv); g_signal_connect (priv->usb_ctx, "device-removed", G_CALLBACK (gusb_device_list_removed_cb), priv); /* wait for replug */ device_new = g_usb_context_wait_for_replug (priv->usb_ctx, device, 5000, error); if (device_new == NULL) return FALSE; g_object_unref (device); return TRUE; }
void sipe_core_ft_incoming_start(struct sipe_file_transfer *ft, gsize total_size) { static const guchar VER[] = "VER MSN_SECURE_FTP\r\n"; static const guchar TFR[] = "TFR\r\n"; const gsize BUFFER_SIZE = 50; const gsize FILE_SIZE_OFFSET = 4; struct sipe_file_transfer_private *ft_private = SIPE_FILE_TRANSFER_PRIVATE; guchar buf[BUFFER_SIZE]; gchar *request; gsize file_size; if (!write_exact(ft_private, VER, sizeof(VER) - 1)) { raise_ft_socket_read_error_and_cancel(ft_private); return; } if (!read_line(ft_private, buf, BUFFER_SIZE)) { raise_ft_socket_read_error_and_cancel(ft_private); return; } request = g_strdup_printf("USR %s %u\r\n", ft_private->sipe_private->username, ft_private->auth_cookie); if (!write_exact(ft_private, (guchar *)request, strlen(request))) { raise_ft_socket_write_error_and_cancel(ft_private); g_free(request); return; } g_free(request); if (!read_line(ft_private, buf, BUFFER_SIZE)) { raise_ft_socket_read_error_and_cancel(ft_private); return; } file_size = g_ascii_strtoull((gchar *) buf + FILE_SIZE_OFFSET, NULL, 10); if (file_size != total_size) { raise_ft_error_and_cancel(ft_private, _("File size is different from the advertised value.")); return; } if (!sipe_backend_ft_write(SIPE_FILE_TRANSFER_PUBLIC, TFR, sizeof(TFR) - 1)) { raise_ft_socket_write_error_and_cancel(ft_private); return; } ft_private->bytes_remaining_chunk = 0; ft_private->cipher_context = sipe_cipher_context_init(ft_private->encryption_key); ft_private->hmac_context = sipe_hmac_context_init(ft_private->hash_key); }
static int packet_parse(const char *buf, int idx, float *temp, float *humidity) { char tmp[4]; /* Packet format MIC98581: "v ttt\r". */ /* Packet format MIC98583: "v ttt hhh\r". */ /* TODO: Sanity check on buf. For now we assume well-formed ASCII. */ tmp[3] = '\0'; strncpy((char *)&tmp, &buf[2], 3); *temp = g_ascii_strtoull((const char *)&tmp, NULL, 10) / 10; if (mic_devs[idx].has_humidity) { strncpy((char *)&tmp, &buf[6], 3); *humidity = g_ascii_strtoull((const char *)&tmp, NULL, 10) / 10; } return SR_OK; }
static guint32 get_uint_parameter(guint8 *parameter_stream, gint parameter_length) { guint32 value; guint8 *val; val = (guint8 *) wmem_alloc(wmem_packet_scope(), parameter_length + 1); memcpy(val, parameter_stream, parameter_length); val[parameter_length] = '\0'; value = (guint32) g_ascii_strtoull(val, NULL, 10); return value; }
guint64 metadata_read_int(FileData *fd, const gchar *key, guint64 fallback) { guint64 ret; gchar *endptr; gchar *string = metadata_read_string(fd, key, METADATA_PLAIN); if (!string) return fallback; ret = g_ascii_strtoull(string, &endptr, 10); if (string == endptr) ret = fallback; g_free(string); return ret; }
static int _put_answer_to_connection(mhd_request_t *request, struct MHD_Connection *connection, gboolean first_call, const char *upload_data, size_t *upload_data_size) { const gchar *content_length; if (first_call) { /* Check header values and get the content lentgh */ _put_check_headers(connection, request->headers); content_length = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH); g_assert(content_length != NULL && "Missing Content-Length"); request->state.content_length = g_ascii_strtoull(content_length, NULL, 10); g_assert(request->state.content_length == request->data_len && "Bad content length header"); /* On the first call, no data have been read */ g_assert(*upload_data_size == 0); return MHD_YES; } if (*upload_data_size == 0) { /* No more data to read, its the last call * so we must send a response to client */ _put_send_response(connection, request); return MHD_YES; } /* Next calls, we must check the uploaded data */ /* Check uploaded data */ if (request->data != NULL) { _put_check_upload_data(request->data, request->data_len, upload_data, *upload_data_size, request->state.content_offset); /* All the current data are good */ request->state.content_offset += *upload_data_size; *upload_data_size = 0; } return MHD_YES; }
gboolean my_object_unstringify (MyObject *obj, const char *str, GValue *value, GError **error) { if (str[0] == '\0' || !g_ascii_isdigit (str[0])) { g_value_init (value, G_TYPE_STRING); g_value_set_string (value, str); } else { g_value_init (value, G_TYPE_INT); g_value_set_int (value, (int) g_ascii_strtoull (str, NULL, 10)); } return TRUE; }
/* * job_reset: * @job: job object * * reset job stat * */ void job_reset (Job *job) { gchar *stat, **stats, **cpustats; GstDateTime *start_time; gint i; EncoderOutput *encoder; guint version, window_size; *(job->output->state) = JOB_STATE_VOID_PENDING; g_file_get_contents ("/proc/stat", &stat, NULL, NULL); stats = g_strsplit (stat, "\n", 10); cpustats = g_strsplit (stats[0], " ", 10); job->start_ctime = 0; for (i = 1; i < 8; i++) { job->start_ctime += g_ascii_strtoull (cpustats[i], NULL, 10); } job->last_ctime = 0; job->last_utime = 0; job->last_stime = 0; g_free (stat); g_strfreev (stats); g_strfreev (cpustats); start_time = gst_date_time_new_now_local_time (); if (job->last_start_time != NULL) { g_free (job->last_start_time); } job->last_start_time = gst_date_time_to_iso8601_string (start_time); gst_date_time_unref (start_time); /* is live job with m3u8streaming? */ if (!(job->is_live) || !(jobdesc_m3u8streaming (job->description))) { return; } version = jobdesc_m3u8streaming_version (job->description); if (version == 0) { version = 3; } window_size = jobdesc_m3u8streaming_window_size (job->description); for (i = 0; i < job->output->encoder_count; i++) { encoder = &(job->output->encoders[i]); /* encoder dvr sequence */ encoder->sequence = job->output->sequence; /* reset m3u8 playlist */ if (encoder->m3u8_playlist != NULL) { m3u8playlist_free (encoder->m3u8_playlist); } encoder->m3u8_playlist = m3u8playlist_new (version, window_size, 0); } }
/* * job_stat_update: * @job: (in): job object * * update job's stat * * Returns: 0 on success. */ gint job_stat_update (Job *job) { gchar *stat_file, *stat, **stats, **cpustats; guint64 utime, stime, ctime; /* process user time, process system time, total cpu time */ gint i; stat_file = g_strdup_printf ("/proc/%d/stat", job->worker_pid); if (!g_file_get_contents (stat_file, &stat, NULL, NULL)) { GST_ERROR ("Read job %s's stat failure.", job->name); return 1; } stats = g_strsplit (stat, " ", 44); utime = g_ascii_strtoull (stats[13], NULL, 10); /* seconds */ stime = g_ascii_strtoull (stats[14], NULL, 10); /* Resident Set Size */ job->memory = g_ascii_strtoull (stats[23], NULL, 10) * sysconf (_SC_PAGESIZE); g_free (stat_file); g_free (stat); g_strfreev (stats); if (!g_file_get_contents ("/proc/stat", &stat, NULL, NULL)) { GST_ERROR ("Read /proc/stat failure."); return 1; } stats = g_strsplit (stat, "\n", 10); cpustats = g_strsplit (stats[0], " ", 10); ctime = 0; for (i = 1; i < 8; i++) { ctime += g_ascii_strtoull (cpustats[i], NULL, 10); } g_free (stat); g_strfreev (stats); g_strfreev (cpustats); job->cpu_average = ((utime + stime) * 100) / (ctime - job->start_ctime); job->cpu_current = ((utime - job->last_utime + stime - job->last_stime) * 100) / (ctime - job->last_ctime); job->last_ctime = ctime; job->last_utime = utime; job->last_stime = stime; return 0; }
static CoglBool check_mesa_driver_package (const CoglGpuInfoStrings *strings, int *version_ret) { uint64_t micro_part; const char *v; /* The version string should always begin a two-part GL version number */ if (!_cogl_gpu_info_parse_version_string (strings->version_string, 2, /* n_components */ &v, /* tail */ NULL /* version_ret */)) return FALSE; /* In mesa this will be followed optionally by "(Core Profile)" and * then "Mesa" */ v = strstr (v, " Mesa "); if (!v) return FALSE; v += 6; /* Next there will be a version string that is at least two components. On a git devel build the version will be something like "-devel<git hash>" instead */ if (!_cogl_gpu_info_parse_version_string (v, 2, /* n_components */ &v, /* tail */ version_ret)) return FALSE; /* If it is a development build then we'll just leave the micro number as 0 */ if (g_str_has_prefix (v, "-devel")) return TRUE; /* Otherwise there should be a micro version number */ if (*v != '.') return FALSE; errno = 0; micro_part = g_ascii_strtoull (v + 1, NULL /* endptr */, 10 /* base */); if (errno || micro_part > COGL_VERSION_MAX_COMPONENT_VALUE) return FALSE; *version_ret = COGL_VERSION_ENCODE (COGL_VERSION_GET_MAJOR (*version_ret), COGL_VERSION_GET_MINOR (*version_ret), micro_part); return TRUE; }
/* -------------------------- */ static int price(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int id, int offset, int big) { gint size = (big) ? 19 : 10; const char *str_value = tvb_get_string(wmem_packet_scope(), tvb, offset, size); gdouble value = guint64_to_gdouble(g_ascii_strtoull(str_value, NULL, 10))/((big)?1000000.0:10000.0); proto_tree_add_double(nasdaq_itch_tree, id, tvb, offset, size, value); col_append_fstr(pinfo->cinfo, COL_INFO, "price %g ", value); return offset + size; }
void add_table(const gchar* filename, struct configuration *conf) { struct job *j= g_new0(struct job, 1); struct restore_job *rj= g_new(struct restore_job, 1); j->job_data= (void*) rj; rj->filename= g_strdup(filename); j->type= JOB_RESTORE; gchar** split_file= g_strsplit(filename, ".", 0); rj->database= g_strdup(split_file[0]); rj->table= g_strdup(split_file[1]); rj->part= g_ascii_strtoull(split_file[2], NULL, 10); g_async_queue_push(conf->queue, j); return; }
static void board_size_change_cb (GObject *object, GParamSpec *pspec, gpointer user_data) { HitoriApplication *self = HITORI_APPLICATION (user_data); gchar *size_str; guint64 size; size_str = g_settings_get_string (self->settings, "board-size"); size = g_ascii_strtoull (size_str, NULL, 10); hitori_set_board_size (self, size); g_free (size_str); }
static gboolean barebox_state_get_int(const gchar* name, int *value) { GSubprocess *sub; GError *error = NULL; gboolean res = FALSE; GInputStream *instream; GDataInputStream *datainstream; gchar* outline; guint64 result = 0; GPtrArray *args = g_ptr_array_new_full(10, g_free); g_ptr_array_add(args, g_strdup(BAREBOX_STATE_NAME)); g_ptr_array_add(args, g_strdup("-g")); g_ptr_array_add(args, g_strdup(name)); g_ptr_array_add(args, NULL); sub = g_subprocess_newv((const gchar * const *)args->pdata, G_SUBPROCESS_FLAGS_NONE, &error); if (!sub) { g_warning("getting state failed: %s", error->message); g_clear_error(&error); goto out; } instream = g_subprocess_get_stdout_pipe(sub); datainstream = g_data_input_stream_new(instream); outline = g_data_input_stream_read_line(datainstream, NULL, NULL, NULL); if (!outline) { g_warning("failed reading state"); goto out; } result = g_ascii_strtoull(outline, NULL, 10); if (errno != 0) { g_warning("Invalid return value: '%s'\n", outline); goto out; } res = g_subprocess_wait_check(sub, NULL, &error); if (!res) { g_warning("getting state failed: %s", error->message); g_clear_error(&error); goto out; } out: g_ptr_array_unref(args); *value = result; return res; }
gssize _web_socket_util_parse_status_line (const gchar *data, gsize length, guint *status, gchar **reason) { const gchar *at; const gchar *end; gsize n; guint64 num; gchar *ep; /* * Here we parse a line like: * * HTTP/1.1 101 Switching protocols */ at = data; end = memchr (at, '\n', length); if (end == NULL) return 0; /* need more data */ n = parse_version (at, (end - at)); if (n == 0 || at[n] != ' ') return -1; at += n; /* Extra spaces */ at = strskip (at, ' ', end); /* First check for space after status */ if (memchr (at, ' ', (end - at)) == NULL) return -1; /* This will stop at above space */ num = g_ascii_strtoull (at, &ep, 10); if (num == 0 || num > G_MAXUINT || *ep != ' ') return -1; at = strskip (ep, ' ', end); if (reason) { *reason = g_strndup (at, (end - at)); g_strstrip (*reason); } if (status) *status = (guint)num; return (end - data) + 1; }
void sipe_process_imdn(struct sipe_core_private *sipe_private, struct sipmsg *msg) { gchar *with = parse_from(sipmsg_find_header(msg, "From")); const gchar *callid = sipmsg_find_header(msg, "Call-ID"); static struct sip_session *session; sipe_xml *xn_imdn; const sipe_xml *node; gchar *message_id; gchar *message; session = sipe_session_find_chat_or_im(sipe_private, callid, with); if (!session) { SIPE_DEBUG_INFO("sipe_process_imdn: unable to find conf session with callid=%s", callid); g_free(with); return; } xn_imdn = sipe_xml_parse(msg->body, msg->bodylen); message_id = sipe_xml_data(sipe_xml_child(xn_imdn, "message-id")); message = g_hash_table_lookup(session->conf_unconfirmed_messages, message_id); /* recipient */ for (node = sipe_xml_child(xn_imdn, "recipient"); node; node = sipe_xml_twin(node)) { gchar *tmp = parse_from(sipe_xml_attribute(node, "uri")); gchar *uri = parse_from(tmp); gchar *status = sipe_xml_data(sipe_xml_child(node, "status")); guint error = status ? g_ascii_strtoull(status, NULL, 10) : 0; /* default to error if missing or conversion failed */ if ((error == 0) || (error >= 300)) sipe_user_present_message_undelivered(sipe_private, session, error, -1, uri, message); g_free(status); g_free(tmp); g_free(uri); } sipe_xml_free(xn_imdn); g_hash_table_remove(session->conf_unconfirmed_messages, message_id); SIPE_DEBUG_INFO("sipe_process_imdn: removed message %s from conf_unconfirmed_messages(count=%d)", message_id, g_hash_table_size(session->conf_unconfirmed_messages)); g_free(message_id); g_free(with); }
static gboolean g_ascii_string_to_unsigned (const gchar *str, guint base, guint64 min, guint64 max, guint64 *out_num, GError **error) { const gchar *end_ptr = NULL; gint saved_errno = 0; guint64 number; g_return_val_if_fail (str != NULL, FALSE); g_return_val_if_fail (base >= 2 && base <= 36, FALSE); g_return_val_if_fail (min <= max, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (str[0] == '\0') { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "Empty string is not a number"); return FALSE; } errno = 0; number = g_ascii_strtoull (str, (gchar **)&end_ptr, base); saved_errno = errno; if (g_ascii_isspace (str[0]) || str_has_sign (str) || (base == 16 && str_has_hex_prefix (str)) || (saved_errno != 0 && saved_errno != ERANGE) || end_ptr == NULL || *end_ptr != '\0') { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "“%s” is not an unsigned number", str); return FALSE; } if (saved_errno == ERANGE || number < min || number > max) { g_autofree gchar *min_str = g_strdup_printf ("%" G_GUINT64_FORMAT, min); g_autofree gchar *max_str = g_strdup_printf ("%" G_GUINT64_FORMAT, max); g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "Number “%s” is out of bounds [%s, %s]", str, min_str, max_str); return FALSE; } if (out_num != NULL) *out_num = number; return TRUE; }
void add_rgb_file (gchar *file) { FILE *fp; gchar *p, buffer[512], spec[8]; gint r, g, b; fp = fopen (file, "r"); if (!fp) return; /* silently fail */ while ((p = fgets (buffer, sizeof buffer, fp)) != NULL) { if (buffer[0] == '!') continue; r = g_ascii_strtoull (p, &p, 10); g = g_ascii_strtoull (p, &p, 10); b = g_ascii_strtoull (p, &p, 10); p += strspn (p, " \t"); g_sprintf (spec, "#%.2X%.2X%.2X", r, g, b); colorname = g_strchomp (g_strdup (p)); add_list_color (spec, FALSE); } g_free(p); fclose (fp); }
static gboolean _main_verifyStaticTLS() { const gchar* ldStaticTLSValue = g_getenv("LD_STATIC_TLS_EXTRA"); if(!ldStaticTLSValue) { /* LD_STATIC_TLS_EXTRA contains nothing */ return FALSE; } guint64 tlsSize = g_ascii_strtoull(ldStaticTLSValue, NULL, 10); if(tlsSize >= 1024) { return TRUE; } else { return FALSE; } }
/* internal utility methods */ static bool parse_stinfo(const char *buf, bool *is_local, struct stat *stbuf) { gchar *st_key; guint64 st_value = -1; gchar **components; gchar **cur; gchar *end; components = g_strsplit(buf, ",", 0); if (!components){ return false; } for (cur = components; *cur != NULL; cur++) { gchar **each_stinfo= g_strsplit(*cur, ":", 0); if ((*each_stinfo == NULL) || (*(each_stinfo+1) == NULL)){ return false; } st_key = *(each_stinfo+0); st_value = g_ascii_strtoull(*(each_stinfo+1), &end, 10); if (*(each_stinfo+1) == end) { // string conversion failed return false; } if (strcmp(st_key, "atime") == 0){ stbuf->st_atime = st_value; } else if (strcmp(st_key, "ctime") == 0){ stbuf->st_ctime = st_value; } else if (strcmp(st_key, "mtime") == 0){ stbuf->st_mtime = st_value; } else if (strcmp(st_key, "mode") == 0){ stbuf->st_mode = st_value; } else if (strcmp(st_key, "gid") == 0){ stbuf->st_gid = st_value; } else if (strcmp(st_key, "uid") == 0){ stbuf->st_uid = st_value; } else if (strcmp(st_key, "nlink") == 0){ stbuf->st_nlink= st_value; } else if (strcmp(st_key, "size") == 0){ stbuf->st_size = st_value; } else if (strcmp(st_key, "exists") == 0){ *is_local = st_value; } else { return false; } g_strfreev(each_stinfo); } g_strfreev(components); return true; }
static gboolean process_add_group_response(struct sipe_core_private *sipe_private, struct sipmsg *msg, struct transaction *trans) { if (msg->response == 200) { struct sipe_group *group; struct group_user_context *ctx = trans->payload->data; sipe_xml *xml; const sipe_xml *node; char *group_id; xml = sipe_xml_parse(msg->body, msg->bodylen); if (!xml) { return FALSE; } node = sipe_xml_child(xml, "Body/addGroup/groupID"); if (!node) { sipe_xml_free(xml); return FALSE; } group_id = sipe_xml_data(node); if (!group_id) { sipe_xml_free(xml); return FALSE; } group = sipe_group_add(sipe_private, ctx->group_name, NULL, NULL, g_ascii_strtoull(group_id, NULL, 10)); g_free(group_id); if (group) { struct sipe_buddy *buddy = sipe_buddy_find_by_uri(sipe_private, ctx->user_name); if (buddy) { sipe_buddy_insert_group(buddy, group); sipe_group_update_buddy(sipe_private, buddy); } } sipe_xml_free(xml); return TRUE; } return FALSE; }