00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <stdlib.h>
00039 #include <stdio.h>
00040 #include <SUM.h>
00041 #include <sum_rpc.h>
00042
00043 #define MONE (long)-1
00044
00045
00046 PADATA *panext;
00047 PADATA *panextwd;
00048 PADATA *panextuid;
00049
00050 char *p_strdup (char *s)
00051 {
00052 char *duped;
00053
00054 if(!s) return NULL;
00055 duped = (char *)malloc(strlen(s)+1);
00056 strcpy(duped, s);
00057 return duped;
00058 }
00059
00060
00061 PADATA *getpadata(PADATA *list, char *wd, uint64_t sumid)
00062 {
00063 PADATA *walk = list;
00064
00065 while(walk) {
00066 if(walk->sumid != sumid)
00067 walk = walk->next;
00068 else {
00069 if(!(strcmp(walk->wd, wd)))
00070 return walk;
00071 else
00072 walk = walk->next;
00073 }
00074 }
00075 return walk;
00076 }
00077
00078
00079 PADATA *makepadata(char *wd, uint64_t sumid, double bytes, int stat, int substat, char *eff_date, int group_id, int safe_id, uint64_t ds_index)
00080 {
00081 PADATA *newone;
00082
00083 newone = (PADATA *)malloc(sizeof(PADATA));
00084 newone->next = NULL;
00085 newone->wd = p_strdup(wd);
00086 newone->sumid = sumid;
00087 newone->bytes = bytes;
00088 newone->status = stat;
00089 newone->archsub = substat;
00090 newone->effective_date = p_strdup(eff_date);
00091 newone->group_id = group_id;
00092 newone->safe_id = safe_id;
00093 newone->ds_index = ds_index;
00094 return(newone);
00095 }
00096
00097
00098 void setpadata(PADATA **list, char *wd, uint64_t sumid, double bytes, int stat, int substat, char *eff_date, int group_id, int safe_id, uint64_t ds_index)
00099 {
00100 PADATA *newone;
00101
00102 if(getpadata(*list, wd, sumid)) return;
00103 newone = makepadata(wd, sumid, bytes, stat, substat, eff_date, group_id, safe_id, ds_index);
00104 newone->next = *list;
00105 *list = newone;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114 void setpadatar(PADATA **list, char *wd, uint64_t sumid, double bytes, int stat, int substat, char *eff_date, int group_id, int safe_id, uint64_t ds_index)
00115 {
00116 PADATA *newone;
00117 PADATA *walk;
00118
00119 if(getpadata(*list, wd, sumid)) return;
00120 newone = makepadata(wd, sumid, bytes, stat, substat, eff_date, group_id, safe_id, ds_index);
00121 if(*list == NULL) {
00122 *list = newone;
00123 newone->next = NULL;
00124 }
00125 else {
00126 walk = *list;
00127 while(walk->next) {
00128 walk = walk->next;
00129 }
00130 walk->next = newone;
00131 }
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 void uidpadata(PADATA *pkt, PADATA **start, PADATA **end)
00145 {
00146 PADATA *old, *p, *addnew;
00147
00148 addnew = makepadata(pkt->wd, pkt->sumid, pkt->bytes, pkt->status, pkt->archsub,
00149 pkt->effective_date, pkt->group_id, pkt->safe_id, pkt->ds_index);
00150 p = *start;
00151 if(!*end) {
00152 addnew->next = NULL;
00153 *end = addnew;
00154 *start = addnew;
00155 return;
00156 }
00157 old = NULL;
00158 while(p) {
00159 if(p->sumid < addnew->sumid) {
00160 old = p;
00161 p = p->next;
00162 }
00163 else {
00164 if(old) {
00165 old->next = addnew;
00166 addnew->next = p;
00167 return;
00168 }
00169 addnew->next = p;
00170 *start = addnew;
00171 return;
00172 }
00173 }
00174 (*end)->next = addnew;
00175 addnew->next = NULL;
00176 *end = addnew;
00177 }
00178
00179
00180
00181
00182
00183
00184 void remuidpadata(PADATA **start, PADATA **end, char *wd, uint64_t sumid)
00185 {
00186 PADATA *walk = *start;
00187 PADATA *trail = NULL;
00188
00189 while(walk) {
00190 if(walk->sumid != sumid) {
00191 trail = walk;
00192 walk = walk->next;
00193 }
00194 else {
00195 if(!(strcmp(walk->wd, wd))) {
00196 if(trail) {
00197 trail->next = walk->next;
00198 if(trail->next == NULL) *end = trail;
00199 }
00200 else {
00201 *start = walk->next;
00202 if(*start == NULL) *end = NULL;
00203 }
00204 free(walk->wd);
00205 free(walk->effective_date);
00206 free(walk);
00207 walk = NULL;
00208 }
00209 else {
00210 trail = walk;
00211 walk = walk->next;
00212 }
00213 }
00214 }
00215 }
00216
00217
00218
00219
00220
00221 PADATA *getpawd(PADATA *list, char *wd)
00222 {
00223 PADATA *walk;
00224
00225 if(list != (PADATA *)MONE)
00226 panextwd = list;
00227 walk = panextwd;
00228 while(walk) {
00229 if(!(strcmp(walk->wd, wd))) {
00230 panextwd = walk->next;
00231 return walk;
00232 }
00233 else
00234 walk = walk->next;
00235 }
00236 return walk;
00237 }
00238
00239
00240
00241
00242 PADATA *getpauid(PADATA *list, uint64_t sumid)
00243 {
00244 PADATA *walk;
00245
00246 if(list != (PADATA *)MONE)
00247 panextuid = list;
00248 walk = panextuid;
00249 while(walk) {
00250 if(walk->sumid != sumid)
00251 walk = walk->next;
00252 else {
00253 panextuid = walk->next;
00254 return walk;
00255 }
00256 }
00257 return walk;
00258 }
00259
00260
00261
00262
00263 PADATA *getpanext(PADATA *list)
00264 {
00265 PADATA *walk;
00266
00267 if(list != (PADATA *)MONE) {
00268 panext = list;
00269 }
00270 if(walk=panext)
00271 panext = panext->next;
00272 return walk;
00273 }
00274
00275 void rempadata(PADATA **list, char *wd, uint64_t sumid)
00276 {
00277 PADATA *walk = *list;
00278 PADATA *trail = NULL;
00279
00280 while(walk) {
00281 if(walk->sumid != sumid) {
00282 trail = walk;
00283 walk = walk->next;
00284 }
00285 else {
00286 if(!(strcmp(walk->wd, wd))) {
00287 if(trail)
00288 trail->next = walk->next;
00289 else
00290 *list = walk->next;
00291
00292 if(panext == walk)
00293 panext = walk->next;
00294 if(panextwd == walk)
00295 panextwd = walk->next;
00296 if(panextuid == walk)
00297 panextuid = walk->next;
00298 free(walk->wd);
00299 free(walk->effective_date);
00300 free(walk);
00301 walk = NULL;
00302 }
00303 else {
00304 trail = walk;
00305 walk = walk->next;
00306 }
00307 }
00308 }
00309 }
00310
00311
00312 void updpadata (PADATA **list, char *wd, uint64_t sumid, char *eff_date)
00313 {
00314 PADATA *walk = *list;
00315
00316 while(walk) {
00317 if(walk->sumid != sumid) {
00318 walk = walk->next;
00319 }
00320 else {
00321 if(!(strcmp(walk->wd, wd))) {
00322 free(walk->effective_date);
00323 walk->effective_date = p_strdup(eff_date);
00324 }
00325 walk = walk->next;
00326 }
00327 }
00328 }