- Timestamp:
- 2012-02-08T00:24:12Z (13 years ago)
- Branches:
- master
- Children:
- e0a0a42
- Parents:
- d2abcae
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/twitter/twitter.c
rd2abcae r7d27962 197 197 } 198 198 199 int twitter_url_len_diff(gchar *msg, unsigned int target_len) 200 { 201 int url_len_diff = 0; 202 203 static GRegex *regex = NULL; 204 GMatchInfo *match_info; 205 206 if (regex == NULL) 207 regex = g_regex_new("(^|\\s)(http(s)?://[^\\s$]+)", 0, 0, NULL); 208 209 g_regex_match(regex, msg, 0, &match_info); 210 while (g_match_info_matches(match_info)) { 211 gchar *url = g_match_info_fetch(match_info, 2); 212 url_len_diff += target_len - g_utf8_strlen(url, -1); 213 if (g_match_info_fetch(match_info, 3) != NULL) 214 url_len_diff += 1; 215 g_free(url); 216 g_match_info_next(match_info, NULL); 217 } 218 g_match_info_free(match_info); 219 220 return url_len_diff; 221 } 222 199 223 static gboolean twitter_length_check(struct im_connection *ic, gchar * msg) 200 224 { 201 225 int max = set_getint(&ic->acc->set, "message_length"), len; 202 203 if (max == 0 || (len = g_utf8_strlen(msg, -1)) <= max) 226 int target_len = set_getint(&ic->acc->set, "target_url_length"); 227 int url_len_diff = 0; 228 229 if (target_len > 0) 230 url_len_diff = twitter_url_len_diff(msg, target_len); 231 232 if (max == 0 || (len = g_utf8_strlen(msg, -1) + url_len_diff) <= max) 204 233 return TRUE; 205 234 … … 214 243 char *def_url; 215 244 char *def_oauth; 245 char *def_tul; 216 246 217 247 if (strcmp(acc->prpl->name, "twitter") == 0) { 218 248 def_url = TWITTER_API_URL; 219 249 def_oauth = "true"; 250 def_tul = "20"; 220 251 } else { /* if( strcmp( acc->prpl->name, "identica" ) == 0 ) */ 221 252 def_url = IDENTICA_API_URL; 222 253 def_oauth = "true"; 254 def_tul = "0"; 223 255 } 224 256 … … 236 268 237 269 s = set_add(&acc->set, "message_length", "140", set_eval_int, acc); 270 271 s = set_add(&acc->set, "target_url_length", def_tul, set_eval_int, acc); 238 272 239 273 s = set_add(&acc->set, "mode", "chat", set_eval_mode, acc);
Note: See TracChangeset
for help on using the changeset viewer.