int memcache_store (struct connection *c, int op, const char *old_key, int old_key_len, int flags, int delay, int size) { INIT; if (verbosity > 1) { fprintf (stderr, "memcache_store: key='%s', key_len=%d, value_len=%d, \n", old_key, old_key_len, size); } if (size + 1 < MAX_VALUE_LEN) { char *key; int key_len; eat_at (old_key, old_key_len, &key, &key_len); //set ("stat{$uid},{$type}#{$cnt}", $text) if (key_len >= 4 && !strncmp (key, "stat", 4)) { int uid, type, cnt; if (sscanf (key, "stat%d,%d#%d", &uid, &type, &cnt) != 3 || cnt == 0) { RETURN(set, -2); } safe_read_in (&c->In, buf, size); buf[size] = 0; do_isearch_set_stat (uid, type, cnt, buf, size); RETURN(set, 1); } if (key_len >= 14 && !strncmp (key, "add_black_list", 14)) { safe_read_in (&c->In, buf, size); buf[size] = 0; if (verbosity > 1) { fprintf (stderr, "add_black_list %s\n", buf); } int result = do_black_list_add (buf, size); RETURN(set, result); } if (key_len >= 17 && !strncmp (key, "delete_black_list", 17)) { safe_read_in (&c->In, buf, size); buf[size] = 0; if (verbosity > 1) { fprintf (stderr, "delete_black_list %s\n", buf); } int result = do_black_list_delete (buf, size); RETURN(set, result); } } RETURN(set, -2); }
int friends_check_query (int type, const char *key, int key_len) { int l = eat_at (key, key_len); key += l; key_len -= l; if (type == mct_get) { return (key_len >= 19 && (!strncmp (key, "common_friends_num", 18) || !strncmp (key, "%common_friends_num", 19))) || (key_len >= 15 && (!strncmp (key, "common_friends", 14) || !strncmp (key, "%common_friends", 15))); } else if (type == mct_set || type == mct_replace || type == mct_add) { return (key_len >= 8 && !strncmp (key, "userlist", 8)); } else { return 0; } }
int memcache_store (struct connection *c, int op, const char *old_key, int old_key_len, int flags, int delay, int size) { cmd_set++; double cmd_time = -mytime(); if (verbosity > 1) { fprintf (stderr, "memcache_store: key='%s', key_len=%d, value_len=%d\n", old_key, old_key_len, size); } dl_log_add (LOG_HISTORY, 1, "memcache_store: key='%s', key_len=%d, value_len=%d\n", old_key, old_key_len, size); sprintf (query, "key='%s', value_len=%d", old_key, size); if (size + 1 < MAX_VALUE_LEN) { char *key; int key_len; eat_at (old_key, old_key_len, &key, &key_len); if (key_len >= 5 && !strncmp (key, "queue", 5)) { int add = 0, x, y; if (sscanf(key + 5, "%d,%d%n", &x, &y, &add) != 2) { x = y = add = 0; } if (key[key_len - 1] != ')' || key[5 + add] != '(' || (key_len - 6 >= STATS_BUFF_SIZE)) { QRETURN(set, -2); } safe_read_in (&c->In, buf, size); buf[size] = 0; int len = key_len - 7 - add; memcpy (stats_buff, key + 6 + add, len); stats_buff[len] = 0; if (!do_add_event (stats_buff, len, buf, size, x, y, TTL_EVENT)) { QRETURN(set, 0) } QRETURN(set, 1); }
int memcache_get (struct connection *c, const char *old_key, int old_key_len) { INIT; if (verbosity > 1) { fprintf (stderr, "memcache_get: key='%s', key_len=%d\n", old_key, old_key_len); } char *key; int key_len; eat_at (old_key, old_key_len, &key, &key_len); int mode = 0, st = 0; if (key_len >= 5 && !strncmp (key, "hints", 5)) { mode = 1; st = 5; } #ifdef TYPES if (key_len >= 5 && !strncmp (key, "types", 5)) { mode = 2; st = 5; } if (key_len >= 11 && !strncmp (key, "hints_debug", 11)) { mode = 3; st = 11; } #endif if (mode) { if (key[st] != '(' || key[key_len - 1] != ')') { RETURN(get, 0); } int len = key_len - st - 2; memcpy (buf, key + st + 1, sizeof (char) * len); buf[len] = 0; if (verbosity >= 2) { fprintf (stderr, "run get_hints (%s, %d)\n", buf, mode); } get_hints (buf, mode, MAX_VALUE_LEN); return_one_key (c, old_key, buf, strlen (buf)); if (verbosity > 0) { if (mytime() + cmd_time > 0.005) { fprintf (stderr, "Warning!!! Search query (%s) was %lf seconds.\n", key, mytime() + cmd_time); } } RETURN(get, 0); } if (key_len >= 10 && !strncmp (key, "suggestion", 10)) { if (key[10] != '(' || key[key_len - 1] != ')') { RETURN(get, 0); } int len = key_len - 12; memcpy (buf, key + 11, sizeof (char) * len); buf[len] = 0; if (verbosity >= 2) { fprintf (stderr, "run get_suggestion (%s)\n", buf); } get_suggestion (buf, MAX_VALUE_LEN); return_one_key (c, old_key, buf, strlen (buf)); if (verbosity > 0) { if (mytime() + cmd_time > 0.005) { fprintf (stderr, "Warning!!! Search query (%s) was %lf seconds.\n", key, mytime() + cmd_time); } } RETURN(get, 0); } if (key_len >= 5 && !strncmp (key, "stats", 5)) { int len = isearch_prepare_stats (); int len2 = prepare_stats (c, stats_buff + len, STATS_BUFF_SIZE - len); return_one_key (c, old_key, stats_buff, len + len2 - 1); return 0; } if (key_len >= 3 && !strncmp (key, "top", 3)) { int cnt; if (sscanf (key, "top%d", &cnt) == 1) { get_top (buf, cnt, MAX_VALUE_LEN); return_one_key (c, old_key, buf, strlen (buf)); } RETURN(get, 0); } if (key_len >= 4 && !strncmp (key, "best", 4)) { int cnt; if (sscanf (key, "best%d", &cnt) == 1) { get_best (buf, cnt, MAX_VALUE_LEN); return_one_key (c, old_key, buf, strlen (buf)); } RETURN(get, 0); } if (key_len >= 10 && !strncmp (key, "black_list", 10)) { if (key_len >= 16 && !strncmp (key, "black_list_force", 16)) { black_list_force(); } else { char *s = black_list_get(); int len = strlen (s); return_one_key (c, old_key, s, len); } RETURN(get, 0); } RETURN(get, 0); }
int friends_check_query (int type, const char *key, int key_len) { int l = eat_at (key, key_len); key += l; key_len -= l; if (type == mct_get) { return (key_len