/**
 * 检查连接池连接是否超时
 * @param[IN] GTimeVal *now_tv 当前时间。如果为NULL则函数里重新计算当前时间
 * @param[IN] gint max_idle_interval 超时时间(秒)
 * @return TRUE 超时
 * @return FALSE 没超时
 */
gboolean check_pool_entry_timeout(network_connection_pool_entry *entry,
		GTimeVal *now_tv, gint max_idle_interval) {
	GTimeVal now_tv_storage;
	gint time_diff;
//#define	POOL_ENTRY_MAX_TIMEOUT (20 * G_USEC_PER_SEC)

	if (max_idle_interval < 0) {
		return FALSE;
	}

	if (now_tv == NULL) {
		g_get_current_time(&now_tv_storage);
		now_tv = &now_tv_storage;
	}
	time_diff = now_tv->tv_sec - (entry->added_ts).tv_sec;
	if (time_diff > max_idle_interval) {
#ifdef DEBUG_CONN_POOL
		char * add_time_str = g_time_val_to_iso8601(&(entry->added_ts));
		char * now_time_str = g_time_val_to_iso8601(now_tv);
		g_debug("[%s]: entry is timed out: %p, added: %s, now: %s, diff: %d(s), timeout: %d(s)"
				, G_STRLOC, entry
				, add_time_str
				, now_time_str
				, time_diff
				, max_idle_interval
				);
		g_free(add_time_str);
		g_free(now_time_str);
#endif
		return TRUE;
	} else {
		return FALSE;
	}
}
PhotosQuery *
photos_query_builder_create_collection_query (PhotosSearchContextState *state, const gchar *name)
{
  GTimeVal tv;
  gchar *sparql;
  gchar *time;
  gint64 timestamp;

  timestamp = g_get_real_time () / G_USEC_PER_SEC;
  tv.tv_sec = timestamp;
  tv.tv_usec = 0;
  time = g_time_val_to_iso8601 (&tv);

  sparql = g_strdup_printf ("INSERT { _:res a nfo:DataContainer ; a nie:DataObject ; "
                            "nie:contentLastModified '%s' ; "
                            "nie:title '%s' ; "
                            "nao:identifier '%s%s' }",
                            time,
                            name,
                            PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER,
                            name);
  g_free (time);

  return photos_query_new (state, sparql);
}
Exemple #3
0
void write_dot_file(const gchar *base_file_name, gchar *dot_data, gboolean with_timestamp)
{
    GTimeVal time;
    const gchar *path;
    gchar *filename, *timestamp = NULL;
    gboolean success;

    g_return_if_fail(base_file_name);
    g_return_if_fail(dot_data);

    path = g_getenv("OWR_DEBUG_DUMP_DOT_DIR");
    if (!path)
        return;

    if (with_timestamp) {
        g_get_current_time(&time);
        timestamp = g_time_val_to_iso8601(&time);
    }

    filename = g_strdup_printf("%s/%s%s%s.dot", path[0] ? path : ".",
        timestamp ? timestamp : "", timestamp ? "-" : "", base_file_name);
    success = g_file_set_contents(filename, dot_data, -1, NULL);
    g_warn_if_fail(success);

    g_free(dot_data);
    g_free(filename);
    g_free(timestamp);
}
Exemple #4
0
bool
Opal::Sip::EndPoint::OnReceivedMESSAGE (OpalTransport & transport,
					SIP_PDU & pdu)
{
  if (pdu.GetMIME().GetContentType(false) != "text/plain")
    return false; // Ignore what we do not handle.

  PString from = pdu.GetMIME().GetFrom();
  PINDEX j = from.Find (';');
  if (j != P_MAX_INDEX)
    from = from.Left(j); // Remove all parameters
  j = from.Find ('<');
  if (j != P_MAX_INDEX && from.Find ('>') == P_MAX_INDEX)
    from += '>';

  SIPURL uri = from;
  uri.Sanitise (SIPURL::RequestURI);
  std::string display_name = (const char *) uri.GetDisplayName ();
  std::string message_uri = (const char *) uri.AsString ();
  std::string _message = (const char *) pdu.GetEntityBody ();
  Ekiga::Message::payload_type payload;
  // FIXME: we push as 'text/plain' without really knowing
  payload.insert (std::make_pair ("text/plain", _message));
  GTimeVal current;
  g_get_current_time (&current);
  gchar* time = g_time_val_to_iso8601 (&current);
  Ekiga::Message msg = {time, display_name, payload };
  g_free (time);

  Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::push_message_in_main, this, message_uri, msg));

  return SIPEndPoint::OnReceivedMESSAGE (transport, pdu);
}
void
mex_content_set_last_used_metadatas (MexContent *content)
{
  guint count;
  gchar str[20], *nstr;
  const gchar *play_count;
  GDateTime *datetime;
  GTimeVal tv;

  play_count = mex_content_get_metadata (content,
                                         MEX_CONTENT_METADATA_PLAY_COUNT);
  if (play_count) {
    count = atoi (play_count);
    count++;
  } else
    count = 1;
  snprintf (str, sizeof (str), "%u", count);
  mex_content_set_metadata (content, MEX_CONTENT_METADATA_PLAY_COUNT, str);

  datetime = g_date_time_new_now_local ();
  if (datetime) {
    if (g_date_time_to_timeval (datetime, &tv)) {
      tv.tv_usec = 0;
      nstr = g_time_val_to_iso8601 (&tv);
      if (nstr) {
        mex_content_set_metadata (content,
                                  MEX_CONTENT_METADATA_LAST_PLAYED_DATE,
                                  nstr);
        g_free (nstr);
      }
    }
    g_date_time_unref (datetime);
  }
}
Exemple #6
0
void
Opal::Sip::EndPoint::OnMESSAGECompleted (const SIPMessage::Params & params,
                                         SIP_PDU::StatusCodes reason)
{
  PTRACE (4, "IM sending completed, reason: " << reason);

  // after TemporarilyUnavailable, RequestTimeout appears too, hence do not process it too
  if (reason == SIP_PDU::Successful_OK || reason == SIP_PDU::Failure_RequestTimeout)
    return;

  SIPURL to = params.m_remoteAddress;
  to.Sanitise (SIPURL::ToURI);
  std::string uri = (const char*) to.AsString ();
  std::string display_name = (const char*) to.GetDisplayName ();

  std::string reason_shown = _("Could not send message: ");
  if (reason == SIP_PDU::Failure_TemporarilyUnavailable)
    reason_shown += _("user offline");
  else
    reason_shown += SIP_PDU::GetStatusCodeDescription (reason);  // too many to translate them with _()...
  Ekiga::Message::payload_type payload;
  // FIXME: we push as 'text/plain' without really knowing...
  payload.insert (std::make_pair ("text/plain", reason_shown));
  GTimeVal current;
  g_get_current_time (&current);
  gchar* time = g_time_val_to_iso8601 (&current);
  Ekiga::Message msg = {time, "" /* it's a notice */, payload };
  g_free (time);

  Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::push_message_in_main, this, uri, msg));
}
static gboolean
gst_hls_demux_schedule (GstHLSDemux * demux)
{
  gfloat update_factor;
  gint count;

  /* As defined in §6.3.4. Reloading the Playlist file:
   * "If the client reloads a Playlist file and finds that it has not
   * changed then it MUST wait for a period of time before retrying.  The
   * minimum delay is a multiple of the target duration.  This multiple is
   * 0.5 for the first attempt, 1.5 for the second, and 3.0 thereafter."
   */
  count = demux->client->update_failed_count;
  if (count < 3)
    update_factor = update_interval_factor[count];
  else
    update_factor = update_interval_factor[3];

  /* schedule the next update using the target duration field of the
   * playlist */
  g_time_val_add (&demux->next_update,
      demux->client->current->targetduration * update_factor * 1000000);
  GST_DEBUG_OBJECT (demux, "Next update scheduled at %s",
      g_time_val_to_iso8601 (&demux->next_update));

  return TRUE;
}
Exemple #8
0
static json_t *tr_msg_encode_one_server(TID_SRVR_BLK *srvr)
{
  json_t *jsrvr = NULL;
  json_t *jstr = NULL;
  gchar *time_str = g_time_val_to_iso8601(&srvr->key_expiration);

  tr_debug("Encoding one server.");

  jsrvr = json_object();

  /* Server IP Address -- TBD handle IPv6 */
  jstr = json_string(inet_ntoa(srvr->aaa_server_addr));
  json_object_set_new(jsrvr, "server_addr", jstr);

  json_object_set_new(jsrvr,
		      "key_expiration", json_string(time_str));
  g_free(time_str);
  /* Server DH Block */
  jstr = json_string(srvr->key_name->buf);
  json_object_set_new(jsrvr, "key_name", jstr);
  json_object_set_new(jsrvr, "server_dh", tr_msg_encode_dh(srvr->aaa_server_dh));
  if (srvr->path)
    /* The path is owned by the srvr, so grab an extra ref*/
    json_object_set(jsrvr, "path", srvr->path);
  return jsrvr;
}
Exemple #9
0
void logToFile(session_t* session, int socket, char* resource, char* verb, int responseCode) {
    FILE* file = fopen("httpd.log", "a");
    connection_t *c =(connection_t *)g_hash_table_lookup(session->connections, GINT_TO_POINTER(socket));

    if (c == NULL)
    {
        return;
    }

    if (file == NULL) {
        perror("Failed to open logfile.\n");
        return;
    }

    GTimeVal tv;
    g_get_current_time(&tv);
    tv.tv_usec = 0;
    gchar *timestr = g_time_val_to_iso8601(&tv);

    // Print to file (append)
    fprintf(file, "%s : %s:%d %s\n", timestr, c->ip, c->port, verb);
    fprintf(file, "%s : %d\n\n", resource, responseCode);

    // Free resources
    g_free(timestr);
    fclose(file);
}
Exemple #10
0
/**
 * xml_writer_write_timeval:
 * @writer: A #XmlWriter
 * @value: a #GTimeVal
 *
 * Writes @value as an iso8601 formatted string.
 */
void
xml_writer_write_timeval (XmlWriter *writer,
                          GTimeVal  *timeval)
{
  gchar *str = g_time_val_to_iso8601 (timeval);
  xml_writer_write_string (writer, str);
  g_free (str);
}
Exemple #11
0
/** get time as a string, for NOW use NULL, user must g_free result */
gchar* get_time(GTimeVal* ptv) {
    if (ptv == NULL) {
	GTimeVal tv;
	ptv = &tv;
	g_get_current_time(ptv);
    }
    gchar* res = g_time_val_to_iso8601(ptv);
    return(res);
}
Exemple #12
0
/**
 * gd_iso8601_from_timestamp:
 * @timestamp:
 *
 * Returns: (transfer full):
 */
gchar *
gd_iso8601_from_timestamp (gint64 timestamp)
{
  GTimeVal tv;

  tv.tv_sec = timestamp;
  tv.tv_usec = 0;
  return g_time_val_to_iso8601 (&tv);
}
const char* stored_item_get_last_access(psi si)
{
	GTimeVal tv;
	if (!si->lastaccess)
		return "Never";
	tv.tv_sec = si->lastaccess >> 32;
	tv.tv_usec = si->lastaccess & 0xFFFFFFFF;
	return g_time_val_to_iso8601(&tv);
}
Exemple #14
0
gchar *
gdata_parser_int64_to_iso8601 (gint64 _time)
{
	GTimeVal time_val;

	time_val.tv_sec = _time;
	time_val.tv_usec = 0;

	return g_time_val_to_iso8601 (&time_val);
}
Exemple #15
0
void     S52_printf(const gchar *string)
{
    char str[MAXL];
    g_get_current_time(&_now);

    snprintf(str, MAXL-1, "%s %s\n", g_time_val_to_iso8601(&_now), string);
    write(_log, str, strlen(str));

    if (NULL != _err_cb)
        _err_cb(str);
}
Exemple #16
0
/**
 * CacheUtilDatetimeToString:
 * @value: Date to create string from. Must be UTC.
 *
 * Returns: (allow-none): Date in "{yyyy}-{mm}-{dd}T{hh}:{mm}:{ss}Z" format
 * (ISO 8601) or #NULL if the date couldn't be serialized.
 */
gchar *CacheUtilDatetimeToString(GDateTime *value) {
  GTimeVal tv = {0, 0};

  if (!value)
    return NULL;

  if (g_date_time_to_timeval(value, &tv)) {
    return g_time_val_to_iso8601(&tv);
  } else {
    return NULL;
  }
}
Exemple #17
0
/**
 * pk_iso8601_present:
 *
 * Return value: The current iso8601 date and time
 *
 * Since: 0.5.2
 **/
gchar *
pk_iso8601_present (void)
{
	GTimeVal timeval;
	gchar *timespec;

	/* get current time */
	g_get_current_time (&timeval);
	timespec = g_time_val_to_iso8601 (&timeval);

	return timespec;
}
Exemple #18
0
static void appendMessage(char *message, PhpConsoleMessageType type)
{
	GTimeVal now;
	g_get_current_time(&now);
	char *dateTime = g_time_val_to_iso8601(&now);

	GtkTreeIter iter;
	gtk_list_store_append(store, &iter);
	gtk_list_store_set(store, &iter, ROW_TIME, dateTime, ROW_MESSAGE, message, ROW_MESSAGE_TYPE, type, -1);

	GtkTreePath	*path = gtk_tree_path_new_from_indices(lines++, -1);
	gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(list), path, NULL, TRUE, 0.0, 0.0);
	gtk_tree_path_free(path);
}
Exemple #19
0
void       
gnm_insert_meta_date (GODoc *doc, char const *name)
{
	GValue *value = g_new0 (GValue, 1);
	GTimeVal time;

	g_get_current_time (&time);
	time.tv_usec = 0L;
	g_value_init (value, G_TYPE_STRING);
	g_value_take_string (value,
			     g_time_val_to_iso8601 (&time));
	gsf_doc_meta_data_insert (go_doc_get_meta_data (doc), 
				  g_strdup (name), 
				  value);
}
Exemple #20
0
static void     _S52_printf(const gchar *string)
{
    char str[MAXL];
    g_get_current_time(&_now);

    snprintf(str, MAXL-1, "%s %s", g_time_val_to_iso8601(&_now), string);

    // if user set a callback .. call it
    if (NULL != _err_cb) {
        _err_cb(str);
    }
#ifdef S52_USE_LOG
    // log to file
    write(_log, str, strlen(str));
#endif
}
Exemple #21
0
/*
 * Print an error message to current monitor if we have one, else to stderr.
 * Format arguments like vsprintf().  The resulting message should be
 * a single phrase, with no newline or trailing punctuation.
 * Prepend the current location and append a newline.
 * It's wrong to call this in a QMP monitor.  Use error_setg() there.
 */
void error_vreport(const char *fmt, va_list ap)
{
    GTimeVal tv;
    gchar *timestr;

    if (enable_timestamp_msg && !cur_mon) {
        g_get_current_time(&tv);
        timestr = g_time_val_to_iso8601(&tv);
        error_printf("%s ", timestr);
        g_free(timestr);
    }

    error_print_loc();
    error_vprintf(fmt, ap);
    error_printf("\n");
}
Exemple #22
0
void
accounts_set_last_activity(const char *const account_name)
{
    if (accounts_account_exists(account_name)) {
        GDateTime *nowdt = g_date_time_new_now_utc();
        GTimeVal nowtv;
        gboolean res = g_date_time_to_timeval(nowdt, &nowtv);
        g_date_time_unref(nowdt);

        if (res) {
            char *timestr = g_time_val_to_iso8601(&nowtv);
            g_key_file_set_string(accounts, account_name, "last.activity", timestr);
            free(timestr);
            _save_accounts();
        }
    }
}
PhotosQuery *
photos_query_builder_update_mtime_query (PhotosSearchContextState *state, const gchar *resource)
{
  GTimeVal tv;
  gchar *sparql;
  gchar *time;
  gint64 timestamp;

  timestamp = g_get_real_time () / G_USEC_PER_SEC;
  tv.tv_sec = timestamp;
  tv.tv_usec = 0;
  time = g_time_val_to_iso8601 (&tv);

  sparql = g_strdup_printf ("INSERT OR REPLACE { <%s> nie:contentLastModified '%s' }", resource, time);
  g_free (time);

  return photos_query_new (state, sparql);
}
Exemple #24
0
 std::string DateTime::to_iso8601() const
 {
   std::string retval;
   if(!is_valid()) {
     return retval;
   }
   char *  iso8601 = g_time_val_to_iso8601(const_cast<Glib::TimeVal*>(&m_date));
   if(iso8601) {
     retval = iso8601;
     if(m_date.tv_usec == 0) {
       // see http://bugzilla.gnome.org/show_bug.cgi?id=581844
       // when usec is 0, glib/libc does NOT add the usec values
       // to the output
       retval.insert(19, ".000000");
     }
     g_free(iso8601);
   }
   return retval;
 }
Exemple #25
0
/*
 * Print an error message to current monitor if we have one, else to stderr.
 * Format arguments like sprintf().  The result should not contain
 * newlines.
 * Prepend the current location and append a newline.
 * It's wrong to call this in a QMP monitor.  Use qerror_report() there.
 */
void error_report(const char *fmt, ...)
{
    va_list ap;
    GTimeVal tv;
    gchar *timestr;

    if (enable_timestamp_msg) {
        g_get_current_time(&tv);
        timestr = g_time_val_to_iso8601(&tv);
        error_printf("%s ", timestr);
        g_free(timestr);
    }

    error_print_loc();
    va_start(ap, fmt);
    error_vprintf(fmt, ap);
    va_end(ap);
    error_printf("\n");
}
Exemple #26
0
static void appendMessage(char *tabname, char *message, IrcConsoleMessageType type)
{
	IrcConsoleTab *tab = g_hash_table_lookup(tabs, tabname);

	if(tab == NULL) {
		logError("Requested unknown tab '%s'", tabname);
		return;
	}

	GTimeVal *now = ALLOCATE_OBJECT(GTimeVal);
	g_get_current_time(now);
	char *dateTime = g_time_val_to_iso8601(now);

	GtkTreeIter iter;
	gtk_list_store_append(tab->store, &iter);
	gtk_list_store_set(tab->store, &iter, ROW_TIME, dateTime, ROW_MESSAGE, message, ROW_MESSAGE_TYPE, type, -1);

	GtkTreePath	*path = gtk_tree_path_new_from_indices(tab->lines++, -1);
	gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(tab->list), path, NULL, TRUE, 0.0, 0.0);
}
Exemple #27
0
static void latest_version_thread ( GtkWindow *window )
{
	// Need to allow a few redirects, as SF file is often served from different server
	DownloadMapOptions options = { FALSE, FALSE, NULL, 5, NULL, NULL, NULL };
	gchar *filename = a_download_uri_to_tmp_file ( "http://sourceforge.net/projects/viking/files/VERSION", &options );
	//gchar *filename = g_strdup ( "VERSION" );
	if ( !filename ) {
		return;
	}

	GMappedFile *mf = g_mapped_file_new ( filename, FALSE, NULL );
	if ( !mf )
		return;

	gchar *text = g_mapped_file_get_contents ( mf );

	gint latest_version = viking_version_to_number ( text );
	gint my_version = viking_version_to_number ( VIKING_VERSION );

	g_debug ( "The lastest version is: %s", text );

	if ( my_version < latest_version ) {
		new_version_thread_data *nvtd = g_malloc ( sizeof(new_version_thread_data) );
		nvtd->window = window;
		nvtd->version = g_strdup ( text );
		gdk_threads_add_idle ( (GSourceFunc) new_version_available_message, nvtd );
	}
	else
		g_debug ( "Running the lastest version: %s", VIKING_VERSION );

	g_mapped_file_unref ( mf );
	if ( filename ) {
		g_remove ( filename );
		g_free ( filename );
	}

	// Update last checked time
	GTimeVal time;
	g_get_current_time ( &time );
	a_settings_set_string ( VIK_SETTINGS_VERSION_CHECKED_DATE, g_time_val_to_iso8601(&time) );
}
Exemple #28
0
static void   _S52_printf(CCHAR *string)
{
    char str[MAXL];
    //static
    GTimeVal now;
    g_get_current_time(&now);

    snprintf(str, MAXL-1, "%s %s", g_time_val_to_iso8601(&now), string);

    // if user set a callback .. call it
    if (NULL != _log_cb) {
        _log_cb(str);
    }

    // log to file
    if (NULL != _logFile) {
        write(_logFile, str, strlen(str));
    }

    // STDOUT
    g_printf("%s", str);
}
Exemple #29
0
static void
print_build_info (IdeContext *context,
                  IdeDevice  *device)
{
  IdeProject *project;
  IdeBuildSystem *build_system;
  IdeVcs *vcs;
  const gchar *project_name;
  const gchar *vcs_name;
  const gchar *build_system_name;
  const gchar *device_id;
  const gchar *system_type;
  g_autofree gchar *build_date = NULL;
  GTimeVal tv;

  project = ide_context_get_project (context);
  project_name = ide_project_get_name (project);

  vcs = ide_context_get_vcs (context);
  vcs_name = g_type_name (G_TYPE_FROM_INSTANCE (vcs));

  build_system = ide_context_get_build_system (context);
  build_system_name = g_type_name (G_TYPE_FROM_INSTANCE (build_system));

  device_id = ide_device_get_id (device);
  system_type = ide_device_get_system_type (device);

  g_get_current_time (&tv);
  build_date = g_time_val_to_iso8601 (&tv);

  g_printerr (_("========================\n"));
  g_printerr (_("           Project Name: %s\n"), project_name);
  g_printerr (_(" Version Control System: %s\n"), vcs_name);
  g_printerr (_("           Build System: %s\n"), build_system_name);
  g_printerr (_("    Build Date and Time: %s\n"), build_date);
  g_printerr (_("    Building for Device: %s (%s)\n"), device_id, system_type);
  g_printerr (_("========================\n"));
}
Exemple #30
0
static void
_logger_stderr(const gchar *log_domain, GLogLevelFlags log_level,
		const gchar *message, gpointer user_data UNUSED)
{
	static guint longest_prefix = 38;
	GString *gstr = g_string_sized_new(256);

	if (oio_log_flags & LOG_FLAG_PRETTYTIME) {
		GTimeVal tv;
		g_get_current_time(&tv);
		gchar * strnow = g_time_val_to_iso8601 (&tv);
		g_string_append_printf(gstr, "%s", strnow);
		g_free(strnow);
	} else {
		g_string_append_printf(gstr, "%"G_GINT64_FORMAT,
				g_get_monotonic_time () / G_TIME_SPAN_MILLISECOND);
	}

	g_string_append_printf(gstr, " %d %04X ",
			getpid(), oio_log_current_thread_id());

	if (!log_domain || !*log_domain)
		log_domain = "-";

	if (LOG_LOCAL1 == get_facility(log_domain)) {
		g_string_append_printf(gstr, "acc %s ", glvl_to_str(log_level));
	} else {
		g_string_append_printf(gstr, "log %s ", glvl_to_str(log_level));

		/* print the domain */
		if (!(oio_log_flags & LOG_FLAG_TRIM_DOMAIN))
			g_string_append(gstr, log_domain);
		else {
			const gchar *p = log_domain;
			while (p && *p) {
				g_string_append_c(gstr, *p);
				p = strchr(p, '.');
				if (p) {
					g_string_append_c(gstr, '.');
					p ++;
				}
			}
		}
	}

	/* prefix done, print a separator */
	if (oio_log_flags & LOG_FLAG_COLUMNIZE) {
		longest_prefix = MAX(gstr->len+1,longest_prefix);
		do {
			g_string_append_c(gstr, ' ');
		} while (gstr->len < longest_prefix);
	}
	else
		g_string_append_c(gstr, ' ');

	/* now append the message */
	_append_message(gstr, message);
	g_string_append_c(gstr, '\n');

	if (oio_log_flags & LOG_FLAG_PURIFY)
		_purify(gstr->str);

	/* send the buffer */
	fwrite(gstr->str, gstr->len, 1, stderr);
	g_string_free(gstr, TRUE);
}