download_file_downloader (public)

 download_file_downloader

Defined in packages/download/tcl/download-procs.tcl

Sends the requested file to the user. Note that the path has the original file name, so the browser will have a sensible name if you save the file. Version downloads are supported by looking for the form variable version_id. We don't actually check that the version_id matches the path, we just serve it up.

Partial Call Graph (max 5 caller/called nodes):
%3 ad_conn ad_conn (public) ad_job ad_job (public) ad_page_contract ad_page_contract (public) ad_returnredirect ad_returnredirect (public) ad_script_abort ad_script_abort (public) download_file_downloader download_file_downloader download_file_downloader->ad_conn download_file_downloader->ad_job download_file_downloader->ad_page_contract download_file_downloader->ad_returnredirect download_file_downloader->ad_script_abort

Testcases:
No testcase defined.
Source code:
    ad_page_contract {
    } {
        { revision_id:naturalnum "" }
        { download_id:naturalnum "" }
        { reason_id "" }
        { reason_other ""}
    }

    ns_log Debug "download_file_downloader: downloading $revision_id"

    set user_id [ad_conn user_id]
    set download_ip [ad_conn peeraddr]
    if [catch {
        set download_hostname [ad_job -timeout 0:500000 ns_hostbyaddr $download_ip]
    }] {
        set download_hostname ""
    }
    set user_agent  [ns_set iget [ad_conn headers] user-agent]

    regexp "[ad_conn package_url]download/(.*)" [ad_conn url] match path

    if {$revision_id eq ""} {
        set file_name [ad_conn path_info]
        set revision_id [lindex [db_list get_revision_id {
            select revision_id from download_arch_revisions_obj
            where file_name=:file_name
            and approved_p = 't'
            order by revision_id desc}] 0]
    }
    if {$revision_id eq ""} {
        ad_returnredirect [ad_conn package_url]
        ad_script_abort
    }

    permission::require_permission -object_id $revision_id -privilege "read"

    ##Record the download for all time!!
    set double_click_p [db_string download_count "select count(*) from download_downloads where download_id = :download_id"]
    if { $double_click_p == 0 } {
        if {[catch {
            db_dml download_insert {
                insert into download_downloads (
                                                download_id,
                                                user_id,
                                                revision_id,
                                                download_date,
                                                download_ip,
                                                download_hostname,
                                                user_agent,
                                                reason_id,
                                                reason)
                values
                (:download_id,
                 :user_id,
                 :revision_id,
                 sysdate,
                 :download_ip,
                 :download_hostname,
                 :user_agent,
                 :reason_id,
                 :reason_other)
            }
        } errmsg]} {
            ns_log Error "Download: Unable to log download due to an error: $errmsg"
        }
    }

    cr_write_content -revision_id $revision_id

    return filter_return
Generic XQL file:
<fullquery name="download_file_downloader.download_count">
    <querytext>

select count(*) from download_downloads 
where download_id = :download_id

</querytext>
</fullquery>
packages/download/tcl/download-procs.xql

PostgreSQL XQL file:
<fullquery name="download_file_downloader.download_insert">
    <querytext>

insert into download_downloads (
  download_id, 
  user_id, 
  revision_id, 
  download_date, 
  download_ip,
  download_hostname,
  user_agent,
  reason_id,
  reason)
values (
  :download_id, 
  :user_id, 
  :revision_id, 
  current_timestamp, 
  :download_ip,
  :download_hostname,
  :user_agent,
  :reason_id,
  :reason_other)
            
</querytext>
</fullquery>
packages/download/tcl/download-procs-postgresql.xql

Oracle XQL file:
<fullquery name="download_file_downloader.download_insert">
    <querytext>
      
                insert into download_downloads (
                download_id, 
                user_id, 
                revision_id, 
                download_date, 
                download_ip,
                download_hostname,
                user_agent,
                reason_id,
                reason)
                values
                (:download_id, 
                :user_id, 
                :revision_id, 
                sysdate, 
                :download_ip,
                :download_hostname,
                :user_agent,
                :reason_id,
                :reason_other)
            
      </querytext>
</fullquery>
packages/download/tcl/download-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: