00001
00002
00003
00004
00005 #ifndef windows_platform
00006
00007 #ifdef USE_BOOST
00008 #else
00009
00010 #endif
00011
00012 #include <sys/types.h>
00013 #include <sys/wait.h>
00014 #endif
00015 #include "objMetaOpr.h"
00016 #include "resource.h"
00017 #include "collection.h"
00018 #include "specColl.h"
00019 #if 0
00020 #include "modDataObjMeta.h"
00021 #include "ruleExecSubmit.h"
00022 #include "ruleExecDel.h"
00023 #include "reSysDataObjOpr.h"
00024 #endif
00025 #include "genQuery.h"
00026 #include "icatHighLevelRoutines.h"
00027 #include "miscUtil.h"
00028 #include "rodsClient.h"
00029 #include "rsIcatOpr.h"
00030
00031
00032 int
00033 svrCloseQueryOut (rsComm_t *rsComm, genQueryOut_t *genQueryOut)
00034 {
00035 genQueryInp_t genQueryInp;
00036 genQueryOut_t *junk = NULL;
00037 int status;
00038
00039 if (genQueryOut->continueInx <= 0) {
00040 return (0);
00041 }
00042
00043 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00044
00045
00046 genQueryInp.maxRows = 0;;
00047 genQueryInp.continueInx = genQueryOut->continueInx;
00048
00049 status = rsGenQuery (rsComm, &genQueryInp, &junk);
00050
00051 return (status);
00052 }
00053
00054 int
00055 isData (rsComm_t *rsComm, char *objName, rodsLong_t *dataId)
00056 {
00057 genQueryInp_t genQueryInp;
00058 genQueryOut_t *genQueryOut = NULL;
00059 char tmpStr[MAX_NAME_LEN];
00060 char logicalEndName[MAX_NAME_LEN];
00061 char logicalParentDirName[MAX_NAME_LEN];
00062 int status;
00063
00064 status = splitPathByKey(objName,
00065 logicalParentDirName, logicalEndName, '/');
00066 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00067 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName);
00068 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr);
00069 addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1);
00070 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName);
00071 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr);
00072 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00073 genQueryInp.maxRows = 2;
00074 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00075 if (status >= 0) {
00076 sqlResult_t *dataIdRes;
00077
00078 if ((dataIdRes = getSqlResultByInx (genQueryOut, COL_D_DATA_ID)) ==
00079 NULL) {
00080 rodsLog (LOG_ERROR,
00081 "isData: getSqlResultByInx for COL_D_DATA_ID failed");
00082 return (UNMATCHED_KEY_OR_INDEX);
00083 }
00084 if (dataId != NULL) {
00085 *dataId = strtoll (dataIdRes->value, 0, 0);
00086 }
00087 freeGenQueryOut (&genQueryOut);
00088 }
00089
00090 clearGenQueryInp (&genQueryInp);
00091 return(status);
00092 }
00093
00094 int
00095 getPhyPath (rsComm_t *rsComm, char *objName, char *resource, char *phyPath)
00096 {
00097 genQueryInp_t genQueryInp;
00098 genQueryOut_t *genQueryOut = NULL;
00099 char tmpStr[MAX_NAME_LEN];
00100 char logicalEndName[MAX_NAME_LEN];
00101 char logicalParentDirName[MAX_NAME_LEN];
00102 int status;
00103
00104 status = splitPathByKey(objName,
00105 logicalParentDirName, logicalEndName, '/');
00106 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00107 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalEndName);
00108 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, tmpStr);
00109 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", logicalParentDirName);
00110 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr);
00111 addInxIval (&genQueryInp.selectInp, COL_D_DATA_PATH, 1);
00112 genQueryInp.maxRows = 2;
00113 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00114 if (status >= 0) {
00115 sqlResult_t *phyPathRes = NULL;
00116 if ((phyPathRes = getSqlResultByInx (genQueryOut, COL_D_DATA_PATH)) ==
00117 NULL) {
00118 rodsLog (LOG_ERROR,
00119 "getPhyPath: getSqlResultByInx for COL_D_DATA_PATH failed");
00120 return (UNMATCHED_KEY_OR_INDEX);
00121 }
00122 if (phyPath != NULL) {
00123 rstrcpy (phyPath, phyPathRes->value, MAX_NAME_LEN);
00124 }
00125 freeGenQueryOut (&genQueryOut);
00126 }
00127 clearGenQueryInp (&genQueryInp);
00128 return(status);
00129 }
00130
00131 int
00132 isCollAllKinds (rsComm_t *rsComm, char *objName, rodsLong_t *collId)
00133 {
00134 dataObjInp_t dataObjInp;
00135 int status;
00136 rodsObjStat_t *rodsObjStatOut = NULL;
00137
00138 bzero (&dataObjInp, sizeof (dataObjInp));
00139 rstrcpy (dataObjInp.objPath, objName, MAX_NAME_LEN);
00140 status = collStatAllKinds (rsComm, &dataObjInp, &rodsObjStatOut);
00141 if (status >= 0 && collId != NULL && NULL != rodsObjStatOut) {
00142 *collId = strtoll (rodsObjStatOut->dataId, 0, 0);
00143 }
00144 if (rodsObjStatOut != NULL)
00145 freeRodsObjStat (rodsObjStatOut);
00146 return status;
00147 }
00148
00149 int
00150 isColl (rsComm_t *rsComm, char *objName, rodsLong_t *collId)
00151 {
00152 genQueryInp_t genQueryInp;
00153 genQueryOut_t *genQueryOut = NULL;
00154 char tmpStr[MAX_NAME_LEN];
00155 int status;
00156
00157 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00158 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", objName);
00159 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, tmpStr);
00160 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00161 genQueryInp.maxRows = 2;
00162 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00163 if (status >= 0) {
00164 sqlResult_t *collIdRes;
00165
00166 if ((collIdRes = getSqlResultByInx (genQueryOut, COL_COLL_ID)) ==
00167 NULL) {
00168 rodsLog (LOG_ERROR,
00169 "isColl: getSqlResultByInx for COL_D_DATA_ID failed");
00170 return (UNMATCHED_KEY_OR_INDEX);
00171 }
00172
00173 if (collId != NULL) {
00174 *collId = strtoll (collIdRes->value, 0, 0);
00175 }
00176 freeGenQueryOut (&genQueryOut);
00177 }
00178
00179 clearGenQueryInp (&genQueryInp);
00180 return(status);
00181 }
00182
00183 int
00184 isUser(rsComm_t *rsComm, char *objName)
00185 {
00186 genQueryInp_t genQueryInp;
00187 genQueryOut_t *genQueryOut = NULL;
00188 char tmpStr[NAME_LEN];
00189 int status;
00190
00191 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00192 snprintf (tmpStr, NAME_LEN, "='%s'", objName);
00193 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, tmpStr);
00194 addInxIval (&genQueryInp.selectInp, COL_USER_ID, 1);
00195 genQueryInp.maxRows = 2;
00196 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00197 freeGenQueryOut (&genQueryOut);
00198 clearGenQueryInp (&genQueryInp);
00199 return(status);
00200 }
00201
00202 int
00203 isResc (rsComm_t *rsComm, char *objName)
00204 {
00205 genQueryInp_t genQueryInp;
00206 genQueryOut_t *genQueryOut = NULL;
00207 char tmpStr[NAME_LEN];
00208 int status;
00209
00210 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00211 snprintf (tmpStr, NAME_LEN, "='%s'", objName);
00212 addInxVal (&genQueryInp.sqlCondInp, COL_R_RESC_NAME, tmpStr);
00213 addInxIval (&genQueryInp.selectInp, COL_R_RESC_ID, 1);
00214 genQueryInp.maxRows = 2;
00215 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00216 freeGenQueryOut (&genQueryOut);
00217 clearGenQueryInp (&genQueryInp);
00218 return(status);
00219 }
00220
00221 int
00222 isRescGroup (rsComm_t *rsComm, char *objName)
00223 {
00224 genQueryInp_t genQueryInp;
00225 genQueryOut_t *genQueryOut = NULL;
00226 char tmpStr[NAME_LEN];
00227 int status;
00228
00229 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00230 snprintf (tmpStr, NAME_LEN, "='%s'", objName);
00231 addInxVal (&genQueryInp.sqlCondInp, COL_RESC_GROUP_NAME, tmpStr);
00232 addInxIval (&genQueryInp.selectInp, COL_RESC_GROUP_ID, 1);
00233 genQueryInp.maxRows = 2;
00234 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00235 freeGenQueryOut (&genQueryOut);
00236 clearGenQueryInp (&genQueryInp);
00237 return(status);
00238 }
00239
00240 int
00241 isMeta(rsComm_t *rsComm, char *objName)
00242 {
00243
00244 return(INVALID_OBJECT_TYPE);
00245 }
00246
00247 int
00248 isToken(rsComm_t *rsComm, char *objName)
00249 {
00250
00251 return(INVALID_OBJECT_TYPE);
00252 }
00253
00254 int
00255 getObjType(rsComm_t *rsComm, char *objName, char * objType)
00256 {
00257 if (isData(rsComm, objName, NULL) >= 0)
00258 strcpy(objType,"-d");
00259 else if (isColl(rsComm, objName, NULL) >= 0)
00260 strcpy(objType,"-c");
00261 else if (isResc(rsComm, objName) == 0)
00262 strcpy(objType,"-r");
00263 else if (isRescGroup(rsComm, objName) == 0)
00264 strcpy(objType,"-g");
00265 else if (isUser(rsComm, objName) == 0)
00266 strcpy(objType,"-u");
00267 else if (isMeta(rsComm, objName) == 0)
00268 strcpy(objType,"-m");
00269 else if (isToken(rsComm, objName) == 0)
00270 strcpy(objType,"-t");
00271 else
00272 return(INVALID_OBJECT_TYPE);
00273 return (0);
00274 }
00275
00276 int
00277 addAVUMetadataFromKVPairs (rsComm_t *rsComm, char *objName, char *inObjType,
00278 keyValPair_t *kVP)
00279 {
00280 int i,j;
00281 char objType[10];
00282 modAVUMetadataInp_t modAVUMetadataInp;
00283
00284 bzero (&modAVUMetadataInp, sizeof (modAVUMetadataInp));
00285 if (strcmp(inObjType,"-1")) {
00286 strcpy(objType,inObjType);
00287 }
00288 else {
00289 i = getObjType(rsComm, objName,objType);
00290 if (i < 0)
00291 return(i);
00292 }
00293
00294 modAVUMetadataInp.arg0 = "add";
00295 for (i = 0; i < kVP->len ; i++) {
00296
00297
00298
00299
00300 modAVUMetadataInp.arg1 = objType;
00301 modAVUMetadataInp.arg2 = objName;
00302 modAVUMetadataInp.arg3 = kVP->keyWord[i];
00303 modAVUMetadataInp.arg4 = kVP->value[i];
00304 modAVUMetadataInp.arg5 = "";
00305 j = rsModAVUMetadata (rsComm, &modAVUMetadataInp);
00306 if (j < 0)
00307 return(j);
00308 }
00309 return(0);
00310 }
00311
00312
00313 int
00314 setAVUMetadataFromKVPairs (rsComm_t *rsComm, char *objName, char *inObjType,
00315 keyValPair_t *kVP)
00316 {
00317 int i,j;
00318 char objType[10];
00319 modAVUMetadataInp_t modAVUMetadataInp;
00320
00321 bzero (&modAVUMetadataInp, sizeof(modAVUMetadataInp));
00322 if (strcmp(inObjType, "-1")) {
00323 strcpy(objType, inObjType);
00324 }
00325 else {
00326 i = getObjType(rsComm, objName, objType);
00327 if (i < 0)
00328 return(i);
00329 }
00330 for (i = 0; i < kVP->len ; i++) {
00331
00332
00333
00334
00335 modAVUMetadataInp.arg0 = "set";
00336 modAVUMetadataInp.arg1 = objType;
00337 modAVUMetadataInp.arg2 = objName;
00338 modAVUMetadataInp.arg3 = kVP->keyWord[i];
00339 modAVUMetadataInp.arg4 = kVP->value[i];
00340 modAVUMetadataInp.arg5 = NULL;
00341 j = rsModAVUMetadata (rsComm, &modAVUMetadataInp);
00342 if (j < 0)
00343 return j;
00344 }
00345 return 0;
00346 }
00347
00348 int
00349 getStructFileType (specColl_t *specColl)
00350 {
00351 if (specColl == NULL) {
00352 return (-1);
00353 }
00354
00355 if (specColl->collClass == STRUCT_FILE_COLL) {
00356 return ((int) specColl->type);
00357 } else {
00358 return (-1);
00359 }
00360 }
00361
00362 int
00363 removeAVUMetadataFromKVPairs (rsComm_t *rsComm, char *objName, char *inObjType,
00364 keyValPair_t *kVP)
00365 {
00366 int i,j;
00367 char objType[10];
00368 modAVUMetadataInp_t modAVUMetadataInp;
00369
00370 if (strcmp(inObjType,"-1")) {
00371 strcpy(objType,inObjType);
00372 }
00373 else {
00374 i = getObjType(rsComm, objName,objType);
00375 if (i < 0)
00376 return(i);
00377 }
00378
00379 modAVUMetadataInp.arg0 = "rm";
00380 for (i = 0; i < kVP->len ; i++) {
00381
00382
00383
00384
00385 modAVUMetadataInp.arg1 = objType;
00386 modAVUMetadataInp.arg2 = objName;
00387 modAVUMetadataInp.arg3 = kVP->keyWord[i];
00388 modAVUMetadataInp.arg4 = kVP->value[i];
00389 modAVUMetadataInp.arg5 = "";
00390 j = rsModAVUMetadata (rsComm, &modAVUMetadataInp);
00391 if (j < 0)
00392 return(j);
00393 }
00394 return(0);
00395 }
00396
00397 int
00398 getTokenId(rsComm_t *rsComm, char *tokenNameSpace, char *tokenName)
00399 {
00400
00401 genQueryInp_t genQueryInp;
00402 genQueryOut_t *genQueryOut = NULL;
00403 char tmpStr[MAX_NAME_LEN];
00404 char tmpStr2[MAX_NAME_LEN];
00405 int status;
00406
00407 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00408 snprintf (tmpStr, NAME_LEN, "='%s'", tokenNameSpace);
00409 snprintf (tmpStr2, NAME_LEN, "='%s'", tokenName);
00410 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAMESPACE, tmpStr);
00411 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAME, tmpStr2);
00412 addInxIval (&genQueryInp.selectInp, COL_TOKEN_ID, 1);
00413 genQueryInp.maxRows = 2;
00414 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00415 clearGenQueryInp (&genQueryInp);
00416 if (status >= 0) {
00417 sqlResult_t *tokenIdRes;
00418
00419 if ((tokenIdRes = getSqlResultByInx (genQueryOut, COL_TOKEN_ID)) ==
00420 NULL) {
00421 rodsLog (LOG_ERROR,
00422 "getTokenId: getSqlResultByInx for COL_TOKEN_ID failed");
00423 freeGenQueryOut (&genQueryOut);
00424 return (UNMATCHED_KEY_OR_INDEX);
00425 }
00426 status = atoi(tokenIdRes->value);
00427 freeGenQueryOut (&genQueryOut);
00428 }
00429 return(status);
00430 }
00431
00432 int
00433 getUserId(rsComm_t *rsComm, char *userName, char *zoneName)
00434 {
00435
00436 genQueryInp_t genQueryInp;
00437 genQueryOut_t *genQueryOut = NULL;
00438 char tmpStr[MAX_NAME_LEN];
00439 char tmpStr2[MAX_NAME_LEN];
00440 int status;
00441
00442 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00443 snprintf (tmpStr, NAME_LEN, "='%s'", userName);
00444 snprintf (tmpStr2, NAME_LEN, "='%s'", zoneName);
00445 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, tmpStr);
00446 addInxVal (&genQueryInp.sqlCondInp, COL_USER_ZONE, tmpStr2);
00447 addInxIval (&genQueryInp.selectInp, COL_USER_ID, 1);
00448 genQueryInp.maxRows = 2;
00449 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00450 clearGenQueryInp (&genQueryInp);
00451 if (status >= 0) {
00452 sqlResult_t *userIdRes;
00453
00454 if ((userIdRes = getSqlResultByInx (genQueryOut, COL_USER_ID)) ==
00455 NULL) {
00456 rodsLog (LOG_ERROR,
00457 "getUserId: getSqlResultByInx for COL_USER_ID failed");
00458 freeGenQueryOut (&genQueryOut);
00459 return (UNMATCHED_KEY_OR_INDEX);
00460 }
00461 status = atoi(userIdRes->value);
00462 freeGenQueryOut (&genQueryOut);
00463 }
00464 return(status);
00465 }
00466
00467
00468 int
00469 checkPermitForDataObject(rsComm_t *rsComm, char *objName, int userId, int operId)
00470 {
00471 genQueryInp_t genQueryInp;
00472 genQueryOut_t *genQueryOut = NULL;
00473 char t1[MAX_NAME_LEN];
00474 char t11[MAX_NAME_LEN];
00475 char t2[MAX_NAME_LEN];
00476 char t3[MAX_NAME_LEN];
00477 char logicalEndName[MAX_NAME_LEN];
00478 char logicalParentDirName[MAX_NAME_LEN];
00479 int status;
00480
00481 status = splitPathByKey(objName,
00482 logicalParentDirName, logicalEndName, '/');
00483 snprintf (t1, MAX_NAME_LEN, " = '%s'", logicalEndName);
00484 snprintf (t11, MAX_NAME_LEN, " = '%s'", logicalParentDirName);
00485 snprintf (t2, MAX_NAME_LEN, " = '%i'", userId);
00486 snprintf (t3, MAX_NAME_LEN, " >= '%i' ", operId);
00487
00488 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00489 addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1);
00490 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, t1);
00491 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, t11);
00492 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_ACCESS_USER_ID, t2);
00493 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_ACCESS_TYPE, t3);
00494 genQueryInp.maxRows = 2;
00495 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00496 clearGenQueryInp (&genQueryInp);
00497 if (status >= 0) {
00498 freeGenQueryOut (&genQueryOut);
00499 return(1);
00500 }
00501 else
00502 return(0);
00503 }
00504
00505 int
00506 checkPermitForCollection(rsComm_t *rsComm, char *objName, int userId, int operId)
00507 {
00508 genQueryInp_t genQueryInp;
00509 genQueryOut_t *genQueryOut = NULL;
00510 char t1[MAX_NAME_LEN];
00511 char t2[MAX_NAME_LEN];
00512 char t4[MAX_NAME_LEN];
00513 int status;
00514
00515 snprintf (t1, MAX_NAME_LEN, " = '%s'", objName);
00516 snprintf (t2, MAX_NAME_LEN, " = '%i'", userId);
00517 snprintf (t4, MAX_NAME_LEN, " >= '%i' ", operId);
00518
00519 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00520 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00521 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, t1);
00522 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_ACCESS_USER_ID, t2);
00523 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_ACCESS_TYPE, t4);
00524 genQueryInp.maxRows = 2;
00525 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00526 clearGenQueryInp (&genQueryInp);
00527 if (status >= 0) {
00528 freeGenQueryOut (&genQueryOut);
00529 return(1);
00530 }
00531 else
00532 return(0);
00533 }
00534
00535 int
00536 checkPermitForResource(rsComm_t *rsComm, char *objName, int userId, int operId)
00537 {
00538 genQueryInp_t genQueryInp;
00539 genQueryOut_t *genQueryOut = NULL;
00540 char t1[MAX_NAME_LEN];
00541 char t2[MAX_NAME_LEN];
00542 char t4[MAX_NAME_LEN];
00543 int status;
00544
00545 snprintf (t1, MAX_NAME_LEN, " = '%s'", objName);
00546 snprintf (t2, MAX_NAME_LEN, " = '%i'", userId);
00547 snprintf (t4, MAX_NAME_LEN, " >= '%i' ", operId);
00548
00549 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00550 addInxIval (&genQueryInp.selectInp, COL_R_RESC_ID, 1);
00551 addInxVal (&genQueryInp.sqlCondInp, COL_R_RESC_NAME, t1);
00552 addInxVal (&genQueryInp.sqlCondInp, COL_RESC_ACCESS_USER_ID, t2);
00553 addInxVal (&genQueryInp.sqlCondInp, COL_RESC_ACCESS_TYPE, t4);
00554 genQueryInp.maxRows = 2;
00555 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00556 clearGenQueryInp (&genQueryInp);
00557 if (status >= 0) {
00558 freeGenQueryOut (&genQueryOut);
00559 return(1);
00560 }
00561 else
00562 return(0);
00563 }
00564
00565
00566 int
00567 checkPermissionByObjType(rsComm_t *rsComm, char *objName, char *objType, char *user, char *zone, char *oper)
00568 {
00569 int i;
00570 int operId;
00571 int userId;
00572 operId = getTokenId(rsComm, "access_type", oper);
00573 if (operId < 0)
00574 return(operId);
00575
00576 userId = getUserId(rsComm, user, zone);
00577 if (userId < 0)
00578 return(userId);
00579
00580 if (!strcmp(objType,"-d"))
00581 i = checkPermitForDataObject(rsComm, objName, userId, operId);
00582 else if (!strcmp(objType,"-c"))
00583 i = checkPermitForCollection(rsComm, objName, userId, operId);
00584 else if (!strcmp(objType,"-r"))
00585 i = checkPermitForResource(rsComm, objName, userId, operId);
00586
00587
00588
00589
00590 else
00591 i = INVALID_OBJECT_TYPE;
00592 return(i);
00593 }
00594
00595
00596
00597
00598 int
00599 checkDupReplica (rsComm_t *rsComm, rodsLong_t dataId, char *rescName,
00600 char *filePath)
00601 {
00602 genQueryInp_t genQueryInp;
00603 genQueryOut_t *genQueryOut = NULL;
00604 char tmpStr[MAX_NAME_LEN];
00605 int status;
00606
00607 if (rsComm == NULL || rescName == NULL || filePath == NULL)
00608 return USER__NULL_INPUT_ERR;
00609
00610 bzero (&genQueryInp, sizeof (genQueryInp_t));
00611
00612 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", rescName);
00613 addInxVal (&genQueryInp.sqlCondInp, COL_D_RESC_NAME, tmpStr);
00614 snprintf (tmpStr, MAX_NAME_LEN, "='%s'", filePath);
00615 addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_PATH, tmpStr);
00616 snprintf (tmpStr, MAX_NAME_LEN, "='%lld'", dataId);
00617 addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_ID, tmpStr);
00618
00619 addInxIval (&genQueryInp.selectInp, COL_DATA_REPL_NUM, 1);
00620 genQueryInp.maxRows = 2;
00621 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00622 clearGenQueryInp (&genQueryInp);
00623 if (status >= 0) {
00624 int intReplNum;
00625 sqlResult_t *replNum;
00626 if ((replNum = getSqlResultByInx (genQueryOut, COL_DATA_REPL_NUM)) ==
00627 NULL) {
00628 rodsLog (LOG_ERROR,
00629 "checkDupReplica: getSqlResultByInx COL_DATA_REPL_NUM failed");
00630 return (UNMATCHED_KEY_OR_INDEX);
00631 }
00632 intReplNum = atoi (replNum->value);
00633 freeGenQueryOut (&genQueryOut);
00634 return (intReplNum);
00635 } else {
00636 return status;
00637 }
00638 }
00639
00640
00641 int
00642 getNumSubfilesInBunfileObj (rsComm_t *rsComm, char *objPath)
00643 {
00644 int status;
00645 genQueryOut_t *genQueryOut = NULL;
00646 genQueryInp_t genQueryInp;
00647 int totalRowCount;
00648 char condStr[MAX_NAME_LEN];
00649
00650 bzero (&genQueryInp, sizeof (genQueryInp));
00651 genQueryInp.maxRows = 1;
00652 genQueryInp.options = RETURN_TOTAL_ROW_COUNT;
00653
00654 snprintf (condStr, MAX_NAME_LEN, "='%s'", objPath);
00655 addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_PATH, condStr);
00656 snprintf (condStr, MAX_NAME_LEN, "='%s'", BUNDLE_RESC_CLASS);
00657 addInxVal (&genQueryInp.sqlCondInp, COL_R_CLASS_NAME, condStr);
00658 addKeyVal (&genQueryInp.condInput, ZONE_KW, objPath);
00659
00660 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00661 addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
00662 addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, 1);
00663
00664 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00665 if ( genQueryOut == NULL || status < 0) {
00666 clearGenQueryInp (&genQueryInp);
00667 if (status == CAT_NO_ROWS_FOUND) {
00668 return 0;
00669 } else {
00670 return status;
00671 }
00672 }
00673 totalRowCount = genQueryOut->totalRowCount;
00674 freeGenQueryOut (&genQueryOut);
00675
00676 genQueryInp.maxRows = 0;
00677 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00678 clearGenQueryInp (&genQueryInp);
00679
00680 return totalRowCount;
00681 }
00682
00683
00684