/*
** Copyright (c) 2002 D. Richard Hipp
**
** 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; either
** version 2 of the License, or (at your option) any later version.
**
** 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 library; if not, write to the
** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
** Boston, MA 02111-1307, USA.
**
** Author contact information:
** drh@hwaci.com
** http://www.hwaci.com/drh/
**
*******************************************************************************
**
** Code for handling attachments
*/
#include "config.h"
#include "attach.h"
#include Error: %h Existing attachments: There are currently no attachments on this document. To add a new attachment \n"
"select the file to attach below an press the \"Add Attachment\" button.\n"
"Attachments may not be larger than %dKB.Ticket #%d: %h
\n",tn,zTitle);
}
if( attachment_html(zPage, "
\n"
"\n"
"Formatting Hints:
\n",mxSize/1024,zPage);
append_formatting_hints();
common_footer();
}
static int output_attachment_callback(
int *nGot, /* Set if we got results */
int nArg, /* Number of columns in this result row */
char **azArg, /* Text of data in all columns */
char **azName /* Names of the columns */
){
if( nArg != 4 ) return 0;
(*nGot) ++;
cgi_set_content_type(azArg[1]);
cgi_modified_since(atoi(azArg[3]));
cgi_append_header(
mprintf("Last-Modified: %s\r\n",cgi_rfc822_datestamp(atoi(azArg[3]))));
cgi_append_content(azArg[2], atoi(azArg[0]));
g.isConst = 1;
return 0;
}
void attachment_output(int atn){
/*
** We need to use a callback here since the content is a BLOB type object
** and the usual db_query() won't handle NUL characters in a returned
** row. The callback has the full row buffer available and will handle
** all the output duties. got will be set if we get a row.
*/
int got = 0;
db_callback_query( output_attachment_callback, &got,
"SELECT size, mime, content, date "
"FROM attachment "
"WHERE atn=%d", atn);
if( !got ){
common_err("No such attachment: %d", atn);
}
}
/*
** WEBPAGE: /attach_get
**
** Retrieve an attachment. g.zExtra looks something like "90/file.gif", which
** the atoi() call turns into just the integer "90". The filename is ignored,
** although some browsers use it as an initial name when saving to disk.
*/
void attachment_get(void){
int atn = g.zExtra ? atoi(g.zExtra) : 0;
char *z;
login_check_credentials();
throttle(1,0);
if( atn==0 ) common_err("No attachment specified");
z = db_short_query("SELECT tn FROM attachment WHERE atn=%d", atn);
if( z && z[0] ){
if( is_integer(z) ){
if( !g.okRead ){ login_needed(); return; }
}else{
if( !g.okRdWiki ){ login_needed(); return; }
}
attachment_output(atn);
}else{
common_err("No attachment specified");
}
}
/*
** Return true if it is ok to delete an attachment created by zUser
** at time addTime. Rules:
**
** * The Setup user can delete any attachment no matter who added
** it or how old it is.
**
** * Any registered user can delete an attachment that they
** themselves created less than 24 hours ago.
**
** * Users with Delete privilege can delete an attachment added
** by anonymous within the past 24 hours.
**
*/
int ok_to_delete_attachment(int addTime, const char *zUser){
if( g.okSetup ){
return 1;
}
if( addTime
\n" "%h %h bytes added by %h on %h UTC.\n",az[5],az[1],az[3],zDate); if(az[6] && az[6][0]){ cgi_printf("\n" "\n" "\n",atn); common_footer(); } /* ** This routine generates HTML that shows a list of attachments for ** the given ticket number or wiki page. If there are no attachments, ** nothing is generated. Return the number of attachments. */ int attachment_html(const char *zPage, const char *zBefore, const char *zAfter){ char **az; int i = 0; time_t now; if( is_integer(zPage) ){ if( !g.okRead ) return 0; }else{ if( !g.okRdWiki ) return 0; } az = db_query("SELECT atn, size, date, user, mime, fname, description " "FROM attachment WHERE tn='%q' ORDER BY date", zPage); time(&now); if( az[0] ){ cgi_printf("%s\n" "
\n"); output_formatted(az[6], NULL); cgi_printf("
\n"); } cgi_printf("