money.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pi-macros.h"
#include "pi-money.h"

Include dependency graph for money.c:

Go to the source code of this file.

Functions

int unpack_Transaction (Transaction_t *trans, unsigned char *buffer, size_t len)
int pack_Transaction (struct Transaction *trans, unsigned char *buffer, size_t len)
int unpack_MoneyAppInfo (MoneyAppInfo_t *appinfo, unsigned char *buffer, size_t len)
int pack_MoneyAppInfo (MoneyAppInfo_t *appinfo, unsigned char *buffer, size_t len)


Function Documentation

int pack_MoneyAppInfo ( MoneyAppInfo_t appinfo,
unsigned char *  buffer,
size_t  len 
)

Definition at line 232 of file money.c.

References MoneyAppInfo::category, pack_CategoryAppInfo(), MoneyAppInfo::tranLabels, and MoneyAppInfo::typeLabels.

00233 {
00234         int     i,
00235                 j;
00236         unsigned char *p;
00237 
00238         i = pack_CategoryAppInfo(&appinfo->category, buffer, len);
00239 
00240         if (!buffer)
00241                 return i + 603;
00242         if (!i)
00243                 return i;
00244 
00245         p = (unsigned char *) (buffer + i);
00246         len -= i;
00247         if (i < 603)
00248                 return 0;
00249 
00250         for (j = 0; j < 20; j++) {
00251                 memcpy(p, appinfo->typeLabels[j], 10);
00252                 p += 10;
00253         }
00254 
00255         for (j = 0; j < 20; j++) {
00256                 memcpy(p, appinfo->tranLabels[j], 20);
00257                 p += 20;
00258         }
00259 
00260         return (i + 603);
00261 }

Here is the call graph for this function:

int pack_Transaction ( struct Transaction trans,
unsigned char *  buffer,
size_t  len 
)

Definition at line 112 of file money.c.

References Transaction::amount, Transaction::amountc, Transaction::checknum, Transaction::day, Transaction::description, Transaction::flags, Transaction::flags2, Transaction::hour, Transaction::minute, Transaction::month, Transaction::note, Transaction::repeat, Transaction::second, set_byte, set_short, set_slong, set_sshort, Transaction::total, Transaction::totalc, Transaction::type, Transaction::wday, Transaction::xfer, and Transaction::year.

00114 {
00115         size_t  destlen = 46 + strlen(trans->note) + 1;
00116         unsigned char *p;
00117 
00118         if (!buffer)
00119                 return destlen;
00120         if (len < destlen)
00121                 return 0;
00122 
00123         p = buffer;
00124         set_byte(p, trans->flags);
00125         p += 1;
00126         set_byte(p, 0);
00127         p += 1;                 /* gap fill */
00128         set_short(p, trans->checknum);
00129         p += 2;
00130         set_slong(p, trans->amount);
00131         p += 4;
00132         set_slong(p, trans->total);
00133         p += 4;
00134         set_sshort(p, trans->amountc);
00135         p += 2;
00136         set_sshort(p, trans->totalc);
00137         p += 2;
00138 
00139         set_sshort(p, trans->second);
00140         p += 2;
00141         set_sshort(p, trans->minute);
00142         p += 2;
00143         set_sshort(p, trans->hour);
00144         p += 2;
00145         set_sshort(p, trans->day);
00146         p += 2;
00147         set_sshort(p, trans->month);
00148         p += 2;
00149         set_sshort(p, trans->year);
00150         p += 2;
00151         set_sshort(p, trans->wday);
00152         p += 2;
00153 
00154         set_byte(p, trans->repeat);
00155         p += 1;
00156         set_byte(p, trans->flags2);
00157         p += 1;
00158         set_byte(p, trans->type);
00159         p += 1;
00160 
00161         /* gap fill */
00162         set_short(p, 0);
00163         p += 2;
00164 
00165         set_byte(p, trans->xfer);
00166         p += 1;
00167 
00168         strcpy((char *)p, trans->description);
00169         p += 19;
00170         strcpy((char *)p, trans->note);
00171         p += strlen((char *)p) + 1;
00172 
00173         return (p - buffer);
00174 }

int unpack_MoneyAppInfo ( MoneyAppInfo_t appinfo,
unsigned char *  buffer,
size_t  len 
)

Definition at line 189 of file money.c.

References MoneyAppInfo::category, MoneyAppInfo::tranLabels, MoneyAppInfo::typeLabels, and unpack_CategoryAppInfo().

00190 {
00191         int     i,
00192                 j;
00193 
00194         unsigned char *p;
00195 
00196         i = unpack_CategoryAppInfo(&appinfo->category, buffer, len);
00197         if (!i)
00198                 return 0;
00199 
00200         p = (unsigned char *) (buffer + i);
00201 
00202         len -= i;
00203         if (len < 603)
00204                 return 0;
00205 
00206         for (j = 0; j < 20; j++) {
00207                 memcpy(appinfo->typeLabels[j], p, 10);
00208                 p += 10;
00209         }
00210 
00211         for (j = 0; j < 20; j++) {
00212                 memcpy(appinfo->tranLabels[j], p, 20);
00213                 p += 20;
00214         }
00215 
00216         return i + 603;
00217 }

Here is the call graph for this function:

int unpack_Transaction ( Transaction_t trans,
unsigned char *  buffer,
size_t  len 
)

Definition at line 42 of file money.c.

References Transaction::amount, Transaction::amountc, Transaction::checknum, Transaction::day, Transaction::description, Transaction::flags, Transaction::flags2, get_byte, get_short, get_slong, get_sshort, Transaction::hour, Transaction::minute, Transaction::month, Transaction::note, Transaction::repeat, Transaction::reserved, Transaction::second, Transaction::total, Transaction::totalc, Transaction::type, Transaction::wday, Transaction::xfer, and Transaction::year.

00043 {
00044 
00045         unsigned char *p;
00046 
00047         if (len < 46)
00048                 return 0;
00049 
00050         p = buffer;
00051         trans->flags    = get_byte(p);
00052         p += 2;                 /* gap */
00053         trans->checknum         = get_short(p);
00054         p += 2;
00055         trans->amount   = get_slong(p);
00056         p += 4;
00057         trans->total    = get_slong(p);
00058         p += 4;
00059         trans->amountc  = get_sshort(p);
00060         p += 2;
00061         trans->totalc   = get_sshort(p);
00062         p += 2;
00063 
00064         trans->second   = get_sshort(p);
00065         p += 2;
00066         trans->minute   = get_sshort(p);
00067         p += 2;
00068         trans->hour     = get_sshort(p);
00069         p += 2;
00070         trans->day              = get_sshort(p);
00071         p += 2;
00072         trans->month    = get_sshort(p);
00073         p += 2;
00074         trans->year     = get_sshort(p);
00075         p += 2;
00076         trans->wday     = get_sshort(p);
00077         p += 2;
00078 
00079         trans->repeat   = get_byte(p);
00080         p += 1;
00081         trans->flags2   = get_byte(p);
00082         p += 1;
00083         trans->type     = get_byte(p);
00084         p += 1;
00085 
00086         memcpy(trans->reserved, p, 2);
00087         p += 2;
00088 
00089         trans->xfer = get_byte(p);
00090         p += 1;
00091 
00092         strcpy(trans->description, (char *)p);
00093         p += 19;
00094         strcpy(trans->note, (char *)p);
00095         p += strlen((char *)p) + 1;
00096 
00097         return (p - buffer);
00098 }


© 1996-2007 by pilot-link.org. All rights reserved.