#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pi-macros.h"
#include "pi-address.h"
Include dependency graph for address.c:

Go to the source code of this file.
Defines | |
| #define | hi(x) (((x) >> 4) & 0x0f) |
| #define | lo(x) ((x) & 0x0f) |
| #define | pair(x, y) (((x) << 4) | (y)) |
Functions | |
| void | free_Address (Address_t *addr) |
| int | unpack_Address (Address_t *addr, const pi_buffer_t *buf, addressType type) |
| int | pack_Address (const Address_t *addr, pi_buffer_t *buf, addressType type) |
| int | unpack_AddressAppInfo (AddressAppInfo_t *ai, const unsigned char *record, size_t len) |
| int | pack_AddressAppInfo (const AddressAppInfo_t *ai, unsigned char *record, size_t len) |
| #define hi | ( | x | ) | (((x) >> 4) & 0x0f) |
| #define lo | ( | x | ) | ((x) & 0x0f) |
| void free_Address | ( | Address_t * | addr | ) |
Definition at line 47 of file address.c.
References Address::entry.
Referenced by addresses(), and read_file().
00048 { 00049 int i; 00050 00051 for (i = 0; i < 19; i++) 00052 if (addr->entry[i]) { 00053 free(addr->entry[i]); 00054 addr->entry[i] = NULL; 00055 } 00056 }
| int pack_Address | ( | const Address_t * | addr, | |
| pi_buffer_t * | buf, | |||
| addressType | type | |||
| ) |
Definition at line 134 of file address.c.
References address_v1, buf, buffer, Address::entry, entryCompany, and pi_buffer_expect().
Referenced by addresses(), read_file(), and test_address().
00135 { 00136 unsigned int l, 00137 destlen = 9; 00138 00139 unsigned char *buffer; 00140 unsigned long contents, 00141 v, 00142 phoneflag; 00143 00144 unsigned char offset; 00145 00146 if (addr == NULL || buf == NULL) 00147 return -1; 00148 00149 if (type != address_v1) 00150 /* Don't support anything else yet */ 00151 return -1; 00152 00153 for (v = 0; v < 19; v++) 00154 if (addr->entry[v] && strlen(addr->entry[v])) 00155 destlen += strlen(addr->entry[v]) + 1; 00156 00157 pi_buffer_expect (buf, destlen); 00158 buf->used = destlen; 00159 00160 buffer = buf->data + 9; 00161 phoneflag = 0; 00162 contents = 0; 00163 offset = 0; 00164 00165 for (v = 0; v < 19; v++) { 00166 if (addr->entry[v] && strlen(addr->entry[v])) { 00167 if (v == entryCompany) 00168 offset = 00169 (unsigned char) (buffer - buf->data) - 8; 00170 contents |= (1 << v); 00171 l = strlen(addr->entry[v]) + 1; 00172 memcpy(buffer, addr->entry[v], l); 00173 buffer += l; 00174 } 00175 } 00176 00177 phoneflag = ((unsigned long) addr->phoneLabel[0]) << 0; 00178 phoneflag |= ((unsigned long) addr->phoneLabel[1]) << 4; 00179 phoneflag |= ((unsigned long) addr->phoneLabel[2]) << 8; 00180 phoneflag |= ((unsigned long) addr->phoneLabel[3]) << 12; 00181 phoneflag |= ((unsigned long) addr->phoneLabel[4]) << 16; 00182 phoneflag |= ((unsigned long) addr->showPhone) << 20; 00183 00184 set_long(buf->data, phoneflag); 00185 set_long(buf->data + 4, contents); 00186 set_byte(buf->data + 8, offset); 00187 00188 return 0; 00189 }
Here is the call graph for this function:

| int pack_AddressAppInfo | ( | const AddressAppInfo_t * | ai, | |
| unsigned char * | record, | |||
| size_t | len | |||
| ) |
Definition at line 263 of file address.c.
References AddressAppInfo::category, AddressAppInfo::country, AddressAppInfo::labelRenamed, AddressAppInfo::labels, pack_CategoryAppInfo(), AddressAppInfo::phoneLabels, set_byte, set_long, set_short, and AddressAppInfo::sortByCompany.
Referenced by test_address().
00264 { 00265 int i; 00266 size_t destlen = 4 + 16 * 22 + 2 + 2; 00267 unsigned char *pos = record; 00268 unsigned long r; 00269 00270 i = pack_CategoryAppInfo(&ai->category, record, len); 00271 if (!record) 00272 return destlen + i; 00273 if (!i) 00274 return i; 00275 00276 pos += i; 00277 len -= i; 00278 00279 for (i = 3; i < 8; i++) 00280 strcpy(ai->phoneLabels[i - 3], ai->labels[i]); 00281 for (i = 19; i < 22; i++) 00282 strcpy(ai->phoneLabels[i - 19 + 5], ai->labels[i]); 00283 00284 memset(pos, 0, destlen); 00285 00286 r = 0; 00287 for (i = 0; i < 22; i++) 00288 if (ai->labelRenamed[i]) 00289 r |= (1 << i); 00290 set_long(pos, r); 00291 pos += 4; 00292 00293 memcpy(pos, ai->labels, 16 * 22); 00294 pos += 16 * 22; 00295 set_short(pos, ai->country); 00296 pos += 2; 00297 set_byte(pos, ai->sortByCompany); 00298 pos += 2; 00299 00300 for (i = 3; i < 8; i++) 00301 strcpy(ai->phoneLabels[i - 3], ai->labels[i]); 00302 for (i = 19; i < 22; i++) 00303 strcpy(ai->phoneLabels[i - 19 + 5], ai->labels[i]); 00304 00305 return (pos - record); 00306 }
Here is the call graph for this function:

| int unpack_Address | ( | Address_t * | addr, | |
| const pi_buffer_t * | buf, | |||
| addressType | type | |||
| ) |
Definition at line 72 of file address.c.
References address_v1, buf, Address::entry, get_byte, get_long, hi, lo, Address::phoneLabel, Address::showPhone, and strdup().
Referenced by addresses(), test_address(), and write_file().
00073 { 00074 unsigned long contents, 00075 v; 00076 size_t ofs; 00077 00078 if (type != address_v1) 00079 /* Don't support anything else yet */ 00080 return -1; 00081 00082 if (buf == NULL || buf->data == NULL || buf->used < 9) 00083 return -1; 00084 00085 /* get_byte(buffer); gapfill */ 00086 addr->showPhone = hi(get_byte(buf->data + 1)); 00087 addr->phoneLabel[4] = lo(get_byte(buf->data + 1)); 00088 addr->phoneLabel[3] = hi(get_byte(buf->data + 2)); 00089 addr->phoneLabel[2] = lo(get_byte(buf->data + 2)); 00090 addr->phoneLabel[1] = hi(get_byte(buf->data + 3)); 00091 addr->phoneLabel[0] = lo(get_byte(buf->data + 3)); 00092 00093 contents = get_long(buf->data + 4); 00094 00095 /* get_byte(buf->data+8) offset */ 00096 00097 ofs = 9; 00098 00099 /* if(flag & 0x1) { 00100 addr->lastname = strdup((buf->data + ofs); 00101 ofs += strlen((buf->data + ofs)) + 1; 00102 } else { 00103 addr->lastname = 0; 00104 } */ 00105 00106 for (v = 0; v < 19; v++) { 00107 if (contents & (1 << v)) { 00108 if ((buf->used - ofs) < 1) 00109 return 0; 00110 addr->entry[v] = strdup((char *) (buf->data + ofs)); 00111 ofs += strlen(addr->entry[v]) + 1; 00112 } else { 00113 addr->entry[v] = 0; 00114 } 00115 } 00116 00117 return 0; 00118 }
Here is the call graph for this function:

| int unpack_AddressAppInfo | ( | AddressAppInfo_t * | ai, | |
| const unsigned char * | record, | |||
| size_t | len | |||
| ) |
Definition at line 207 of file address.c.
References address_v1, AddressAppInfo::category, AddressAppInfo::country, get_byte, get_long, get_short, AddressAppInfo::labelRenamed, AddressAppInfo::labels, AddressAppInfo::phoneLabels, AddressAppInfo::sortByCompany, AddressAppInfo::type, and unpack_CategoryAppInfo().
Referenced by main(), and test_address().
00208 { 00209 size_t i, 00210 destlen = 4 + 16 * 22 + 2 + 2; 00211 00212 unsigned char *start = record; 00213 unsigned long r; 00214 00215 ai->type = address_v1; 00216 00217 i = unpack_CategoryAppInfo(&ai->category, record, len); 00218 if (!record) 00219 return i + destlen; 00220 if (!i) 00221 return i; 00222 record += i; 00223 len -= i; 00224 00225 if (len < destlen) 00226 return 0; 00227 00228 r = get_long(record); 00229 for (i = 0; i < 22; i++) 00230 ai->labelRenamed[i] = !!(r & (1 << i)); 00231 00232 record += 4; 00233 memcpy(ai->labels, record, 16 * 22); 00234 record += 16 * 22; 00235 ai->country = get_short(record); 00236 record += 2; 00237 ai->sortByCompany = get_byte(record); 00238 record += 2; 00239 00240 for (i = 3; i < 8; i++) 00241 strcpy(ai->phoneLabels[i - 3], ai->labels[i]); 00242 for (i = 19; i < 22; i++) 00243 strcpy(ai->phoneLabels[i - 19 + 5], ai->labels[i]); 00244 00245 return (record - start); 00246 }
Here is the call graph for this function:
