a hV@sddlZddlZddlZddlZddlZddlmmZddl m Z ddl m Z m Z mZddlmZmZeeZGdddZdd ZGd d d eZdS) N)systemd_ctypes)BusBusError introspection)Channel ChannelErrorc@sFeZdZddZddddZddZdd d Zd d Zdd dZdS)InterfaceCachecCsi|_t|_dSN)cachesetoldselfr9/usr/lib/python3.9/site-packages/cockpit/channels/dbus.py__init__tszInterfaceCache.__init__NreturncCs|j|dSr )r update)r interfacesrrrinjectxszInterfaceCache.injectcsD|||ddIdH\}t|}dd|dD}|||S)Nz#org.freedesktop.DBus.IntrospectableZ IntrospectcSsi|]}|jdt|qS)name)ZattribrZparse_interface).0tagrrr z2InterfaceCache.introspect_path.. interface)call_method_asyncETZ fromstringfindallr)rbus destination object_pathZxmletrrrrintrospect_path{s   zInterfaceCache.introspect_pathcs`z |j|WStyYn0|rT|rTz||||IdHWntyRYn0|j|Sr )r KeyErrorr%rgetrinterface_namer!r"r#rrr get_interfaces   zInterfaceCache.get_interfacecs0||jvrdS|j||||||IdHSr )r addr*r(rrrget_interface_if_news  z#InterfaceCache.get_interface_if_newcsD|||||IdH}|dur.td|dd|d|dS)Nz Interface z is not foundmethodsin)r*r&join)rr)methodr!r"r#rrrr get_signatureszInterfaceCache.get_signature)NNN)NNN) __name__ __module__ __qualname__rrr%r*r,r2rrrrr ss  r cCs"dd|D||i|<dS)NcSsi|]\}}||jqSr)value)rkvrrrrrz!notify_update..)items setdefault)notifypathr)propsrrr notify_updatesr>c@seZdZejddZdZdZdZdZ dZ ddZ ddZ d d Z d d Zd dZddZddZddZddZddZddZddZdS) DBusChannelr)indentz dbus-json3Nc s fddfdd}j|ddddjdz$jdddd d jIdH\}Wnty}z|jd krz$jdddd d jdIdHWqty}z*tdj|jjddWYd}~qd}~00ntdj|jWYd}~nd}~00|dS)Ncs j|kr|_j|ddS)Nowner)rB send_jsonrArrr send_owners z9DBusChannel.setup_name_owner_tracking..send_ownercs(|\}}}|dkr|ndddS)Nr-rA)get_body)message_nameZ_oldnew)rDrrhandlersz6DBusChannel.setup_name_owner_tracking..handlerzorg.freedesktop.DBusz/org/freedesktop/DBusZNameOwnerChanged)senderr<rmemberZarg0Z GetNameOwnersz)org.freedesktop.DBus.Error.NameHasNoOwnerZStartServiceByNameZsurz Failed to start service '%s': %srAz'Failed to get owner of service '%s': %s) add_signal_handlerrr!rrloggerdebugrFrC)rrI unique_nameerrorZ start_errorr)rrDrsetup_name_owner_trackings8    $(z%DBusChannel.setup_name_owner_trackingc st_|d_g_|d}|d}z|dur||durT|dkrTtdddtd|jtj |jdud _ n|d krtd jj j j _ n`|d krtd jt_ n>|dks|durtdjt_ ntdd|ddWn@tyB}z&tdd|d|d|WYd}~n d}~00zj ddWn6ty}z|jtjkrxWYd}~n d}~00t_jdurddfdd }|ndS)Nrr!addressZnonezprotocol-errorz0only one of "bus" and "address" can be specifiedrFzget bus with address %s for %s)rSZ bus_clientZinternalzget internal bus for %sZsessionzget session bus for %ssystemzget system bus for %sz invalid bus ""zfailed to connect to z bus: rrc spj4IdHHIdHjr4jjdnddiWdIdHql1IdHsb0YdS)N)rPZproblemz not-found)watch_processing_lockrRrBreadycloserrrr get_readys z&DBusChannel.do_open..get_ready)r r r'rmatchesrrNrOrrHr!ZrouterZ internal_busZclientZ default_userZdefault_systemOSErrorZ attach_eventerrnoZEBUSYasyncioLockrW create_taskrX)roptionsr!rSexcerrrZrrrdo_opensB      0  zDBusChannel.do_openc stfi|}d|d<d|vr2jdur2j|d<|ddkrF|d=fdd}jdurzd|vrz|djkrz|}n}dd d |D}szj||}WqWqtyYq0qj |dS) NsignaltyperJpath_namespace/cs$jdur j|kr |dSr )rBZ get_senderrTrIrrr filter_ownersz4DBusChannel.add_signal_handler..filter_owner,css"|]\}}|d|dVqdS)z=''Nr)rkeyr6rrr rz1DBusChannel.add_signal_handler..) dictrr'r0r9Z is_closingr! add_matchInterruptedErrorr[append)rrIkwargsrrjfuncZr_stringmatchrrirrM s$   zDBusChannel.add_signal_handlerc s$fdd}j|fi|dS)Ncs|dSr )r`rTrirr sync_handler,sz:DBusChannel.add_async_signal_handler..sync_handler)rM)rrIrsrwrriradd_async_signal_handler+sz$DBusChannel.add_async_signal_handlerc sx|d\}}}}|d}|d}|d}|dur@|d9}nd}|d} | durft|dkrfd } | dur\z0td |||j|||j|j|IdH} Wnty} z,|j | jd | j gg|d WYd} ~ dSd} ~ 0t y|j d d|d|dgg|d YdSt yZ} z(|j dd | gg|d WYd} ~ dSd} ~ 00z|jj |j|||| g|R} |jj| |dIdH} |j4IdHD|j | g||durdnd| ddWdIdHq1IdHs0YWntty<} z$|j | j| j gg|d WYd} ~ n@d} ~ 0t yrtd||j dtgg|d Yn0dS)Ncallidflagstimeoutilrfrr-z%Doing introspection request for %s %szIntrospection: rQrzz(org.freedesktop.DBus.Error.UnknownMethodzIntrospection data for method  z not availablez python.error)r|j|||t|gdWdIdHql1IdHsb0YdS)Nz got match)re) rNrOrWrCget_pathr* get_memberlistrErTrrr match_hitms  z+DBusChannel.do_add_match..match_hit)rNrOrx)rrFrprrrr do_add_matchis  zDBusChannel.do_add_matchc sfdd}j||ddjj|ddIdH\}|D]f\}}|D]T\} } dusj| krRj| jj|IdH} | r|| | it||| | qRqBdS)Nc sd|}|dkr|\}}td||i}i}j4IdH|D]T\}}dusb|krJj|jj |IdH}|r| ||it ||||qJj |dj |dWdIdHq1IdHs0Yn||dkr`|\}} td|| j4IdH2|t | i}j |dWdIdHq`1IdHsV0YdS)NZInterfacesAddedzinterfaces added %s %smetar;ZInterfacesRemovedzinterfaces removed %s %s)rrErNrOrWr9r r,r!rrr>rCrofromkeys) rFrKr<Zinterface_propsrr;rr=mmrr)rrrrI~s*  8  z6DBusChannel.setup_objectmanager_watch..handlerz"org.freedesktop.DBus.ObjectManager)r<rZGetManagedObjects) rxr!rrr9r r,rr>) rr<r)rr;rIZobjectspZifacesrr=rrrrsetup_objectmanager_watchys   z%DBusChannel.setup_objectmanager_watchc sfdd}jjj|IdH}|dur@||}||i}|||r`j|d|dnj|d|d|D]V} | drqtz2jj|ddd| IdH\} t ||| | Wqtt yYqt0qtdS) Nc s j4IdH|}|\}}}td|||||D]~}z&jj|ddd||IdH\}WnJty}z2td||j|t |WYd}~qrC) rFr<rr=Zinvalidsinvrrbr;rrrrIs& " z-DBusChannel.setup_path_watch..handlerr)rrg)rr<zorg.freedesktop.DBus.ZGetAllrL) r r%r!rr'rrx startswithrr>r) rr<r)Zrecursive_propsrr;rIZ this_metarrr=rrrsetup_path_watchs4       zDBusChannel.setup_path_watchc s||d}|d}|d}|d}|d}|p6|}||k}|dusP|durtd||jddgg|d |jg|d dSz|j4IdH|i}i} |||||| IdH|r||||| IdH|j|d |j| d |jg|dd WdIdHq&1IdHs0YWnNtyv} z4td || j|j| j | jgg|d WYd} ~ n d} ~ 00dS)Nwatchr<rgrrzz#ignored incomplete watch request %szx.y.zzNot Implementedr})rrzrrz#do_watch(%s) caught D-Bus error: %s) r'rNrOrCrWrrrrFr) rrFrr<rgr)r recursiverr;rQrrrdo_watchs2       DzDBusChannel.do_watchcs|j|ddS)Nr)r r)rrFrrrdo_metaszDBusChannel.do_metacCst|}td|j|d|vr4|||n^d|vrN|||nDd|vrh|||n*d|vr|| |ntd|dSdS)Nzreceive dbus request %s %sryrrrzignored dbus request %s) jsonloadsrNrOrr`rrrr)rdatarFrrrdo_datas  zDBusChannel.do_datacCs&|jD] }|qg|_|dSr )r[cancelrY)rZslotrrrdo_closes  zDBusChannel.do_close)r3r4r5rZ JSONEncoderZ json_encoderZpayloadr[rr!rBrRrdrMrxrrrrrrrrrrrrr?s$ (39*0r?)r^r]rZloggingrZxml.etree.ElementTreeZetreeZ ElementTreerZcockpit._vendorrZcockpit._vendor.systemd_ctypesrrrZchannelrrZ getLoggerr3rNr r>r?rrrr%s  B2