summaryrefslogtreecommitdiffstats
path: root/lurker/render/keyword.cpp
blob: 8339469604851c324b6395a6f82a8a987a28defc (plain)
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
100
101
102
103
104
105
106
107
108
/*  $Id: keyword.cpp 1649 2009-10-19 14:35:01Z terpstra $
 *  
 *  jump.cpp - Jump to a given date offset
 *  
 *  Copyright (C) 2002 - Wesley W. Terpstra
 *  
 *  License: GPL
 *  
 *  Authors: 'Wesley W. Terpstra' <wesley@terpstra.ca>
 *  
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; version 2.
 *    
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *    
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#define _FILE_OFFSET_BITS 64

#include <Keys.h>
#include "parse.h"

#include <set>
#include <vector>

#include <ctime>
#include <cstdlib>
#include <cstring>

using std::set;

vector<string> keys;
set<string> dups;

int push_key(const char* keyword, void* arg)
{
	if (dups.find(keyword) == dups.end())
	{
		dups.insert(keyword);
		keys.push_back(keyword);
	}
	
	return 0;
}

int main()
{
	map<string, string> args = getParams();
	
	struct tm tms;
	memset(&tms, 0, sizeof(tms));
	
	tms.tm_sec  = args.find("sec" ) != args.end() ? atol(args["sec" ].c_str()) : 0;
	tms.tm_min  = args.find("min" ) != args.end() ? atol(args["min" ].c_str()) : 0;
	tms.tm_hour = args.find("hour") != args.end() ? atol(args["hour"].c_str()) : 0;
	tms.tm_mday = args.find("mday") != args.end() ? atol(args["mday"].c_str()) : 1;
	tms.tm_mon  = args.find("mon" ) != args.end() ? atol(args["mon" ].c_str()) - 1 : 0;
	tms.tm_year = args.find("year") != args.end() ? atol(args["year"].c_str()) - 1900 : 138;
	
	time_t utc = atol(args["utc"].c_str());
	if (utc) tms = *gmtime(&utc);
	
	char buf[26];
	strftime(buf, 25, "%Y%m%d.%H%M%S", &tms);
	
	my_keyword_digest_string(
		args["subject"].c_str(), args["subject"].length(), 
		LU_KEYWORD_SUBJECT, &push_key, 0, 0);
	my_keyword_digest_string(
		args["author"].c_str(), args["author"].length(), 
		LU_KEYWORD_AUTHOR, &push_key, 0, 0);
	my_keyword_digest_string(
		args["query"].c_str(), args["query"].length(), 
		LU_KEYWORD_WORD, &push_key, 0, 0);
	my_keyword_digest_string(
		args["list"].c_str(), args["list"].length(), 
		LU_KEYWORD_LIST, &push_key, 0, 0);
	my_keyword_digest_string(
		args["group"].c_str(), args["group"].length(), 
		LU_KEYWORD_GROUP, &push_key, 0, 0);
	my_keyword_digest_string(
		args["lang"].c_str(), args["lang"].length(),
		LU_KEYWORD_LANGUAGE, &push_key, 0, 0);
	
	string url = args["doc-url"] + "/search/" + string(buf) + ".00000000@";
	vector<string>::iterator i;
	for (i = keys.begin(); i != keys.end(); ++i)
	{
		if (i != keys.begin()) url += ",";
		
		// Escape '/' to '!' in url to avoid path problems
		string::size_type x = 0;
		while ((x = i->find('/', x)) != string::npos)
			(*i)[x++] = '!';
		
		url += *i;
	}
	url += "." + args["format"];
	
	return redirectUrl(url);
}