Skip to content

Commit

Permalink
move photo_put() into photo.c, move send() into cgi.c as cgi_send()
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.kfish.org/fastphoto/trunk@135 9c49b5d1-7df3-0310-bce2-b7278e68f44c
  • Loading branch information
conrad committed Feb 15, 2006
1 parent 9dc5c92 commit 811985e
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 135 deletions.
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AM_CFLAGS = $(EPEG_CFLAGS)

bin_PROGRAMS = fastphoto

noinst_HEADERS = alloc_snprintf.h cache.h cgi.h header.h resize.h send.h
noinst_HEADERS = alloc_snprintf.h cache.h cgi.h header.h photo.h resize.h

fastphoto_SOURCES = main.c alloc_snprintf.c cache.c cgi.c header.c resize.c send.c
fastphoto_SOURCES = main.c alloc_snprintf.c cache.c cgi.c header.c photo.c resize.c
fastphoto_LDADD = $(EPEG_LIBS)
26 changes: 3 additions & 23 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <unistd.h>

#include "fastphoto.h"
#include "photo.h"
#include "alloc_snprintf.h"

#define PATH_SEP '/'
Expand Down Expand Up @@ -43,37 +44,16 @@ mkdirs (char * path)
return active;
}

int
file_check (photo_t * photo)
{
struct stat statbuf;

if (stat (photo->name, &statbuf) == -1) {
switch (errno) {
case ENOENT:
return 0;
default:
fprintf (stderr, "fastphoto: Error checking %s: %s\n", photo->name, strerror (errno));
return -1;
}
}

photo->mtime = statbuf.st_mtime;
photo->size = statbuf.st_size;

return 1;
}

static int
cache_check (fastphoto_t * params)
{
int ret;

if ((ret = file_check (&params->out)) != 1) {
if ((ret = photo_stat (&params->out)) != 1) {
return ret;
}

if ((ret = file_check (&params->in)) != 1) {
if ((ret = photo_stat (&params->in)) != 1) {
return ret;
}

Expand Down
3 changes: 0 additions & 3 deletions src/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ int cache_init (fastphoto_t * params, char * path_info);
int memory_init (fastphoto_t * params);
int memory_send (fastphoto_t * params);

int file_check (photo_t * photo);


#endif /* __CACHE_H__ */
30 changes: 26 additions & 4 deletions src/cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

#include "fastphoto.h"
#include "cache.h"

#define CONTENT_TYPE_JPEG "Content-Type: image/jpeg\n"

#define BUFSIZE 4096
#include "header.h"
#include "photo.h"

static void
set_param (fastphoto_t * params, char * key, char * val)
Expand Down Expand Up @@ -105,3 +103,27 @@ cgi_init (fastphoto_t * params)

return 1;
}

size_t
send_memory (fastphoto_t * params)
{
size_t n = fwrite (params->data, 1, params->data_size, stdout);
fflush (stdout);
return n;
}

int
cgi_send (fastphoto_t * params)
{
header_content_length (params->out.size);
header_end();

if (params->out.name) {
photo_put (&params->out);
} else {
fprintf (stderr, "fastphoto: Sending from memory ...\n");
send_memory (params);
}

return 1;
}
2 changes: 2 additions & 0 deletions src/cgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
int cgi_init (fastphoto_t * params);
int cgi_send (fastphoto_t * params);

size_t send_memory (fastphoto_t * params);

#endif /* __CGI_H__ */
3 changes: 1 addition & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "cgi.h"
#include "header.h"
#include "resize.h"
#include "send.h"

static void
version (void)
Expand Down Expand Up @@ -172,7 +171,7 @@ main (int argc, char * argv[])

if (!err) {
if (cgi) {
send (&params);
cgi_send (&params);
} else if (!params.out.name) {
send_memory (&params);
}
Expand Down
4 changes: 2 additions & 2 deletions src/resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <Epeg.h>

#include "fastphoto.h"
#include "cache.h" /* file_check() */
#include "photo.h"

int
resize (fastphoto_t * params)
Expand Down Expand Up @@ -58,7 +58,7 @@ resize (fastphoto_t * params)
epeg_close(im);

if (params->out.name)
file_check (&params->out);
photo_stat (&params->out);
else
params->out.size = (off_t)params->data_size;

Expand Down
92 changes: 0 additions & 92 deletions src/send.c

This file was deleted.

7 changes: 0 additions & 7 deletions src/send.h

This file was deleted.

0 comments on commit 811985e

Please sign in to comment.