void trim_token(t_info *info) { int x; int y; y = -1; while (++y < info->token.y) { x = 0; while (x < info->token.x) { if (info->token.map[y][x] == '*') { if (x < info->token.tok_x) info->token.tok_x = x; if (y < info->token.tok_y) info->token.tok_y = y; if (x > info->token.tok_x_b) info->token.tok_x_b = x; if (y > info->token.tok_y_b) info->token.tok_y_b = y; } x++; } } if (info->token.tok_x || info->token.tok_y) gen_new_token(info); }
char * seaf_web_at_manager_get_access_token (SeafWebAccessTokenManager *mgr, const char *repo_id, const char *obj_id, const char *op, const char *username) { GString *key = g_string_new (NULL); AccessToken *token; AccessInfo *info; long now = (long)time(NULL); long expire; char *t; g_string_printf (key, "%s %s %s %s", repo_id, obj_id, op, username); token = g_hash_table_lookup (mgr->access_info_hash, key->str); /* To avoid returning an almost expired token, we returns token * that has at least 1 minute "life time". */ if (!token || token->expire_time - now <= 60) { t = gen_new_token (mgr->access_token_hash); expire = now + TOKEN_EXPIRE_TIME; token = g_new0 (AccessToken, 1); memcpy (token->token, t, TOKEN_LEN); token->expire_time = expire; g_hash_table_insert (mgr->access_info_hash, g_strdup(key->str), token); info = g_new0 (AccessInfo, 1); info->repo_id = g_strdup (repo_id); info->obj_id = g_strdup (obj_id); info->op = g_strdup (op); info->username = g_strdup (username); info->expire_time = expire; g_hash_table_insert (mgr->access_token_hash, g_strdup(t), info); g_free (t); } g_string_free (key, TRUE); return g_strdup(token->token); }