aboutsummaryrefslogtreecommitdiffstats
path: root/common/package.go
blob: 4e8780c08a64669ea58959930bc759df30dad728 (plain) (blame)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package common

import (
    "archive/zip"
    "encoding/json"
    "fmt"
    "io"
    "io/ioutil"
    "strings"
)

// Manifest object
//
// The manifest object holds all the relevant information supplied with the
// the manifest specified in the package
type Manifest struct {
    Entry         string
    Height, Width int
}

// External package
//
// External package contains the main html file and manifest
type ExtPackage struct {
    EntryHtml string
    Manifest  *Manifest
}

// Read file
//
// Read a given compressed file and returns the read bytes.
// Returns an error otherwise
func ReadFile(f *zip.File) ([]byte, error) {
    rc, err := f.Open()
    if err != nil {
        return nil, err
    }
    defer rc.Close()

    content, err := ioutil.ReadAll(rc)
    if err != nil {
        return nil, err
    }

    return content, nil
}

// Reads manifest
//
// Reads and returns a manifest object. Returns error otherwise
func ReadManifest(m []byte) (*Manifest, error) {
    var manifest Manifest

    dec := json.NewDecoder(strings.NewReader(string(m)))
    if err := dec.Decode(&manifest); err == io.EOF {
    } else if err != nil {
        return nil, err
    }

    return &manifest, nil
}

// Find file in archive
//
// Returns the index of the given file name if it exists. -1 if file not found
func FindFileInArchive(fn string, files []*zip.File) (index int) {
    index = -1
    // Find the manifest first
    for i, f := range files {
        if f.Name == fn {
            index = i
        }
    }

    return
}

// Open package
//
// Opens a prepared ethereum package
// Reads the manifest file and determines file contents and returns and
// the external package.
func OpenPackage(fn string) (*ExtPackage, error) {
    r, err := zip.OpenReader(fn)
    if err != nil {
        return nil, err
    }
    defer r.Close()

    manifestIndex := FindFileInArchive("manifest.json", r.File)

    if manifestIndex < 0 {
        return nil, fmt.Errorf("No manifest file found in archive")
    }

    f, err := ReadFile(r.File[manifestIndex])
    if err != nil {
        return nil, err
    }

    manifest, err := ReadManifest(f)
    if err != nil {
        return nil, err
    }

    if manifest.Entry == "" {
        return nil, fmt.Errorf("Entry file specified but appears to be empty: %s", manifest.Entry)
    }

    entryIndex := FindFileInArchive(manifest.Entry, r.File)
    if entryIndex < 0 {
        return nil, fmt.Errorf("Entry file not found: '%s'", manifest.Entry)
    }

    f, err = ReadFile(r.File[entryIndex])
    if err != nil {
        return nil, err
    }

    extPackage := &ExtPackage{string(f), manifest}

    return extPackage, nil
}
-301-0/+1 * Remove expired ports:rene2015-03-281-1/+0 * net/malo-firmware-kmod: NEW PORT - Marvell Libertas 88W8335 firmwarerobak2014-11-281-0/+1 * Update games/jfsw to 20131019martymac2014-11-251-1/+1 * Make LEGAL and RESTRICTED in Makefile for games/linux-ut match.scf2014-11-041-1/+1 * Welcome unifi4 to the ports tree.feld2014-10-311-0/+1 * Remove www/squid32 and 4 ports dependent on www/squid (v2.7)marino2014-09-161-1/+0 * 2014-08-31 databases/kinterbasdb: Not staged. See http://lists.freebsd.org/pi...antoine2014-09-071-3/+0 * Remove non staged ports without pending PR from wwwbapt2014-09-021-1/+0 * Remove non staged ports without pending PR from s*bapt2014-09-021-6/+0 * - Re-add archivers/bzip entryak2014-09-021-1/+1 * Add the current SUSv4/Open Group Base Specifications Issue 7.mandree2014-09-021-0/+1 * Remove non staged ports without pending PR from ma*bapt2014-09-021-2/+0 * - Update the homepage to the community website as the official one isscf2014-09-021-0/+1 * Remove non staged ports without pending PR from l*bapt2014-09-021-2/+0 * Remove non staged ports without pending PR from j*bapt2014-09-021-2/+0 * Remove non staged ports without pending PR from g*bapt2014-09-021-5/+0 * Remove non staged ports without pending PR from d*bapt2014-09-011-2/+0 * Remove non staged ports without pending PR from d*bapt2014-09-011-1/+0 * Remove non staged ports without pending PR from c*bapt2014-09-011-2/+0 * Remove LEGAL entry about biology/blastbapt2014-09-011-1/+0 * sysutils/arcconf: Updatepi2014-08-201-1/+1 * 2014-08-20 deskutils/horde3-hermes: EOL in April 2012antoine2014-08-201-2/+0 * Remove net/rsmb, MOVED entry was already added on 2014-08-13antoine2014-08-201-1/+0 * New port: sysutils/sas2ircupi2014-08-191-0/+1 * LEGAL: add entry for databases/linux-oracle-instantclient-sqlplusrene2014-07-231-0/+1 * LEGAL: add entry for databases/linux-oracle-instantclient-basicrene2014-07-231-0/+1 * - Update to latest upstream release 1.7.1riggs2014-07-171-1/+0 * Add LEGAL entry for net-p2p/btsynclwhsu2014-06-301-0/+1 * - Correct gmsh-occ entry.stephen2014-06-221-1/+1 * - Add cad/gmsh and cad/gmsh-occ ports.stephen2014-06-221-0/+2 * - Update LEGAL for some perforce portsantoine2014-06-141-0/+5 * LEGAL: Add stardict-longmaneadler2014-06-121-0/+1 * Use the wordings of RESTRICTED.jkim2014-06-121-3/+3 * Belatedly add LEGAL entries for java/jdk*-doc.jkim2014-06-121-0/+3 * - Update to 8.07.14 (and make fetchable again)antoine2014-06-011-1/+1 * Fix LEGAL/LICENSE* for multimedia/vtkmpeg2encode.riggs2014-06-011-1/+0 * LEGAL: fix multiple portseadler2014-05-261-1/+1 * Very minor update to /usr/ports/LEGAL to resolve discrepancy with make -VLEGAL.cs2014-05-191-1/+1 * LEGAL: update for stuffiteadler2014-05-171-1/+1 * LEGAL: fix multiple portseadler2014-05-171-2/+2 * LEGAL: fix multiple portseadler2014-05-171-5/+5 * Sync text of LEGAL and RESTRICTED for x11-fonts/sharefonts.olgeni2014-05-111-1/+1 * Remove expired ports:rene2014-05-111-2/+0 * Sync text of LEGAL and RESTRICTED for x11-fonts/freefonts.olgeni2014-05-111-1/+1 * Remove entry for sysutils/condor, it is no longer requires registration/manua...ak2014-05-071-1/+0 * Remove expired ports:rene2014-05-041-1/+0 * Remove expired ports:rene2014-04-111-2/+0 * Removed Long ago EOLed portbapt2014-04-101-1/+0 * Add Elasticsearch Marvel management plugin.tj2014-04-041-0/+1 * - Remove RESTRICTED.bdrewery2014-04-031-2/+2 * Remove expired ports:rene2014-04-021-4/+0 * The Oracle Java 8 JDK/JRE for Linux.jkim2014-04-011-0/+2 * Drop maintainership and fix LEGAL.ale2014-03-311-1/+1 * Remove expired port:rene2014-03-311-1/+0 * Remove expired ports:rene2014-03-251-1/+0 * libamr(n|w)briggs2014-03-151-2/+2 * - Update RESTRICTED comment for graphics/libecwj2amdmi32014-03-151-1/+1 * multimedia/linux-huludesktop: remove dead porteadler2014-03-151-1/+0 * Remove expired ports:rene2014-03-141-1/+0 * . support STAGE;bsam2014-03-131-1/+1 * Update LEGAL for thundercacheeadler2014-03-131-1/+1 * - Fix devel/raknet's distname within LEGAL filemartymac2014-03-121-1/+1 * LEGAL: fix yed legal texteadler2014-03-121-1/+1 * net/dgd-lpmud: fix LEGAL restrictionseadler2014-03-121-1/+1 * Remove expired ports:rene2014-03-101-2/+0 * LEGAL: fix kzip legal texteadler2014-03-101-1/+1 * LEGAL: fix lang/xds* portseadler2014-03-101-2/+2 * - Make case sensitive to match the output of "make -VLEGAL"tota2014-03-081-1/+1 * Remove expired ports with no active website:rene2014-03-081-1/+0 * - update LEGAL to match NO_CDROM in news/nntpcacheleeym2014-03-081-1/+1 * Mark RESTRICTED, according to EULA in the distfile, distribution is not allowedantoine2014-03-071-0/+1 * LEGAL: fix directoryeadler2014-03-031-1/+1 * Make LEGAL text match ports' RESTRICTED text in their Makefilesfeld2014-03-031-2/+2 * Fix text for www/dansguardiangarga2014-03-031-1/+1 * Fix the reason for french/homard.thierry2014-03-031-1/+1 * Sync legal with port and .src copyright.cy2014-03-031-2/+2 * Sync (and improve) the NO_PACKAGE and IGNORE statements and the entrygerald2014-03-031-1/+1 * LEGAL: make text match porteadler2014-02-231-12/+12 * Remove expired port:nemysis2014-02-191-1/+0 * Cosmetic fixes, update the pkg-descr WWWfeld2014-02-181-0/+1 * emulators/fmsx:rene2014-01-311-1/+1 * - Update to 6.8.0tota2014-01-191-1/+1 * - Fix build on recent FreeBSD (10, 11)martymac2014-01-131-0/+1 * Welcome net-mgmt/unifi2 to the treefeld2014-01-041-0/+1 * Add CONFLICTS for incoming net-mgmt/unifi2feld2014-01-041-1/+1 * Remove entry for mplayer, it is no longer restrictedarved2014-01-031-1/+0 * sync with make -VLEGALnetchild2013-12-241-1/+1 * Remove expired ports:rene2013-12-221-2/+0 * multiple: sync legaleadler2013-12-131-4/+4 * Update distname for games/flightgear-mb339-panmartymac2013-12-121-1/+1 * math/emc2: modernize porteadler2013-12-121-1/+1 * multiple: sync LEGAL and 'make -VLEGAL'eadler2013-12-121-2/+2 * multiple: sync LEGAL and 'make -VLEGAL'eadler2013-12-121-3/+3 * LEGAL: sync LEGAL texteadler2013-12-121-1/+1 * - update LEGALdinoex2013-12-121-4/+3 * - Sync legal texts for my portsmva2013-12-121-7/+15 * LEGAL, chinese/moettf: sync LEGAL texteadler2013-12-121-1/+1 * LEGAL, sysutils/arcconf: canconicalize LEGAL texteadler2013-12-121-1/+1 * LEGAL: remove security/pgpdumpeadler2013-12-121-1/+0 * - Capitalize multimedia/vdr-plugin-markad RESTRICTED.nox2013-12-121-0/+1 * Fix typo.ehaupt2013-12-121-1/+1 * - Update f-prot entry to match the output of "make -VLEGAL"tdb2013-12-111-1/+1 * LEGAL: split emulators/fuse-roms into twoeadler2013-12-111-1/+2 * - Make 'make -VLEGAL' match the entry in LEGAL andrene2013-12-111-1/+1 * LEGAL: add games/kye to LEGALeadler2013-12-111-0/+1 * LEGAL: remove security/pam_authsrveadler2013-12-111-1/+0 * Preparing for new port net-mgmt/unififeld2013-11-261-0/+1 * Remove expired ports:rene2013-11-151-1/+0 * Add Opus-22.rom for emulators/fuse-romsrene2013-11-131-1/+1 * This port installs some extra ZX spectrum ROM images which have beenrene2013-11-131-0/+1 * No public distfiles available anymore, pkgname conflict with sysutils/trackerbapt2013-10-021-1/+0 * Remove expired ports:rene2013-08-281-2/+0 * Add new port print/hplip-plugin:makc2013-07-141-0/+1 * Remove net/urtwn-firmware-kmod, integrated to head/ as of r253139.gjb2013-07-131-1/+0 * Remove expired port:rene2013-07-071-1/+0 * Change comment for uzap. Distributing the source is OK (has beenjoerg2013-06-181-1/+1 * - Add new port: net/urtwn-firmware-kmod:gjb2013-06-081-0/+1 * Restore the LEGAL statement about ventrilo-serverbapt2013-06-061-0/+1 * fwtk has gonebapt2013-06-051-1/+0 * Remove expired ports:rene2013-06-031-1/+0 * - Finish removal of support for Linux 2.4 in bsd.linux-apps.mk andrene2013-05-301-1/+0 * I copied the text from the wrong open makefile :-\eadler2013-05-181-1/+1 * Add a new port with legal issues.eadler2013-05-181-0/+1 * qjail license resolved in r316638bdrewery2013-04-291-1/+0 * Add entry to LEGAL as RESTRICTED status was added in r314731eadler2013-03-281-0/+1 * No approval process was required in my testing.eadler2013-03-251-1/+0 * No approval process was required in my testing.eadler2013-03-251-1/+0 * The file 'COPYING' in the distfile seems to indicate that the line in LEGAL i...eadler2013-03-251-1/+1 * a license was added in r300998. Since there is now the option for AGPL no re...eadler2013-03-251-1/+0 * - A port which is restricted should must not hide this facteadler2013-03-251-1/+1 * Removed in r169678eadler2013-03-221-1/+0 * Remove as port is under the GPL (r255853)eadler2013-03-211-1/+0 * The only reference to the files being restricted is Makefile.icons.eadler2013-03-211-1/+0 * Expand globs. This makes some future work a lot easier.eadler2013-03-211-6/+16 * Add a few missing entrieseadler2013-03-211-0/+2 * - Remove fsharppgj2013-03-211-1/+0 * Removed entry from port Makefile in r267037.eadler2013-03-211-1/+0 * Removed entry from port Makefile in r46360.eadler2013-03-211-1/+0 * Remove non-existent WWWeadler2013-03-191-1/+0 * tkman is licensed under the "Artistic License"eadler2013-03-191-1/+0 * Per r301175 xteddy is GPL so remove entry from LEGALeadler2013-03-191-1/+0 * Removeeadler2013-03-191-1/+0 * french/gibi: IGNORE for more than 6 monthseadler2013-03-191-1/+0 * Per r306610eadler2013-03-181-1/+0 * According to r242466 the port is now GPL so remove this entry from LEGALeadler2013-03-181-1/+0 * This software is under the BSD license:eadler2013-03-181-1/+0 * This software is under the GPLeadler2013-03-181-1/+0 * Per r172016eadler2013-03-181-1/+0 * According to r142824 the port is now BSD so remove this entry from LEGALeadler2013-03-181-1/+0 * Sort by distname. This was kind of done before but clearly got out of wack.eadler2013-03-181-64/+64 * This port seems to be legally distributed based on the COPYING fileeadler2013-03-181-1/+0 * audio/faad:eadler2013-03-181-1/+0 * Remove dns/h2n: legally questionable and obsolete.eadler2013-03-181-1/+0 * According to r160671 the port is not restricted any longereadler2013-03-181-1/+0 * According to r123287 the port is now GPLed so remove this entry from LEGALeadler2013-03-181-1/+0 * add an additional missing porteadler2013-03-181-0/+1 * acroread8 is also legally restrictedeadler2013-03-181-0/+1 * According to r206652 the port is now GPLed so remove this entry from LEGALeadler2013-03-181-1/+0 * According to r249857 the port is now GPLed so remove this entry from LEGALeadler2013-03-181-2/+0 * IDEA was no longer covered by any patents conservatively in 2012.eadler2013-03-171-1/+0 * x11-fonts appears not to exist.eadler2013-03-171-2/+0 * Make LEGAL machine parsableeadler2013-03-171-378/+168 * Remove expired, unmaintained ports:rene2013-03-141-4/+0 * 2013-03-13 misc/gopod: does not work with modern iPods anymorebapt2013-03-131-2/+0 * Remove expired, unmaintained ports:rene2013-03-061-4/+0 * Add entry for science/fvcommakc2013-02-211-0/+1 * 2012-05-10 databases/hypertable: BROKEN for more than 6 monthbapt2013-01-061-1/+0 * 2013-01-04 ports-mgmt/portmanager: Does not support modern ports features suc...bapt2013-01-061-1/+0 * Decommissioning java 1.5 (EOLed since October 2009):bapt2012-12-111-14/+0 * 2012-11-27 java/jmp: Java 1.5 is EOLedbapt2012-11-281-3/+0 * 2012-11-27 devel/p5-SPOPS: Depend on the expired p5-Class-Fieldsbapt2012-11-281-1/+0 * 2012-11-09 x11-fonts/tolkien-ttf: Does not fetch: there are no more public di...bapt2012-11-111-3/+0 * It seems that the file dgguspat.zip is the one which was legally restricted, buteadler2012-10-291-1/+0 * Remove now useless legal notice about gogobapt2012-10-261-1/+0 * 2012-10-20 chinese/wangttf: No more public distfilesbapt2012-10-261-2/+0 * 2012-10-20 games/yace: No more public distfilesbapt2012-10-261-1/+0 * 2012-10-20 lang/ironpython: No more public distfilesbapt2012-10-261-2/+0 * Remove ports which no longer exist.eadler2012-10-221-11/+2 * Add new port games/speakinghangmanjhale2012-09-221-0/+1 * Remove expired port:ak2012-08-221-2/+0 * - Remove entry of chinese/CNS11643-fontlwhsu2012-08-051-2/+0 * 2012-05-31 deskutils/sciplore-mindmapping: Discontinued, use deskutils/docear...bapt2012-06-131-2/+0 * Remove sysutils/linux-megacli; there is a native port at sysutils/megacli.crees2012-06-071-1/+0 * Race for the Galaxy AI is a GTK-based version of the card game of themadpilot2012-05-261-0/+1