00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026
00027 #include "pi-hinote.h"
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 void
00041 free_HiNoteNote(HiNoteNote_t *hinote)
00042 {
00043 if (hinote->text != NULL) {
00044 free(hinote->text);
00045 hinote->text = NULL;
00046 }
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 int
00061 unpack_HiNoteNote(HiNoteNote_t *hinote, unsigned char *buffer, int len)
00062 {
00063 if (len < 3)
00064 return 0;
00065
00066 hinote->flags = buffer[0];
00067 hinote->level = buffer[1];
00068 hinote->text = strdup((char *) &buffer[2]);
00069
00070 return strlen((char *) &buffer[2]) + 3;
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 int
00085 pack_HiNoteNote(HiNoteNote_t *hinote, unsigned char *buffer, int len)
00086 {
00087 int destlen;
00088
00089 destlen = 3;
00090 if (hinote->text)
00091 destlen += strlen(hinote->text);
00092
00093 if (!buffer)
00094 return destlen;
00095 if (len < destlen)
00096 return 0;
00097
00098 buffer[0] = hinote->flags;
00099 buffer[1] = hinote->level;
00100
00101 if (hinote->text)
00102 strcpy((char *) &buffer[2], hinote->text);
00103 else {
00104 buffer[2] = 0;
00105 }
00106 return destlen;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 int
00122 unpack_HiNoteAppInfo(HiNoteAppInfo_t *appinfo, unsigned char *record, size_t len)
00123 {
00124 int i,
00125 idx;
00126 unsigned char *start;
00127
00128 start = record;
00129 i = unpack_CategoryAppInfo(&appinfo->category, record, len);
00130 if (!i)
00131 return i;
00132 record += i;
00133 len -= i;
00134 if (len < 48)
00135 return 0;
00136 for (idx = 0; i < 48; i++)
00137 appinfo->reserved[i] = *record++;
00138 return (record - start);
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 int
00154 pack_HiNoteAppInfo(HiNoteAppInfo_t *appinfo, unsigned char *record, size_t len)
00155 {
00156 int i,
00157 idx;
00158 unsigned char *start = record;
00159
00160 i = pack_CategoryAppInfo(&appinfo->category, record, len);
00161 if (i == 0)
00162 return 0;
00163 if (!record)
00164 return i + 48;
00165 record += i;
00166 len -= i;
00167 if (len < 48)
00168 return (record - start);
00169 for (idx = 0; i < 48; i++)
00170 *record++ = appinfo->reserved[i];
00171
00172 return (record - start);
00173 }
00174
00175
00176
00177
00178
00179
00180