contrib/community_profiles: cleanup and reorder widget options in augsburg profile
[project/luci.git] / contrib / lar / lar.h
1 /*
2 * lar - Lua Archive Library
3 *
4 * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19
20 #ifndef __LAR_H
21 #define __LAR_H
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <stdint.h>
27 #include <fcntl.h>
28 #include <string.h>
29 #include <errno.h>
30 #include <arpa/inet.h>
31 #include <sys/types.h>
32 #include <sys/mman.h>
33 #include <sys/stat.h>
34
35 #include "md5.h"
36
37 #define LAR_DIE(s) \
38 do { \
39 fprintf(stderr, "%s(%i): %s(): %s\n", \
40 __FILE__, __LINE__, __FUNCTION__, s); \
41 if( errno ) fprintf(stderr, "%s(%i): %s\n", \
42 __FILE__, __LINE__, strerror(errno) ); \
43 exit(1); \
44 } while(0)
45
46
47 #define LAR_FNAME_BUFFER 1024
48 #define LAR_FNAME(s) char s[LAR_FNAME_BUFFER]
49
50 #define LAR_TYPE_REGULAR 0x0000
51 #define LAR_TYPE_FILELIST 0xFFFF
52
53 #ifdef __WIN32__
54 #define LAR_DIRSEP '\\'
55 #else
56 #define LAR_DIRSEP '/'
57 #endif
58
59
60 struct lar_index_item {
61 uint32_t offset;
62 uint32_t length;
63 uint16_t type;
64 uint16_t flags;
65 char id[16];
66 char *filename;
67 struct lar_index_item *next;
68 };
69
70 struct lar_member_item {
71 uint16_t type;
72 uint16_t flags;
73 uint32_t length;
74 char *data;
75 char *mmap;
76 size_t mlen;
77 };
78
79 struct lar_archive_handle {
80 int fd;
81 int has_filenames;
82 off_t length;
83 char filename[LAR_FNAME_BUFFER];
84 struct lar_index_item *index;
85 };
86
87 typedef struct lar_index_item lar_index;
88 typedef struct lar_member_item lar_member;
89 typedef struct lar_archive_handle lar_archive;
90
91
92 lar_index * lar_get_index( lar_archive *ar );
93
94 lar_member * lar_mmap_member( lar_archive *ar, lar_index *idx_ptr );
95
96 lar_member * lar_open_member( lar_archive *ar, const char *name );
97
98 int lar_close_member( lar_member *member );
99
100 lar_archive * lar_open( const char *filename );
101
102 int lar_close( lar_archive *ar );
103
104 lar_archive * lar_find_archive( const char *package, const char *path, int pkg);
105
106 lar_member * lar_find_member( lar_archive *ar, const char *package );
107
108 #endif