Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove old C server

  • Loading branch information...
commit d9c396921da98a4823682b3a5fea7680ffeabf03 1 parent a3e8236
@mapleoin authored
View
26 Makefile
@@ -1,26 +0,0 @@
-CC = gcc
-CFLAGS = -Wall
-LDFLAGS = -ltdb
-
-all: popcorn-server popcorn-dump
-
-popcorn-server: popcorn-server.o
- $(CC) $(LDFLAGS) $< -o $@
-
-popcorn-dump: popcorn-dump.o
- $(CC) $(LDFLAGS) $< -o $@
-
-example:
- ./popcorn-client > example.txt
-
-%.o: %.c
- $(CC) $(CFLAGS) -c $< -o $@
-
-clean:
- rm -f *.o popcorn-server popcorn-dump example.txt popcorn.tar.bz2
- rm -rf dist
-
-dist:
- mkdir dist
- tar --transform 's:^:popcorn/:' -j -c -f dist/popcorn.tar.bz2 [^d]*
- cp -a *spec dist
View
58 popcorn-dump.c
@@ -1,58 +0,0 @@
-/*
- Copyright (c) 2009 Pavol Rusnak <stick@gk2.sk>
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <stdio.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <tdb.h>
-
-#define STATSDIR "/var/cache/popcorn/"
-#define STATSFILE "stats.tdb"
-
-int cb(TDB_CONTEXT *db, TDB_DATA key, TDB_DATA val, void *dummy)
-{
- int i, *vals;
- printf("%.*s", (int)key.dsize, (char *)key.dptr);
- vals = (int *)val.dptr;
- for (i=0; i<val.dsize/sizeof(int); i++)
- printf(" %d", vals[i]);
- printf("\n");
- return 0;
-}
-
-int main()
-{
- TDB_CONTEXT *db;
-
- db = tdb_open(STATSDIR STATSFILE, 0, 0, O_RDONLY, 0644);
-
- if (!db) return 1;
-
- tdb_traverse(db, cb, NULL);
-
- tdb_close(db);
-
- return 0;
-}
View
31 popcorn-rotate
@@ -1,31 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2009 Pavol Rusnak <stick@gk2.sk>
-#
-# Permission is hereby granted, free of charge, to any person
-# obtaining a copy of this software and associated documentation
-# files (the "Software"), to deal in the Software without
-# restriction, including without limitation the rights to use,
-# copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the
-# Software is furnished to do so, subject to the following
-# conditions:
-#
-# The above copyright notice and this permission notice shall be
-# included in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-# OTHER DEALINGS IN THE SOFTWARE.
-
-STATSDIR='/var/cache/popcorn/'
-STATSFILE='stats.tdb'
-STATSFMT='+stats-%G-%V.tdb'
-
-# move current data to week-data
-mv -f $STATSDIR$STATSFILE $STATSDIR`date $STATSFMT`
View
148 popcorn-server.c
@@ -1,148 +0,0 @@
-/*
- Copyright (c) 2009 Pavol Rusnak <stick@gk2.sk>
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <tdb.h>
-
-#define STATSDIR "/var/cache/popcorn/"
-#define STATSFILE "stats.tdb"
-
-#define SILENT 0
-
-#define BUFSIZE 1024
-
-#define is_sane(c) ( ((c)>='A'&&(c)<='Z') || ((c)>='a'&&(c)<='z') || ((c)>='0'&&(c)<='9') || ((c)=='.') || ((c)=='-') || ((c)=='_') )
-
-typedef struct {
- unsigned int n; /* no-files */
- unsigned int r; /* recent */
- unsigned int v; /* voted */
- unsigned int o; /* old */
-} TUPLE;
-
-inline void sanitize(char *str)
-{
- char *c = str;
- while (*c) {
- if (!is_sane(*c)) {
- str[0]='\0';
- break;
- }
- ++c;
- }
- if (str[0]=='\0') strcpy(str,"unknown");
-}
-
-int main()
-{
- int l;
- unsigned int cnt;
- char buf[BUFSIZE], ver[BUFSIZE], arch[BUFSIZE], cat, *pkg, *c;
- TDB_CONTEXT *db;
- TDB_DATA key, val;
- TUPLE tuple;
-
- /* read from stdin until line starting with "POPCORN " comes */
- while (fgets(buf, BUFSIZE, stdin)) {
- if (!strncmp(buf, "POPCORN ", 8)) break;
- }
- /* if not present then exit */
- if (strncmp(buf, "POPCORN ", 8)) {
-#if !SILENT
- fprintf(stderr, "Popcorn header not found\n");
-#endif
- return 1;
- }
- /* read and sanitize version and architecture */
- sscanf(buf, "POPCORN %s %s", ver, arch);
- sanitize(ver);
- sanitize(arch);
-
- /* open database */
- db = tdb_open(STATSDIR STATSFILE, 0, 0, O_CREAT | O_RDWR, 0644);
- if ( !db ) {
-#if !SILENT
- fprintf(stderr, "Can't open database: %s\n", STATSDIR STATSFILE);
-#endif
- return 1;
- }
-
- // update architecture field
- key.dsize = strlen(arch) + 5;
- snprintf(buf, BUFSIZE, "arch/%s", arch);
- key.dptr = (unsigned char *)buf;
- val = tdb_fetch(db, key);
- cnt = val.dptr ? *((unsigned int *)val.dptr) + 1 : 1;
- val.dptr = (unsigned char *)&cnt;
- val.dsize = sizeof(cnt);
- tdb_store(db, key, val, TDB_REPLACE);
-
- // update version field
- key.dsize = strlen(ver) + 4;
- snprintf(buf, BUFSIZE, "ver/%s", ver);
- key.dptr = (unsigned char *)buf;
- val = tdb_fetch(db, key);
- cnt = val.dptr ? *((unsigned int *)val.dptr) + 1 : 1;
- val.dptr = (unsigned char *)&cnt;
- val.dsize = sizeof(cnt);
- tdb_store(db, key, val, TDB_REPLACE);
-
- // update packages
- while (fgets(buf, BUFSIZE, stdin)) {
- l = strlen(buf);
- if (l<3) continue;
- cat = buf[0];
- c = strpbrk(buf + 2, " \n\r\t");
- *c = '\0';
- pkg = buf + 2;
-
- key.dsize = strlen(pkg);
- key.dptr = (unsigned char *)pkg;
- val = tdb_fetch(db, key);
- if (!val.dptr) {
- tuple.n = 0;
- tuple.r = 0;
- tuple.v = 0;
- tuple.o = 0;
- } else {
- tuple = *((TUPLE *)val.dptr);
- }
- switch (cat) {
- case 'n': ++tuple.n; break;
- case 'r': ++tuple.r; break;
- case 'v': ++tuple.v; break;
- case 'o': ++tuple.o; break;
- }
- val.dptr = (unsigned char *)&tuple;
- val.dsize = sizeof(tuple);
- tdb_store(db, key, val, TDB_REPLACE);
- }
-
- tdb_close(db);
- return 0;
-}
View
11 popcorn.spec
@@ -7,7 +7,6 @@ Group: System/Packages
Summary: Popularity Contest (for RPM)
Source: %{name}.tar.bz2
BuildRoot: %{_tmppath}/%{name}-%{version}-build
-BuildRequires: libtdb-devel
Requires: rpm-python cron
%description
@@ -24,7 +23,6 @@ Popularity Contest (for RPM) - server
%setup -q -n %{name}
%build
-make
%install
# client
@@ -32,11 +30,6 @@ install -D -m 0755 popcorn-client $RPM_BUILD_ROOT%{_bindir}/popcorn
install -D -m 0644 popcorn.conf $RPM_BUILD_ROOT%{_sysconfdir}/popcorn.conf
install -D -m 0755 popcorn.cron $RPM_BUILD_ROOT%{_sysconfdir}/cron.weekly/popcorn
# server
-install -D -m 0755 popcorn-dump $RPM_BUILD_ROOT%{_bindir}/popcorn-dump
-install -D -m 0755 popcorn-rotate $RPM_BUILD_ROOT%{_bindir}/popcorn-rotate
-install -D -m 0755 popcorn-server $RPM_BUILD_ROOT%{_bindir}/popcorn-server
-mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/cache/popcorn
-# /srv/www/cgi-bin/
%clean
rm -rf $RPM_BUILD_ROOT
@@ -49,9 +42,5 @@ rm -rf $RPM_BUILD_ROOT
%files server
%defattr(-,root,root)
-%{_bindir}/popcorn-dump
-%{_bindir}/popcorn-rotate
-%{_bindir}/popcorn-server
-%{_localstatedir}/cache/popcorn
%changelog
Please sign in to comment.
Something went wrong with that request. Please try again.