/* * dat_saadvert_in * * This is called when active SA discovery is used and SAAdverts * have been detected. * * pdat The DATable which stores the total SA scope list. * pcScopeList The scope list of the individual discovered SA. * pcAttrlist The attribute list of the discovered SA. * This last parameter is currently ignored. * * Side Effect: * The DATable is updated with the new scopes, if any, in the sa * advert, for the pcSASList field. */ EXPORT void dat_saadvert_in(DATable *ignore, const char *pcScopeList, const char *pcAttrlist) { DATable* pdat = GetGlobalDATable(); if (!pcScopeList) return; if (pdat->pcSASList == NULL) { char *pcPacked = list_pack(pcScopeList); int i = strlen(pcPacked); pdat->pcSASList = safe_malloc(i+LISTINCR,pcPacked,i); pdat->iSASListSz = LISTINCR+i; free(pcPacked); } else { list_merge(pcScopeList, &(pdat->pcSASList), &(pdat->iSASListSz), CHECK); } }
int tjt_get_data(HDF *hdf, HASH *dbh, session_t *ses) { char *buf, tbl[LEN_TB]; size_t datalen; file_t *fl; ULIST *ul = NULL; int count, offset, aid, fid, ret; mdb_conn *dbsys, *dbtjt; dbsys = (mdb_conn*)hash_lookup(dbh, "Sys"); dbtjt = (mdb_conn*)hash_lookup(dbh, "Tjt"); PRE_DBOP(hdf, dbsys); PRE_DBOP(hdf, dbtjt); aid = ses->file->aid; fid = ses->file->id; snprintf(tbl, sizeof(tbl), "tjt_%d", aid); /* TODO ses->file not null all time? */ //if (ses->file != NULL) lutil_fill_layout_by_file(dbsys, ses->file, hdf); if (file_get_info_by_id(dbsys, aid, NULL, -1, &fl) == RET_RBTOP_OK) { hdf_set_value(hdf, PRE_OUTPUT".navtitle", fl->remark); file_del(fl); } file_get_nav_by_id(dbsys, aid, PRE_OUTPUT, hdf); ret = file_check_user_power(hdf, dbsys, ses, ses->file, LMT_APPEND); if (ret == RET_RBTOP_OK) { hdf_set_value(hdf, PRE_OUTPUT".appendable", "1"); } lutil_fetch_countf(hdf, dbtjt, tbl, "fid=%d", fid); mmisc_get_offset(hdf, &count, &offset); buf = mmc_getf(&datalen, 0, PRE_MMC_TJT".%d.%d", fid, offset); if (buf == NULL || datalen < sizeof(tjt_t)) { LDB_QUERY_RAW(dbtjt, "tjt_%d", TJT_QUERY_COL, "fid=%d ORDER BY uptime " " LIMIT %d OFFSET %d", NULL, aid, fid, count, offset); mdb_set_rows(hdf, dbtjt, TJT_QUERY_COL, PRE_OUTPUT".atoms"); lutil_image_expand(hdf, PRE_OUTPUT".atoms", "img", IMG_PATH, IMG_S, "imgurl"); lcs_hdf2list(hdf, PRE_OUTPUT".atoms", tjt_hdf2item, &ul); ret = list_pack(ul, TJT_LEN, tjt_pack_nalloc, &buf, &datalen); if (ret == RET_RBTOP_OK) { mmc_storef(MMC_OP_SET, buf, datalen, HALF_HOUR, 0, PRE_MMC_TJT".%d.%d", fid, offset); } } else { list_unpack(buf, tjt_unpack, datalen, &ul); ret = lcs_list2hdf(ul, PRE_OUTPUT".atoms", tjt_item2hdf, hdf); if (ret != RET_RBTOP_OK) { mtc_err("assembly tjt from mmc error"); return RET_RBTOP_MMCERR; } } uListDestroyFunc(&ul, tjt_del); free(buf); return ret; }
/* * dat_get_scopes * * If there is a net.slp.useScopes property, these scopes are * returned. Otherwise, starting with the scope list of the first * element, each DA's list is merged in (looking individually at * each of the already-obtained scopes to see if there is a list * intersection with the scopes of each of the subsequent DAs.) * * If there are no configured scopes and no DAs, and SA discovery * functionality has been compiled in, then SA discovery will be * used to * * slph This is used for SA discovery if needed. * pcTypeHint This is used for SA discovery, to optimize it. * pdat The da table which is checked for a scope list. * ppcScopes The scope list to return (an OUT parameter.) * * Return: * * Error if any. * *ppcScopes is set to the scope list obtained. If no scopes have * been found, this parameter will be set to NULL. * * Side Effects: * * The string list returned in ppcScopes must be freed by the caller. * * Notes: * * SA discovery will be implemented later... * */ EXPORT SLPInternalError dat_get_scopes(SLPHandle slph, const char *pcTypeHint, const DATable *ignore, char **ppcScopes) { DATable* pdat = GetGlobalDATable(); char *pcList, *pcScan; int iListLen = LISTINCR; int i; LockGlobalDATable(); *ppcScopes = NULL; if (!pdat || !ppcScopes) return SLP_PARAMETER_BAD; if (SLPGetProperty("net.slp.useScopes") != NULL) { *ppcScopes = strdup(SLPGetProperty("net.slp.useScopes")); return SLP_OK; } #ifdef EXTRA_MSGS if (slph != NULL && pdat->iSize == 0) { active_sa_discovery(slph,pcTypeHint); if (pdat->pcSASList) { int iLen = strlen(pdat->pcSASList); *ppcScopes = safe_malloc(iLen+1,pdat->pcSASList,iLen); } return SLP_OK; } #endif /* EXTRA_MSGS */ /* send a merged list of scopes from the DATable */ if (pdat->iSize == 0) return SLP_OK; iListLen += strlen(pdat->pDAE[0].pcScopeList); pcList = safe_malloc(iListLen, (char*)pdat->pDAE[0].pcScopeList, iListLen-LISTINCR); if( !pcList ) return SLP_INTERNAL_SYSTEM_ERROR; if (pdat->iSize > 1) { for (i = 1; i < pdat->iSize; i++) { pcScan = list_pack(pdat->pDAE[i].pcScopeList); list_merge(pcScan,&pcList,&iListLen,CHECK); free(pcScan); } } *ppcScopes = pcList; UnlockGlobalDATable(); return SLP_OK; }
/* * dat_daadvert_in * * * Returns: * 1 if the Advert is new and stored services should be forwarded to it. * 0 otherwise. * if negative, it corresponds to a SLPInternalError. */ EXPORT int dat_daadvert_in(DATable *ignore, struct sockaddr_in sin, const char *pcScopeList, long lBootTime) { DATable* pdat = GetGlobalDATable(); int retval = 0; if (!pdat || !pcScopeList ) return SLP_PARAMETER_BAD; if (SLPGetProperty("com.sun.slp.noDA") && !SDstrcasecmp(SLPGetProperty("com.sun.slp.noDA"),"true")) return 0; if (lBootTime == 0) remove_dae(pdat,sin); else { int i,found = 0; LockGlobalDATable(); for (i = 0; i < pdat->iSize; i++) { if (pdat->pDAE[i].sin.sin_addr.s_addr == sin.sin_addr.s_addr) { found = 1; /* update the entry */ if (pdat->pDAE[i].lBootTime < lBootTime || strcmp(pcScopeList, pdat->pDAE[i].pcScopeList) != 0) { /* da rebooted or changed its scopelist */ pdat->pDAE[i].lBootTime = lBootTime; free(pdat->pDAE[i].pcScopeList); pdat->pDAE[i].pcScopeList = list_pack(pcScopeList); pdat->pDAE[i].iStrikes = 0; // reset this retval = 1; /* indicates a new entry */ if ( pdat->pDAE[i].iDAIsScopeSponser ) { // this DA told us what scope to use, we need to make sure that our default registration scope // hasn't changed. } #ifdef ENABLE_SLP_LOGGING SLP_LOG (SLP_LOG_MSG, "Updating DA [%s], in list with scopelist: %s", inet_ntoa(sin.sin_addr), pcScopeList ); #endif } break; } } if (found == 0) { /* add the daentry */ if ((pdat->iSize+1) == pdat->iMax) { /* resize the table if needed */ DAEntry *pdae = (DAEntry*) safe_malloc((pdat->iMax+DATINCR)*sizeof(DAEntry),(char*)pdat->pDAE, pdat->iMax*sizeof(DAEntry)); free(pdat->pDAE); pdat->pDAE = pdae; pdat->iMax += DATINCR; } pdat->pDAE[pdat->iSize].sin.sin_addr.s_addr = sin.sin_addr.s_addr; pdat->pDAE[pdat->iSize].sin.sin_family = AF_INET; pdat->pDAE[pdat->iSize].sin.sin_port = htons(SLP_PORT); pdat->pDAE[pdat->iSize].pcScopeList = list_pack(pcScopeList); pdat->pDAE[pdat->iSize].lBootTime = lBootTime; pdat->pDAE[pdat->iSize].iStrikes = 0; pdat->pDAE[pdat->iSize].iDAIsScopeSponser = false; pdat->iSize++; retval = 1; /* indicates a new entry */ #ifdef ENABLE_SLP_LOGGING SLP_LOG( SLP_LOG_MSG, "Adding DA [%s], to list with scopelist: %s", inet_ntoa(sin.sin_addr), pcScopeList ); #endif } UnlockGlobalDATable(); } return retval; }