00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 #include "udanax.h"
00081
00089 bool
00090 isinlinklist(
00091 typelinkset linkset,
00092 IStreamAddr *linkisaptr)
00093 {
00094 for (; linkset; linkset = linkset->next) {
00095 if (tumblereq(&linkset->address, linkisaptr))
00096 return true;
00097 }
00098 return false;
00099 }
00100
00108 static typelink *
00109 makelinkitem(
00110 Session *sess,
00111 IStreamAddr *linkisa)
00112 {
00113 #ifndef DISTRIBUTION
00114 footumbler("makelinkitem", linkisa);
00115 #endif
00116
00117 typelink *link = new(sess) typelink;
00118 movetumbler(linkisa, &link->address);
00119 link->itemid = LINKID;
00120 link->next = NULL;
00121 return link;
00122 }
00123
00131 void
00132 onlinklist(
00133 Session *sess,
00134 typelinkset *linksetptr,
00135 IStreamAddr *linkisaptr)
00136 {
00137 typelink *linkset, *temp, *nextlink;
00138
00139 linkset = makelinkitem(sess, linkisaptr);
00140
00141 if (*linksetptr == NULL) {
00142 *linksetptr = linkset;
00143 return;
00144 }
00145
00146 for (temp = *linksetptr; (nextlink = temp->next) != 0; temp = nextlink) {
00147 if (tumblereq(&temp->address, linkisaptr))
00148 return;
00149 }
00150
00151 temp->next = linkset;
00152 }
00153
00161 void
00162 intersectlinksets(
00163 Session *sess,
00164 typelinkset linkset1,
00165 typelinkset linkset2,
00166 typelinkset linkset3,
00167 typelinkset *linkset4ptr)
00168 {
00169 typelinkset linkset4;
00170 typelinkset temp1 = NULL;
00171 typelinkset temp2;
00172 typelinkset temp3;
00173 bool olddebug = debug;
00174
00175 #ifndef DISTRIBUTION
00176 if (debug) {
00177 L("\nINTERSECTLINKSETS\n");
00178 fooitemset("", (typeitem *) linkset1);
00179 fooitemset("", (typeitem *) linkset2);
00180 L("inter linkset1 = %x, linkset2 = %x, linkset3 = %x\n", (int) linkset1, (int) linkset2, (int) linkset3);
00181 }
00182 #endif
00183
00184
00185 if (linkset1 && !linkset2 && !linkset3)
00186 *linkset4ptr = linkset1;
00187 else if (!linkset1 && linkset2 && !linkset3)
00188 *linkset4ptr = linkset2;
00189 else if (!linkset1 && !linkset2 && linkset3)
00190 *linkset4ptr = linkset3;
00191 else
00192 *linkset4ptr = NULL;
00193
00194 if (*linkset4ptr) {
00195 #ifndef DISTRIBUTION
00196 if (debug) {
00197 L("*linkset4ptr = %x\n", (int) *linkset4ptr);
00198 }
00199 #endif
00200 debug = olddebug;
00201 return;
00202 }
00203
00204
00205
00206 if (linkset1)
00207 temp1 = linkset1;
00208 if (linkset1 && !linkset2 && linkset3) {
00209 linkset2 = linkset3;
00210 linkset3 = NULL;
00211 } else if (!linkset1 && linkset2 && linkset3) {
00212 temp1 = linkset3;
00213 linkset3 = NULL;
00214 }
00215
00216 #ifndef DISTRIBUTION
00217 if (debug) {
00218 L("temp1 = %x, linkset2 = %x, linkset3 = %x\n", (int) temp1, (int) linkset2, (int) linkset3);
00219 }
00220 #endif
00221
00222 if (!linkset3) {
00223 for (; temp1; temp1 = temp1->next) {
00224 for (temp2 = linkset2; temp2; temp2 = temp2->next) {
00225 if (tumblereq(&temp1->address, &temp2->address)) {
00226 linkset4 = makelinkitem(sess, &temp1->address);
00227 *linkset4ptr = linkset4;
00228 linkset4ptr = &linkset4->next;
00229 }
00230 }
00231 }
00232 } else {
00233 for (; temp1; temp1 = temp1->next) {
00234 for (temp2 = linkset2; temp2; temp2 = temp2->next) {
00235 for (temp3 = linkset3; temp3; temp3 = temp3->next) {
00236 if (tumblereq(&temp1->address, &temp2->address)
00237 && tumblereq(&temp2->address, &temp3->address)) {
00238 linkset4 = makelinkitem(sess, &temp1->address);
00239 *linkset4ptr = linkset4;
00240 linkset4ptr = &linkset4->next;
00241 }
00242 }
00243 }
00244 }
00245 }
00246 debug = olddebug;
00247 }