public
Description: A Clutter-based Twitter client
Homepage: http://live.gnome.org/Tweet
Clone URL: git://github.com/ebassi/tweet.git
Search Repo:
Emmanuele Bassi (author)
Sat Apr 19 07:29:41 -0700 2008
commit  a643edaaa7ba328cf4f24356dbeb5c2faa5837e3
tree    a002d1ab1d3439fcbbd514ce3b803f4d8e216866
parent  455bcf01d7cb8a5c84630024c693349a9c06dafe
tweet / twitter-glib / twitter-common.c
100644 99 lines (74 sloc) 1.784 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
 
#define _XOPEN_SOURCE
 
#include <stdlib.h>
#include <string.h>
 
#include <time.h>
 
#include <libsoup/soup.h>
 
#include "twitter-common.h"
 
guint
twitter_error_from_status (guint status)
{
  switch (status)
    {
    case SOUP_STATUS_CANT_RESOLVE:
    case SOUP_STATUS_CANT_RESOLVE_PROXY:
      return TWITTER_ERROR_HOST_NOT_FOUND;
 
    case SOUP_STATUS_CANCELLED:
      return TWITTER_ERROR_CANCELLED;
 
    case SOUP_STATUS_UNAUTHORIZED:
    case SOUP_STATUS_PAYMENT_REQUIRED:
    case SOUP_STATUS_FORBIDDEN:
      return TWITTER_ERROR_PERMISSION_DENIED;
 
    case SOUP_STATUS_NOT_FOUND:
    case SOUP_STATUS_GONE:
      return TWITTER_ERROR_NOT_FOUND;
 
    case SOUP_STATUS_GATEWAY_TIMEOUT:
      return TWITTER_ERROR_TIMED_OUT;
    }
 
  return TWITTER_ERROR_FAILED;
}
 
GQuark
twitter_error_quark (void)
{
  return g_quark_from_static_string ("twitter-error-quark");
}
 
gchar *
twitter_http_date_from_time_t (time_t time_)
{
  SoupDate *soup_date;
  gchar *retval;
 
  soup_date = soup_date_new_from_time_t (time_);
  retval = soup_date_to_string (soup_date, SOUP_DATE_HTTP);
  soup_date_free (soup_date);
 
  return retval;
}
 
gchar *
twitter_http_date_from_delta (gint seconds)
{
  time_t now, delta;
 
  time (&now);
  delta = now - seconds;
 
  return twitter_http_date_from_time_t (delta);
}
 
time_t
twitter_http_date_to_time_t (const gchar *date)
{
  SoupDate *soup_date;
  time_t retval;
 
  soup_date = soup_date_new_from_string (date);
  retval = soup_date_to_time_t (soup_date);
  soup_date_free (soup_date);
 
  return retval;
}
 
gint
twitter_http_date_to_delta (const gchar *date)
{
  time_t res, now;
 
  res = twitter_http_date_to_time_t (date);
  if (res == (time_t) -1)
    return 0;
 
  time (&now);
 
  return (now - res);
}